X-Git-Url: https://code.citadel.org/?p=citadel.git;a=blobdiff_plain;f=webcit%2Ftiny_mce%2Fplugins%2Fspellchecker%2Feditor_plugin_src.js;h=ee4df887c9953883e33a56039c175b997c037772;hp=d8680baf2cdfac60b4dc0e8624713aebdf7401f6;hb=b05f4eef4014db3885787ef15107cba93c932ac9;hpb=b347fec899815ec89b2738a0877880ee81e74b59 diff --git a/webcit/tiny_mce/plugins/spellchecker/editor_plugin_src.js b/webcit/tiny_mce/plugins/spellchecker/editor_plugin_src.js index d8680baf2..ee4df887c 100644 --- a/webcit/tiny_mce/plugins/spellchecker/editor_plugin_src.js +++ b/webcit/tiny_mce/plugins/spellchecker/editor_plugin_src.js @@ -70,10 +70,8 @@ t._done(); }); - ed.onInit.add(function() { - if (ed.settings.content_css !== false) - ed.dom.loadCSS(url + '/css/content.css'); - }); + if (ed.settings.content_css !== false) + ed.contentCSS.push(url + '/css/content.css'); ed.onClick.add(t._showMenu, t); ed.onContextMenu.add(t._showMenu, t); @@ -132,6 +130,9 @@ var o = {icon : 1}, mi; o.onclick = function() { + if (v == t.selectedLang) { + return; + } mi.setSelected(1); t.selectedItem.setSelected(0); t.selectedItem = mi; @@ -220,21 +221,11 @@ }, _markWords : function(wl) { - var r1, r2, r3, r4, r5, w = '', ed = this.editor, re = this._getSeparators(), dom = ed.dom, nl = []; - var se = ed.selection, b = se.getBookmark(); - - each(wl, function(v) { - w += (w ? '|' : '') + v; - }); - - r1 = new RegExp('([' + re + '])(' + w + ')([' + re + '])', 'g'); - r2 = new RegExp('^(' + w + ')', 'g'); - r3 = new RegExp('(' + w + ')([' + re + ']?)$', 'g'); - r4 = new RegExp('^(' + w + ')([' + re + ']?)$', 'g'); - r5 = new RegExp('(' + w + ')([' + re + '])', 'g'); + var ed = this.editor, dom = ed.dom, doc = ed.getDoc(), se = ed.selection, b = se.getBookmark(), nl = [], + w = wl.join('|'), re = this._getSeparators(), rx = new RegExp('(^|[' + re + '])(' + w + ')(?=[' + re + ']|$)', 'g'); // Collect all text nodes - this._walk(this.editor.getBody(), function(n) { + this._walk(ed.getBody(), function(n) { if (n.nodeType == 3) { nl.push(n); } @@ -242,18 +233,49 @@ // Wrap incorrect words in spans each(nl, function(n) { - var v; - - if (n.nodeType == 3) { - v = n.nodeValue; - - if (r1.test(v) || r2.test(v) || r3.test(v) || r4.test(v)) { - v = dom.encode(v); - v = v.replace(r5, '$1$2'); - v = v.replace(r3, '$1$2'); - - dom.replace(dom.create('span', {'class' : 'mceItemHidden'}, v), n); + var node, elem, txt, pos, v = n.nodeValue; + + if (rx.test(v)) { + // Encode the content + v = dom.encode(v); + // Create container element + elem = dom.create('span', {'class' : 'mceItemHidden'}); + + // Following code fixes IE issues by creating text nodes + // using DOM methods instead of innerHTML. + // Bug #3124:
 elements content is broken after spellchecking.
+					// Bug #1408: Preceding whitespace characters are removed
+					// @TODO: I'm not sure that both are still issues on IE9.
+					if (tinymce.isIE) {
+						// Enclose mispelled words with temporal tag
+						v = v.replace(rx, '$1$2');
+						// Loop over the content finding mispelled words
+						while ((pos = v.indexOf('')) != -1) {
+							// Add text node for the content before the word
+							txt = v.substring(0, pos);
+							if (txt.length) {
+								node = doc.createTextNode(dom.decode(txt));
+								elem.appendChild(node);
+							}
+							v = v.substring(pos+10);
+							pos = v.indexOf('');
+							txt = v.substring(0, pos);
+							v = v.substring(pos+11);
+							// Add span element for the word
+							elem.appendChild(dom.create('span', {'class' : 'mceItemHiddenSpellWord'}, txt));
+						}
+						// Add text node for the rest of the content
+						if (v.length) {
+							node = doc.createTextNode(dom.decode(v));
+							elem.appendChild(node);
+						}
+					} else {
+						// Other browsers preserve whitespace characters on innerHTML usage
+						elem.innerHTML = v.replace(rx, '$1$2');
 					}
+
+					// Finally, replace the node with the container
+					dom.replace(elem, n);
 				}
 			});
 
@@ -266,15 +288,7 @@
 			e = 0; // Fixes IE memory leak
 
 			if (!m) {
-				p1 = DOM.getPos(ed.getContentAreaContainer());
-				//p2 = DOM.getPos(ed.getContainer());
-
-				m = ed.controlManager.createDropMenu('spellcheckermenu', {
-					offset_x : p1.x,
-					offset_y : p1.y,
-					'class' : 'mceNoIcons'
-				});
-
+				m = ed.controlManager.createDropMenu('spellcheckermenu', {'class' : 'mceNoIcons'});
 				t._menu = m;
 			}
 
@@ -337,7 +351,6 @@
 						}
 					});
 
-
 					if (t.editor.getParam("spellchecker_enable_learn_rpc")) {
 						m.add({
 							title : 'spellchecker.learn_word',
@@ -358,6 +371,10 @@
 					m.update();
 				});
 
+				p1 = DOM.getPos(ed.getContentAreaContainer());
+				m.settings.offset_x = p1.x;
+				m.settings.offset_y = p1.y;
+
 				ed.selection.select(wordSpan);
 				p1 = dom.getPos(wordSpan);
 				m.showMenu(p1.x, p1.y + wordSpan.offsetHeight - vp.y);