Revision: 8935
          
http://languagetool.svn.sourceforge.net/languagetool/?rev=8935&view=rev
Author:   dnaber
Date:     2013-01-09 22:45:57 +0000 (Wed, 09 Jan 2013)
Log Message:
-----------
online check: make "ignore this kind of error" work (works until the next check)

Modified Paths:
--------------
    trunk/website/www/online-check/tiny_mce/plugins/atd-tinymce/editor_plugin.js
    trunk/website/www/online-check/tiny_mce/plugins/atd-tinymce/src/atd.core.js
    
trunk/website/www/online-check/tiny_mce/plugins/atd-tinymce/src/editor_plugin.js

Modified: 
trunk/website/www/online-check/tiny_mce/plugins/atd-tinymce/editor_plugin.js
===================================================================
--- 
trunk/website/www/online-check/tiny_mce/plugins/atd-tinymce/editor_plugin.js    
    2013-01-09 22:10:48 UTC (rev 8934)
+++ 
trunk/website/www/online-check/tiny_mce/plugins/atd-tinymce/editor_plugin.js    
    2013-01-09 22:45:57 UTC (rev 8935)
@@ -12,6 +12,16 @@
 /* EXPORTED_SYMBOLS is set so this file can be a JavaScript Module */
 var EXPORTED_SYMBOLS = ['AtDCore'];
 
+//
+// TODO:
+// 1. cursor position gets lost on check
+// 2. "ignore" and "ignore this kind of error" only works until the next check
+//
+// fixed: "ignore all" doesn't work
+// fixed: current cursor position is ignored when incorrect (it has its own 
node)
+// fixed: text with markup (even bold) messes up everything
+//
+
 function AtDCore() {
        /* these are the categories of errors AtD should ignore */
        this.ignore_types = [];
@@ -132,11 +142,8 @@
     brk = brk || '\n';
     width = width || 75;
     cut = cut || false;
-
     if (!str) { return str; }
-
     var regex = '.{1,' +width+ '}(\\s|$)' + (cut ? '|.{' +width+ '}|.+$' : 
'|\\S+?(\\s|$)');
-
     return str.match( new RegExp(regex, 'g') ).join( brk );
 };
 // End of wrapper code by James Padolsey
@@ -144,17 +151,17 @@
 AtDCore.prototype.findSuggestion = function(element) {
     var text = element.innerHTML;
     var metaInfo = element.getAttribute(this.surrogateAttribute);
-    var metaInfoElements = metaInfo.split(this.surrogateAttributeDelimiter);
     var errorDescription = {};
-    errorDescription["description"] = metaInfoElements[0];
-    var suggestions = metaInfoElements[1];
+    errorDescription["description"] = this.getSurrogatePart(metaInfo, 
'description');
+    var suggestions = this.getSurrogatePart(metaInfo, 'suggestions');
     if (suggestions) {
         errorDescription["suggestions"] = suggestions.split("#");
     } else {
         errorDescription["suggestions"] = "";
     }
-    if (metaInfoElements.length == 3) {
-        errorDescription["moreinfo"] = metaInfoElements[2];
+    var url = this.getSurrogatePart(metaInfo, 'url');
+    if (url) {
+        errorDescription["moreinfo"] = url;
     }
     return errorDescription;
 };
@@ -188,9 +195,10 @@
                 cssName = "hiddenGrammarError";
             }
             // TODO: escape metaInfo!?
-            var metaInfo = suggestion.description + 
this.surrogateAttributeDelimiter + suggestion.suggestions;
+            var delim = this.surrogateAttributeDelimiter;
+            var metaInfo = ruleId + delim + suggestion.description + delim + 
suggestion.suggestions;
             if (suggestion.moreinfo) {
-                metaInfo += this.surrogateAttributeDelimiter + 
suggestion.moreinfo;
+                metaInfo += delim + suggestion.moreinfo;
             }
             newText = newText.substring(0, spanStart)
                     + '<span ' + this.surrogateAttribute + '="' + metaInfo + 
'" class="' + cssName + '">'
@@ -202,23 +210,27 @@
     }
     
     tinyMCE.activeEditor.setContent(newText);
