Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 48 additions & 17 deletions languagetool/include/languagetool.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*
* Contributing: https://github.com/KnowZero/tinymce4-languagetool
*/

var LanguageTool = function LanguageTool(lt_set,$) {

// Declare Variables
Expand All @@ -31,14 +30,14 @@ var LanguageTool = function LanguageTool(lt_set,$) {
var lt_remoteTimer = lt_set['lt_timer'] || 10000; // DO NOT CHANGE UNLESS YOU USE YOUR OWN URL!



var lt_setLanguage = lt_set['lt_lang'] || "en-US";

var lt_setMode = lt_set['lt_mode'] || "new_sentence";

var lt_setHighlight = lt_set['lt_highlight'] || {};
var lt_debugLevel = lt_set['lt_debug'] || 0;
var lt_ignoreCallback = lt_set['lt_ignore_callback'] || function () {};
var lt_onNext = lt_set['lt_on_next'] || function () {};
var lt_monopolizeHighlightContextMenu = lt_set['lt_monopolize_highlight_contextmenu'] || true;
var lt_highlightClick = lt_set['lt_highlight_click'] || "right";
var lt_fullMessage = lt_set['lt_full_message'] || false;
Expand Down Expand Up @@ -487,6 +486,40 @@ toval = '#lt_issueChangeTo';
lt_contextMenuClick( $(sug).data('ident-UUID'), $(sug).data('ident-HID'), $(toval).val(), 1 );
};

var setAcceptAllDialog = function(sug, toval){
if (sug == undefined) {
sug = '#lt_issueSuggestions';
toval = '#lt_issueChangeTo';
}
var uuid = $(sug).data('ident-UUID');
var hid = $(sug).data('ident-HID');
var value = $(toval).val();
var mode = 1;
lt_debug( 'INFO|CONTEXT-ITEM='+uuid+'='+hid+'='+value, 4 );
sgfunc['setundo'].call();

//var uuid = $(this).data("ident-uuid");
sgstore['lock'][uuid]=0;

var mynode = sgstore['contextmenu'];
sgstore['run'].push({
node: mynode, mode:mode,
func: function () {
$( sgfunc['body'].call() ).find( 'span[data-word="'+window.btoa( encodeURIComponent(sgstore['lt'][uuid][hid]['word']) )+'"]' ).each(function () {
$(this).replaceWith( value );

});

if ( (this.mode||0) == 1 ) {
lt_nextIssue();
}

//lt_ignoreCallback.call(this,'addWord',sgstore['lt'][uuid][hid]['rule']['id']);
}

});
};


// Queues

Expand Down Expand Up @@ -532,7 +565,6 @@ lt_contextMenuClick( $(sug).data('ident-UUID'), $(sug).data('ident-HID'), $(tova
lt_inactive+=100;
timerRunner+=100;
lastActive+=100;

$.each(sgstore['run'], function(i,val) {
sgstore['run'][i].func();
});
Expand Down Expand Up @@ -1221,7 +1253,7 @@ $(progress_bar).val( sgstore['progress'][0] );
// Suggestion Dialog

function lt_nextIssue (firstOpen) {

lt_debug('INFO|NEXT-ISSUE='+firstOpen, 4 );
var mynode = $( sgfunc['body'].call() ).find('.lt-highlight').not('.skip-dialog-highlight').get(0);

if (mynode == undefined) {
Expand All @@ -1233,15 +1265,15 @@ sgfunc['alert'].call(this,'Done!');

$(mynode).addClass( 'dialog-highlight' );


lt_onNext(mynode);

var mypnode=lt_find_parent_node(mynode);
var uuid = $(mypnode).data('UUID');
var hid = $(mynode).data('hid');

if ( (firstOpen||0) == 0 ) {

if ( $('#lt-filter-check-'+sgstore['lt'][uuid][hid]['rule']['issueType']+'[aria-checked="false"]').length == 1 ) {
if ( $('#lt-filter-check-'+sgstore['lt'][uuid][hid].rule.issueType+'[aria-checked="false"]').length == 1 ) {
$(mynode).removeClass('dialog-highlight').addClass( 'skip-dialog-highlight' );
lt_nextIssue();
return false;
Expand All @@ -1253,8 +1285,10 @@ return false;
$('#lt_issueSuggestions').empty();


var txtMsg = '[' + sgstore['lt'][uuid][hid]['rule']['issueType'].charAt(0).toUpperCase() + sgstore['lt'][uuid][hid]['rule']['issueType'].slice(1) + '] ' + sgstore['lt'][uuid][hid]['message'];
$('#lt_issueMessage').text(txtMsg).attr('title', txtMsg);

$('#lt_issueMessage').text( '[' + sgstore['lt'][uuid][hid]['rule']['issueType'].charAt(0).toUpperCase() + sgstore['lt'][uuid][hid]['rule']['issueType'].slice(1) + '] ' + sgstore['lt'][uuid][hid]['message'] );
$('#lt_issueChangeTo').val('[NO SUGGESTIONS]');

$.each(sgstore['lt'][uuid][hid]['replacements'],function(key,val) {

Expand Down Expand Up @@ -1485,7 +1519,7 @@ function lt_contextMenuClick(uuid,hid,value,mode) {

lt_debug( 'INFO|CONTEXT-ITEM='+uuid+'='+hid+'='+value, 4 );

sgfunc['setundo'].call()
sgfunc['setundo'].call();


//var uuid = $(this).data("ident-uuid");
Expand Down Expand Up @@ -1526,10 +1560,6 @@ function lt_contextMenuClick(uuid,hid,value,mode) {

function lt_contextMenuIgnore (uuid,hid,value,mode) {





// var uuid = $(this).data("ident-uuid");
// var hid = $(this).data("ident-hid");
sgstore['lock'][uuid]=0;
Expand All @@ -1542,6 +1572,7 @@ function lt_contextMenuIgnore (uuid,hid,value,mode) {


if ( value == 'once' ) {
lt_debug('INFO|IGNORE-ONCE='+sgstore['lt'][uuid][hid]['word'], 4 );
if ( sgstore['ignore']['once'][uuid] == undefined ) {
sgstore['ignore']['once'][uuid]={};
}
Expand All @@ -1553,17 +1584,16 @@ function lt_contextMenuIgnore (uuid,hid,value,mode) {

if ( mynode.nodeName == 'SPAN' && $(mynode).hasClass('lt-highlight') == true ) {


sgstore['run'].push({
node: mynode, mode:mode,
func: function () {
mynode=this.node;
$( mynode ).replaceWith( $(mynode).html() );

lt_queue( uuid, $(mynode).parent(), 0, 0 );
if ( (this.mode||0) == 1 ) {
lt_nextIssue();
}
if ( (this.mode||0) == 1 ) {
lt_nextIssue();
}

//sgcheck[ uuid ]=lt_text($(mynode).parent().text());
//sgstore['html'][ uuid ]=lt_text($(mynode).parent().html());
Expand Down Expand Up @@ -1628,7 +1658,7 @@ sgfunc['confirm'].call(this,'Are you sure you wish to ignore this rule going for
});

}

lt_timer(0); // Resume if idle

}

Expand Down Expand Up @@ -1694,6 +1724,7 @@ return {
setProgress: setProgress,
nextIssue: nextIssue,
setAcceptDialog: setAcceptDialog,
setAcceptAllDialog: setAcceptAllDialog,
setIgnoreDialog: setIgnoreDialog,
setSkipDialog: setSkipDialog,

Expand Down
15 changes: 10 additions & 5 deletions languagetool/plugin.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,11 @@ LT.setStore('viewport_process','temp');
var tfilter=[];

$.each( LT.highlightList ,function(key,val){
tfilter.push( {type: 'checkbox', id: 'lt-filter-check-'+key, text: key.charAt(0).toUpperCase() + key.slice(1), value: val, 'class': 'lt_issueFilterAllow', checked: true } );
tfilter.push( {
type: 'checkbox', id: 'lt-filter-check-'+key,
text: key.charAt(0).toUpperCase() + key.slice(1),
value: val, 'class': 'lt_issueFilterAllow',
checked: true } );
});


Expand All @@ -299,10 +303,11 @@ $.each( LT.highlightList ,function(key,val){
{
type : 'buttongroup',
name : 'buttongroup',
label : '- Action:',
label : 'Action:',
items : [
{ text: 'Apply', value: 'Apply', onClick: function() { LT.setAcceptDialog(); } },
{ text: 'Skip', value: 'Skip', onClick: function () { LT.setSkipDialog(); } },
{ text: 'Change', value: 'Apply', onClick: function() { LT.setAcceptDialog(); } },
{ text: 'Change All', value: 'Apply to All', onClick: function() { LT.setAcceptAllDialog(); } },
{ text: 'Next', value: 'Skip', onClick: function () { LT.setSkipDialog(); } },
{ text: 'Ignore', value: 'Ignore', onClick: function() { LT.setIgnoreDialog('once'); } },
{ text: 'Ignore All', value: 'Ignore All', onClick: function() { LT.setIgnoreDialog('all'); } },
{ text: 'Ignore Rule', value: 'Ignore Rule', onClick: function() { LT.setIgnoreDialog('rule'); } }
Expand Down Expand Up @@ -334,7 +339,7 @@ $( tinymce.activeEditor.getBody() ).find('.skip-dialog-highlight').removeClass('

}
});

$('#mce-modal-block').remove();

}

Expand Down