Mercurial > public > sg101
diff static/js/tiny_mce/plugins/spellchecker/editor_plugin_src.js @ 442:6c182ceb7147
Fixing #217; upgrade TinyMCE to 3.4.2 and enable the paste plugin.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Thu, 26 May 2011 00:43:49 +0000 |
parents | 88b2b9cb8c1f |
children |
line wrap: on
line diff
--- a/static/js/tiny_mce/plugins/spellchecker/editor_plugin_src.js Wed May 25 02:39:08 2011 +0000 +++ b/static/js/tiny_mce/plugins/spellchecker/editor_plugin_src.js Thu May 26 00:43:49 2011 +0000 @@ -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; + var node, elem, txt, pos, v = n.nodeValue; - if (n.nodeType == 3) { - v = n.nodeValue; + if (rx.test(v)) { + // Encode the content + v = dom.encode(v); + // Create container element + elem = dom.create('span', {'class' : 'mceItemHidden'}); - if (r1.test(v) || r2.test(v) || r3.test(v) || r4.test(v)) { - v = dom.encode(v); - v = v.replace(r5, '<span class="mceItemHiddenSpellWord">$1</span>$2'); - v = v.replace(r3, '<span class="mceItemHiddenSpellWord">$1</span>$2'); + // Following code fixes IE issues by creating text nodes + // using DOM methods instead of innerHTML. + // Bug #3124: <PRE> 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<mcespell>$2</mcespell>'); + // Loop over the content finding mispelled words + while ((pos = v.indexOf('<mcespell>')) != -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('</mcespell>'); + 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<span class="mceItemHiddenSpellWord">$2</span>'); + } - dom.replace(dom.create('span', {'class' : 'mceItemHidden'}, v), n); - } + // 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; } @@ -358,6 +372,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);