-    
-    //
-    // TODO??:
-    // 1. "ignore all" doesn't work
-    // 2. text with markup (even bold) messes up everything
-    // 3. cursor position gets lost on check
-    // 4. "ignore" only works until the next check
-    //
-    // fixed:. current cursor position is ignored when incorrect (it has its 
own node)
-    //
 };
 
+AtDCore.prototype.getSurrogatePart = function(surrogateString, part) {
+    var parts = surrogateString.split(this.surrogateAttributeDelimiter);
+    if (part == 'id') {
+        return parts[0];
+    } else if (part == 'description') {
+        return parts[1];
+    } else if (part == 'suggestions') {
+        return parts[2];
+    } else if (part == 'url' && parts.length >= 3) {
+        return parts[3];
+    }
+    return null;
+};
+
 AtDCore.prototype.getText = function() {
     return tinyMCE.activeEditor.getContent({ format: 'text' 
}).replace(/<.*?>/g, "").replace(/\ufeff/g, "");  // feff = 65279 = cursor code
 };
 
-AtDCore.prototype.removeWords = function(node, w) {   
+AtDCore.prototype.removeWords = function(node, w) {
        var count = 0;
        var parent = this;
 
@@ -238,6 +250,29 @@
        return count;
 };
 
+AtDCore.prototype.removeWordsByRuleId = function(node, ruleId) {
+       var count = 0;
+       var parent = this;
+
+       this.map(this.findSpans(node).reverse(), function(n) {
+               if (n && (parent.isMarkedNode(n) || parent.hasClass(n, 
'mceItemHidden') || parent.isEmptySpan(n)) ) {
+                       if (n.innerHTML == '&nbsp;') {
+                               var nnode = document.createTextNode(' '); /* 
hax0r */
+                               parent.replaceWith(n, nnode);
+                       }
+                       else {
+        var surrogate = n.getAttribute(parent.surrogateAttribute);
+        if (!ruleId || (surrogate && parent.getSurrogatePart(surrogate, 'id') 
== ruleId)) {
+            parent.removeParent(n);
+            count++;
+        }
+      }
+               }
+       });
+
+       return count;
+};
+
 AtDCore.prototype.isEmptySpan = function(node) {
        return (this.getAttrib(node, 'class') == "" && this.getAttrib(node, 
'style') == "" && this.getAttrib(node, 'id') == "" && !this.hasClass(node, 
'Apple-style-span') && this.getAttrib(node, 'mce_name') == "");
 };
@@ -413,7 +448,6 @@
 
             /* send request to our service */
             var textContent = plugin.editor.core.getText();
-            console.log("#####TEXT:" + textContent);
             plugin.sendRequest('checkDocument', textContent, languageCode, 
function(data, request, someObject)
             {
                /* turn off the spinning thingie */
@@ -520,6 +554,20 @@
          se.moveToBookmark(b);
       },
 
+      _removeWordsByRuleId : function(ruleId) 
+      {
+         var ed = this.editor, dom = ed.dom, se = ed.selection, b = 
se.getBookmark();
+
+         ed.core.removeWordsByRuleId(undefined, ruleId);
+
+         /* force a rebuild of the DOM... even though the right elements are 
stripped, the DOM is still organized
+            as if the span were there and this breaks my code */
+
+         dom.setHTML(dom.getRoot(), dom.getRoot().innerHTML);
+
+         se.moveToBookmark(b);
+      },
+
       markMyWords : function()
       {
          var ed  = this.editor;
@@ -676,10 +724,12 @@
             else
             {
                 m.add({
-                  title : plugin.editor.getLang('menu_option_ignore_all', 
'Ignore all'),
+                  title : plugin.editor.getLang('menu_option_ignore_all', 
'Ignore this kind of error'),
                   onclick : function() 
                   {
-                     t._removeWords(e.target.innerHTML);
+                     var surrogate = 
e.target.getAttribute(plugin.editor.core.surrogateAttribute);
+                     var ruleId = 
plugin.editor.core.getSurrogatePart(surrogate, 'id');
+                     t._removeWordsByRuleId(ruleId);
                      t._checkDone();
                   }
                });

Modified: 
trunk/website/www/online-check/tiny_mce/plugins/atd-tinymce/src/atd.core.js
===================================================================
--- trunk/website/www/online-check/tiny_mce/plugins/atd-tinymce/src/atd.core.js 
2013-01-09 22:10:48 UTC (rev 8934)
+++ trunk/website/www/online-check/tiny_mce/plugins/atd-tinymce/src/atd.core.js 
2013-01-09 22:45:57 UTC (rev 8935)
@@ -12,6 +12,16 @@
 /* EXPORTED_SYMBOLS is set so this file can be a JavaScript Module */
 var EXPORTED_SYMBOLS = ['AtDCore'];
 
+//
+// TODO:
+// 1. cursor position gets lost on check
+// 2. "ignore" and "ignore this kind of error" only works until the next check
+//
+// fixed: "ignore all" doesn't work
+// fixed: current cursor position is ignored when incorrect (it has its own 
node)
+// fixed: text with markup (even bold) messes up everything
+//
+
 function AtDCore() {
        /* these are the categories of errors AtD should ignore */
        this.ignore_types = [];
@@ -132,11 +142,8 @@
     brk = brk || '\n';
     width = width || 75;
     cut = cut || false;
-
     if (!str) { return str; }
-
     var regex = '.{1,' +width+ '}(\\s|$)' + (cut ? '|.{' +width+ '}|.+$' : 
'|\\S+?(\\s|$)');
-
     return str.match( new RegExp(regex, 'g') ).join( brk );
 };
 // End of wrapper code by James Padolsey
@@ -144,17 +151,17 @@
 AtDCore.prototype.findSuggestion = function(element) {
     var text = element.innerHTML;
     var metaInfo = element.getAttribute(this.surrogateAttribute);
-    var metaInfoElements = metaInfo.split(this.surrogateAttributeDelimiter);
     var errorDescription = {};
-    errorDescription["description"] = metaInfoElements[0];
-    var suggestions = metaInfoElements[1];
+    errorDescription["description"] = this.getSurrogatePart(metaInfo, 
'description');
+    var suggestions = this.getSurrogatePart(metaInfo, 'suggestions');
     if (suggestions) {
         errorDescription["suggestions"] = suggestions.split("#");
     } else {
         errorDescription["suggestions"] = "";
     }
-    if (metaInfoElements.length == 3) {
-        errorDescription["moreinfo"] = metaInfoElements[2];
+    var url = this.getSurrogatePart(metaInfo, 'url');
+    if (url) {
+        errorDescription["moreinfo"] = url;
     }
     return errorDescription;
 };
@@ -188,9 +195,10 @@
                 cssName = "hiddenGrammarError";
             }
             // TODO: escape metaInfo!?
-            var metaInfo = suggestion.description + 
this.surrogateAttributeDelimiter + suggestion.suggestions;
+            var delim = this.surrogateAttributeDelimiter;
+            var metaInfo = ruleId + delim + suggestion.description + delim + 
suggestion.suggestions;
             if (suggestion.moreinfo) {
-                metaInfo += this.surrogateAttributeDelimiter + 
suggestion.moreinfo;
+                metaInfo += delim + suggestion.moreinfo;
             }
             newText = newText.substring(0, spanStart)
                     + '<span ' + this.surrogateAttribute + '="' + metaInfo + 
'" class="' + cssName + '">'
@@ -202,23 +210,27 @@
     }
     
     tinyMCE.activeEditor.setContent(newText);
-    
-    //
-    // TODO??:
-    // 1. "ignore all" doesn't work
-    // 2. text with markup (even bold) messes up everything
-    // 3. cursor position gets lost on check
-    // 4. "ignore" only works until the next check
-    //
-    // fixed:. current cursor position is ignored when incorrect (it has its 
own node)
-    //
 };
 
