Revision: 8934
http://languagetool.svn.sourceforge.net/languagetool/?rev=8934&view=rev
Author: dnaber
Date: 2013-01-09 22:10:48 +0000 (Wed, 09 Jan 2013)
Log Message:
-----------
online check: try another approach by using the editor's getContent() method.
Now markup like images will just be thrown away and we check and return the
plain text.
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 21:33:40 UTC (rev 8933)
+++
trunk/website/www/online-check/tiny_mce/plugins/atd-tinymce/editor_plugin.js
2013-01-09 22:10:48 UTC (rev 8934)
@@ -27,8 +27,6 @@
*/
this.surrogateAttribute = "onkeypress";
this.surrogateAttributeDelimiter = "---#---";
-
- this.newText = "";
};
/*
@@ -146,7 +144,7 @@
AtDCore.prototype.findSuggestion = function(element) {
var text = element.innerHTML;
var metaInfo = element.getAttribute(this.surrogateAttribute);
- var metaInfoElements = metaInfo.split(this.surrogateAttributeDelimiter)
+ var metaInfoElements = metaInfo.split(this.surrogateAttributeDelimiter);
var errorDescription = {};
errorDescription["description"] = metaInfoElements[0];
var suggestions = metaInfoElements[1];
@@ -165,8 +163,7 @@
* code to manage highlighting of errors
*/
AtDCore.prototype.markMyWords = function(container_nodes) {
- this.newText = "";
- this._walkNodesAndSetText(container_nodes);
+ var newText = this.getText();
var previousSpanStart = -1;
// iterate backwards as we change the text and thus modify positions:
@@ -195,16 +192,16 @@
if (suggestion.moreinfo) {
metaInfo += this.surrogateAttributeDelimiter +
suggestion.moreinfo;
}
- this.newText = this.newText.substring(0, spanStart)
+ newText = newText.substring(0, spanStart)
+ '<span ' + this.surrogateAttribute + '="' + metaInfo +
'" class="' + cssName + '">'
- + this.newText.substring(spanStart, spanEnd)
+ + newText.substring(spanStart, spanEnd)
+ '</span>'
- + this.newText.substring(spanEnd);
+ + newText.substring(spanEnd);
suggestion.used = true;
}
}
- tinyMCE.activeEditor.setContent(this.newText);
+ tinyMCE.activeEditor.setContent(newText);
//
// TODO??:
@@ -217,29 +214,10 @@
//
};
-AtDCore.prototype._walk = function(elements, f) {
- var i;
- for (i = 0; i < elements.length; i++) {
- f.call(f, elements[i]);
- this._walk(this.contents(elements[i]), f);
- }
+AtDCore.prototype.getText = function() {
+ return tinyMCE.activeEditor.getContent({ format: 'text'
}).replace(/<.*?>/g, "").replace(/\ufeff/g, ""); // feff = 65279 = cursor code
};
-AtDCore.prototype._walkNodesAndSetText = function(elements) {
- var i;
- for (i = 0; i < elements.length; i++) {
- var node = elements[i];
- if (node.nodeType == 1) {
- this._walkNodesAndSetText(this.contents(node));
- } else if (node.nodeType == 3) {
- if (node.nodeValue.length == 1 && node.nodeValue.charCodeAt(0) ==
65279) { // cursor has its own node, ignore it
- continue;
- }
- this.newText += node.nodeValue;
- }
- }
-};
-
AtDCore.prototype.removeWords = function(node, w) {
var count = 0;
var parent = this;
@@ -434,8 +412,8 @@
plugin._removeWords();
/* send request to our service */
- //plugin.sendRequest('checkDocument', ed.getContent({ format:
'raw' }), function(data, request, someObject)
- var textContent = ed.getContent().replace(/<.*?>/g, "");
+ var textContent = plugin.editor.core.getText();
+ console.log("#####TEXT:" + textContent);
plugin.sendRequest('checkDocument', textContent, languageCode,
function(data, request, someObject)
{
/* turn off the spinning thingie */
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 21:33:40 UTC (rev 8933)
+++ trunk/website/www/online-check/tiny_mce/plugins/atd-tinymce/src/atd.core.js
2013-01-09 22:10:48 UTC (rev 8934)
@@ -27,8 +27,6 @@
*/
this.surrogateAttribute = "onkeypress";
this.surrogateAttributeDelimiter = "---#---";
-
- this.newText = "";
};
/*
@@ -165,8 +163,7 @@
* code to manage highlighting of errors
*/
AtDCore.prototype.markMyWords = function(container_nodes) {
- this.newText = "";
- this._walkNodesAndSetText(container_nodes);
+ var newText = this.getText();
var previousSpanStart = -1;
// iterate backwards as we change the text and thus modify positions:
@@ -195,16 +192,16 @@
if (suggestion.moreinfo) {
metaInfo += this.surrogateAttributeDelimiter +
suggestion.moreinfo;
}
- this.newText = this.newText.substring(0, spanStart)
+ newText = newText.substring(0, spanStart)
+ '<span ' + this.surrogateAttribute + '="' + metaInfo +
'" class="' + cssName + '">'
- + this.newText.substring(spanStart, spanEnd)
+ + newText.substring(spanStart, spanEnd)
+ '</span>'
- + this.newText.substring(spanEnd);
+ + newText.substring(spanEnd);
suggestion.used = true;
}
}
- tinyMCE.activeEditor.setContent(this.newText);
+ tinyMCE.activeEditor.setContent(newText);
//
// TODO??:
@@ -217,29 +214,10 @@
//
};
-AtDCore.prototype._walk = function(elements, f) {
- var i;
- for (i = 0; i < elements.length; i++) {
- f.call(f, elements[i]);
- this._walk(this.contents(elements[i]), f);
- }
+AtDCore.prototype.getText = function() {
+ return tinyMCE.activeEditor.getContent({ format: 'text'
}).replace(/<.*?>/g, "").replace(/\ufeff/g, ""); // feff = 65279 = cursor code
};
-AtDCore.prototype._walkNodesAndSetText = function(elements) {
- var i;
- for (i = 0; i < elements.length; i++) {
- var node = elements[i];
- if (node.nodeType == 1) {
- this._walkNodesAndSetText(this.contents(node));
- } else if (node.nodeType == 3) {
- if (node.nodeValue.length == 1 && node.nodeValue.charCodeAt(0) ==
65279) { // cursor has its own node, ignore it
- continue;
- }
- this.newText += node.nodeValue;
- }
- }
-};
-
AtDCore.prototype.removeWords = function(node, w) {
var count = 0;
var parent = this;
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 21:33:40 UTC (rev 8933)
+++
trunk/website/www/online-check/tiny_mce/plugins/atd-tinymce/src/editor_plugin.js
2013-01-09 22:10:48 UTC (rev 8934)
@@ -135,8 +135,7 @@
plugin._removeWords();
/* send request to our service */
- //plugin.sendRequest('checkDocument', ed.getContent({ format:
'raw' }), function(data, request, someObject)
- var textContent = ed.getContent().replace(/<.*?>/g, "");
+ var textContent = plugin.editor.core.getText();
plugin.sendRequest('checkDocument', textContent, languageCode,
function(data, request, someObject)
{
/* turn off the spinning thingie */
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