+AtDCore.prototype.getSurrogatePart = function(surrogateString, part) {
+    var parts = surrogateString.split(this.surrogateAttributeDelimiter);
+    if (part == 'id') {
+        return parts[0];
+    } else if (part == 'description') {
+        return parts[1];
+    } else if (part == 'suggestions') {
+        return parts[2];
+    } else if (part == 'url' && parts.length >= 3) {
+        return parts[3];
+    }
+    return null;
+};
+
 AtDCore.prototype.getText = function() {
     return tinyMCE.activeEditor.getContent({ format: 'text' 
}).replace(/<.*?>/g, "").replace(/\ufeff/g, "");  // feff = 65279 = cursor code
 };
 
-AtDCore.prototype.removeWords = function(node, w) {   
+AtDCore.prototype.removeWords = function(node, w) {
        var count = 0;
        var parent = this;
 
@@ -238,6 +250,29 @@
        return count;
 };
 
+AtDCore.prototype.removeWordsByRuleId = function(node, ruleId) {
+       var count = 0;
+       var parent = this;
+
+       this.map(this.findSpans(node).reverse(), function(n) {
+               if (n && (parent.isMarkedNode(n) || parent.hasClass(n, 
'mceItemHidden') || parent.isEmptySpan(n)) ) {
+                       if (n.innerHTML == '&nbsp;') {
+                               var nnode = document.createTextNode(' '); /* 
hax0r */
+                               parent.replaceWith(n, nnode);
+                       }
+                       else {
+        var surrogate = n.getAttribute(parent.surrogateAttribute);
+        if (!ruleId || (surrogate && parent.getSurrogatePart(surrogate, 'id') 
== ruleId)) {
+            parent.removeParent(n);
+            count++;
+        }
+      }
+               }
+       });
+
+       return count;
+};
+
 AtDCore.prototype.isEmptySpan = function(node) {
        return (this.getAttrib(node, 'class') == "" && this.getAttrib(node, 
'style') == "" && this.getAttrib(node, 'id') == "" && !this.hasClass(node, 
'Apple-style-span') && this.getAttrib(node, 'mce_name') == "");
 };

Modified: 
trunk/website/www/online-check/tiny_mce/plugins/atd-tinymce/src/editor_plugin.js
===================================================================
--- 
trunk/website/www/online-check/tiny_mce/plugins/atd-tinymce/src/editor_plugin.js
    2013-01-09 22:10:48 UTC (rev 8934)
+++ 
trunk/website/www/online-check/tiny_mce/plugins/atd-tinymce/src/editor_plugin.js
    2013-01-09 22:45:57 UTC (rev 8935)
@@ -242,6 +242,20 @@
          se.moveToBookmark(b);
       },
 
+      _removeWordsByRuleId : function(ruleId) 
+      {
+         var ed = this.editor, dom = ed.dom, se = ed.selection, b = 
se.getBookmark();
+
+         ed.core.removeWordsByRuleId(undefined, ruleId);
+
+         /* force a rebuild of the DOM... even though the right elements are 
stripped, the DOM is still organized
+            as if the span were there and this breaks my code */
+
+         dom.setHTML(dom.getRoot(), dom.getRoot().innerHTML);
+
+         se.moveToBookmark(b);
+      },
+
       markMyWords : function()
       {
          var ed  = this.editor;
@@ -398,10 +412,12 @@
             else
             {
                 m.add({
-                  title : plugin.editor.getLang('menu_option_ignore_all', 
'Ignore all'),
+                  title : plugin.editor.getLang('menu_option_ignore_all', 
'Ignore this kind of error'),
                   onclick : function() 
                   {
-                     t._removeWords(e.target.innerHTML);
+                     var surrogate = 
e.target.getAttribute(plugin.editor.core.surrogateAttribute);
+                     var ruleId = 
plugin.editor.core.getSurrogatePart(surrogate, 'id');
+                     t._removeWordsByRuleId(ruleId);
                      t._checkDone();
                   }
                });

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Master Java SE, Java EE, Eclipse, Spring, Hibernate, JavaScript, jQuery
and much more. Keep your Java skills current with LearnJavaNow -
200+ hours of step-by-step video tutorials by Java experts.
SALE $49.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122612 
_______________________________________________
Languagetool-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/languagetool-commits

Reply via email to