X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=program%2Fjs%2Ftiny_mce%2Fplugins%2Fspellchecker%2Feditor_plugin_src.js;h=84a9989f63ca2b8fe92b8d8082d8fd14848bfd00;hb=8d00e7f2ca613449885c5b9613a234c387825907;hp=196d246404006f63205bd4c10fc70d5a979001f0;hpb=8a4a1a7851436ef5ff246a861b1cac2d3c0d030b;p=roundcube.git diff --git a/program/js/tiny_mce/plugins/spellchecker/editor_plugin_src.js b/program/js/tiny_mce/plugins/spellchecker/editor_plugin_src.js index 196d246..84a9989 100644 --- a/program/js/tiny_mce/plugins/spellchecker/editor_plugin_src.js +++ b/program/js/tiny_mce/plugins/spellchecker/editor_plugin_src.js @@ -1,588 +1,338 @@ /** - * $Id: editor_plugin_src.js 28 2006-08-01 16:02:56Z spocke $ + * $Id: editor_plugin_src.js 425 2007-11-21 15:17:39Z spocke $ * * @author Moxiecode - * @copyright Copyright © 2004-2006, Moxiecode Systems AB, All rights reserved. + * @copyright Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved. */ -tinyMCE.importPluginLanguagePack('spellchecker', 'en,fr,sv,nn,nb'); - -// Plucin static class -var TinyMCE_SpellCheckerPlugin = { - _contextMenu : new TinyMCE_Menu(), - _menu : new TinyMCE_Menu(), - _counter : 0, - _ajaxPage : '/tinyspell.php', - - getInfo : function() { - return { - longname : 'Spellchecker', - author : 'Moxiecode Systems AB', - authorurl : 'http://tinymce.moxiecode.com', - infourl : 'http://tinymce.moxiecode.com/tinymce/docs/plugin_spellchecker.html', - version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion - }; - }, - - handleEvent : function(e) { - var elm = tinyMCE.isMSIE ? e.srcElement : e.target; - var inst = tinyMCE.selectedInstance, args = ''; - var self = TinyMCE_SpellCheckerPlugin; - var cm = self._contextMenu; - var p, p2, x, y, sx, sy, h, elm; - - // Handle click on word - if ((e.type == "click" || e.type == "contextmenu") && elm) { - do { - if (tinyMCE.getAttrib(elm, 'class') == "mceItemHiddenSpellWord") { - inst.spellCheckerElm = elm; - - // Setup arguments - args += 'id=' + inst.editorId + "|" + (++self._counter); - args += '&cmd=suggest&check=' + encodeURIComponent(elm.innerHTML); - args += '&lang=' + escape(inst.spellCheckerLang); - - elm = inst.spellCheckerElm; - p = tinyMCE.getAbsPosition(inst.iframeElement); - p2 = tinyMCE.getAbsPosition(elm); - h = parseInt(elm.offsetHeight); - sx = inst.getBody().scrollLeft; - sy = inst.getBody().scrollTop; - x = p.absLeft + p2.absLeft - sx; - y = p.absTop + p2.absTop - sy + h; - - cm.clear(); - cm.addTitle(tinyMCE.getLang('lang_spellchecker_wait', '', true)); - cm.show(); - cm.moveTo(x, y); - - inst.selection.selectNode(elm, false, false); - - self._sendAjax(self.baseURL + self._ajaxPage, self._ajaxResponse, 'post', args); - - tinyMCE.cancelEvent(e); - return false; +(function() { + var JSONRequest = tinymce.util.JSONRequest, each = tinymce.each, DOM = tinymce.DOM; + + tinymce.create('tinymce.plugins.SpellcheckerPlugin', { + getInfo : function() { + return { + longname : 'Spellchecker', + author : 'Moxiecode Systems AB', + authorurl : 'http://tinymce.moxiecode.com', + infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/spellchecker', + version : "2.0.2" + }; + }, + + init : function(ed, url) { + var t = this, cm; + + t.url = url; + t.editor = ed; + + // Register commands + ed.addCommand('mceSpellCheck', function() { + if (!t.active) { + ed.setProgressState(1); + t._sendRPC('checkWords', [t.selectedLang, t._getWords()], function(r) { + if (r.length > 0) { + t.active = 1; + t._markWords(r); + ed.setProgressState(0); + ed.nodeChanged(); + } else { + ed.setProgressState(0); + ed.windowManager.alert('spellchecker.no_mpell'); + } + }); + } else + t._done(); + }); + + ed.onInit.add(function() { + if (ed.settings.content_css !== false) + ed.dom.loadCSS(url + '/css/content.css'); + }); + + ed.onClick.add(t._showMenu, t); + ed.onContextMenu.add(t._showMenu, t); + ed.onBeforeGetContent.add(function() { + if (t.active) + t._removeWords(); + }); + + ed.onNodeChange.add(function(ed, cm) { + cm.setActive('spellchecker', t.active); + }); + + ed.onSetContent.add(function() { + t._done(); + }); + + ed.onBeforeGetContent.add(function() { + t._done(); + }); + + ed.onBeforeExecCommand.add(function(ed, cmd) { + if (cmd == 'mceFullScreen') + t._done(); + }); + + // Find selected language + t.languages = {}; + each(ed.getParam('spellchecker_languages', '+English=en,Danish=da,Dutch=nl,Finnish=fi,French=fr,German=de,Italian=it,Polish=pl,Portuguese=pt,Spanish=es,Swedish=sv', 'hash'), function(v, k) { + if (k.indexOf('+') === 0) { + k = k.substring(1); + t.selectedLang = v; } - } while ((elm = elm.parentNode)); - } - - return true; - }, - - initInstance : function(inst) { - var self = TinyMCE_SpellCheckerPlugin, m = self._menu, cm = self._contextMenu, e; - - tinyMCE.importCSS(inst.getDoc(), tinyMCE.baseURL + "/plugins/spellchecker/css/content.css"); - - if (!tinyMCE.hasMenu('spellcheckercontextmenu')) { - tinyMCE.importCSS(document, tinyMCE.baseURL + "/plugins/spellchecker/css/spellchecker.css"); - - cm.init({drop_menu : false}); - tinyMCE.addMenu('spellcheckercontextmenu', cm); - } - - if (!tinyMCE.hasMenu('spellcheckermenu')) { - m.init({}); - tinyMCE.addMenu('spellcheckermenu', m); - } - - inst.spellCheckerLang = 'en'; - self._buildSettingsMenu(inst, null); - - e = self._getBlockBoxLayer(inst).create('div', 'mceBlockBox', document.getElementById(inst.editorId + '_parent')); - self._getMsgBoxLayer(inst).create('div', 'mceMsgBox', document.getElementById(inst.editorId + '_parent')); - }, - - _getMsgBoxLayer : function(inst) { - if (!inst.spellCheckerMsgBoxL) - inst.spellCheckerMsgBoxL = new TinyMCE_Layer(inst.editorId + '_spellcheckerMsgBox', false); - return inst.spellCheckerMsgBoxL; - }, + t.languages[k] = v; + }); + }, - _getBlockBoxLayer : function(inst) { - if (!inst.spellCheckerBoxL) - inst.spellCheckerBoxL = new TinyMCE_Layer(inst.editorId + '_spellcheckerBlockBox', false); + createControl : function(n, cm) { + var t = this, c, ed = t.editor; - return inst.spellCheckerBoxL; - }, + if (n == 'spellchecker') { + c = cm.createSplitButton(n, {title : 'spellchecker.desc', cmd : 'mceSpellCheck', scope : t}); - _buildSettingsMenu : function(inst, lang) { - var i, ar = tinyMCE.getParam('spellchecker_languages', '+English=en').split(','), p; - var self = TinyMCE_SpellCheckerPlugin, m = self._menu, c; + c.onRenderMenu.add(function(c, m) { + m.add({title : 'spellchecker.langs', 'class' : 'mceMenuItemTitle'}).setDisabled(1); + each(t.languages, function(v, k) { + var o = {icon : 1}, mi; - m.clear(); - m.addTitle(tinyMCE.getLang('lang_spellchecker_langs', '', true)); + o.onclick = function() { + mi.setSelected(1); + t.selectedItem.setSelected(0); + t.selectedItem = mi; + t.selectedLang = v; + }; - for (i=0; i'; - h += ''; - h += ''; - h += ''; - } else { - if (tinyMCE.isMSIE && !tinyMCE.isOpera) - h += ''; - else - h += ''; - - h += ''; - h += ''; - h += ''; - h += ''; - } - - return h; - }, - - _menuButtonEvent : function(e, o) { - if (o.className == 'mceMenuButtonFocus') - return; - - if (e == 'over') - o.className = o.className + ' mceMenuHover'; - else - o.className = o.className.replace(/\s.*$/, ''); - }, + }, - _toggleMenu : function(editor_id, id) { - var self = TinyMCE_SpellCheckerPlugin; - var e = document.getElementById(editor_id + '_spellchecker'); - var inst = tinyMCE.getInstanceById(editor_id); + // Internal functions - if (self._menu.isVisible()) { - tinyMCE.hideMenus(); - return; - } - - tinyMCE.lastMenuBtnClass = e.className.replace(/\s.*$/, ''); - tinyMCE.switchClass(editor_id + '_spellchecker', 'mceMenuButtonFocus'); - - self._menu.moveRelativeTo(e, 'bl'); - self._menu.moveBy(tinyMCE.isMSIE && !tinyMCE.isOpera ? 0 : 1, -1); - - if (tinyMCE.isOpera) - self._menu.moveBy(0, -2); - - self._onMenuEvent(inst, self._menu, 'show'); - - self._menu.show(); - - tinyMCE.lastSelectedMenuBtn = editor_id + '_spellchecker'; - }, + _walk : function(n, f) { + var d = this.editor.getDoc(), w; - _onMenuEvent : function(inst, m, n) { - TinyMCE_SpellCheckerPlugin._buildSettingsMenu(inst, inst.spellCheckerLang); - }, + if (d.createTreeWalker) { + w = d.createTreeWalker(n, NodeFilter.SHOW_TEXT, null, false); - execCommand : function(editor_id, element, command, user_interface, value) { - var inst = tinyMCE.getInstanceById(editor_id), self = TinyMCE_SpellCheckerPlugin, args = '', co, bb, mb, nl, i, e; + while ((n = w.nextNode()) != null) + f.call(this, n); + } else + tinymce.walk(n, f, 'childNodes'); + }, - // Handle commands - switch (command) { - case "mceSpellCheck": - if (!inst.spellcheckerOn) { - inst.spellCheckerBookmark = inst.selection.getBookmark(); + _getSeparators : function() { + var re = '', i, str = this.editor.getParam('spellchecker_word_separator_chars', '\\s!"#$%&()*+,-./:;<=>?@[\]^_{|}§©«®±¶·¸»¼½¾¿×÷¤\u201d\u201c'); - // Setup arguments - args += 'id=' + inst.editorId + "|" + (++self._counter); - args += '&cmd=spell&check=' + encodeURIComponent(self._getWordList(inst.getBody())).replace( /\'/g, '%27' ); - args += '&lang=' + escape(inst.spellCheckerLang); + // Build word separator regexp + for (i=0; i'; - mb.show(); - mb.moveRelativeTo(co, 'cc'); + _getWords : function() { + var ed = this.editor, wl = [], tx = '', lo = {}; - if (tinyMCE.isMSIE && !tinyMCE.isOpera) { - nl = co.getElementsByTagName('select'); - for (i=0; i?@[\]^_{|}§©«®±¶·¸»¼½¾¿×÷¤\u201d\u201c'); - - for (i=0; i 0) - wl[wl.length] = nl[i]; - } + }); - return wl.join(' '); - }, + se.moveToBookmark(b); + }, - _removeWords : function(doc, word) { - var i, c, nl = doc.getElementsByTagName("span"); - var self = TinyMCE_SpellCheckerPlugin; - var inst = tinyMCE.selectedInstance, b = inst ? inst.selection.getBookmark() : null; + _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(); - word = typeof(word) == 'undefined' ? null : word; - - for (i=nl.length-1; i>=0; i--) { - c = tinyMCE.getAttrib(nl[i], 'class'); - - if ((c == 'mceItemHiddenSpellWord' || c == 'mceItemHidden') && (word == null || nl[i].innerHTML == word)) - self._removeWord(nl[i]); - } + each(wl, function(v) { + w += (w ? '|' : '') + v; + }); - if (b) - inst.selection.moveToBookmark(b); - }, - - _checkDone : function(inst) { - var self = TinyMCE_SpellCheckerPlugin; - var w = self._countWords(inst); - - if (w == 0) { - self._removeWords(inst.getDoc()); - inst.spellcheckerOn = false; - tinyMCE.switchClass(inst.editorId + '_spellchecker', 'mceMenuButton'); - } - }, - - _countWords : function(inst) { - var i, w = 0, nl = inst.getDoc().getElementsByTagName("span"), c; - var self = TinyMCE_SpellCheckerPlugin; + 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'); - for (i=nl.length-1; i>=0; i--) { - c = tinyMCE.getAttrib(nl[i], 'class'); + // Collect all text nodes + this._walk(this.editor.getBody(), function(n) { + if (n.nodeType == 3) { + nl.push(n); + } + }); - if (c == 'mceItemHiddenSpellWord') - w++; - } + // Wrap incorrect words in spans + each(nl, function(n) { + var v; - return w; - }, + if (n.nodeType == 3) { + v = n.nodeValue; - _removeWord : function(e) { - if (e != null) - tinyMCE.setOuterHTML(e, e.innerHTML); - }, + 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'); - _markWords : function(doc, n, wl) { - var i, nv, nn, nl = tinyMCE.getNodeTree(n, new Array(), 3); - var r1, r2, r3, r4, r5, w = ''; - var re = TinyMCE_SpellCheckerPlugin._getWordSeparators(); + dom.replace(dom.create('span', {'class' : 'mceItemHidden'}, v), n); + } + } + }); - for (i=0; i 0) - w += wl[i] + ((i == wl.length-1) ? '' : '|'); - } + se.moveToBookmark(b); + }, - for (i=0; i$1$2'); - nv = nv.replace(r3, '$1$2'); + if (!m) { + p1 = DOM.getPos(ed.getContentAreaContainer()); + //p2 = DOM.getPos(ed.getContainer()); - nn = doc.createElement('span'); - nn.className = "mceItemHidden"; - nn.innerHTML = nv; + m = ed.controlManager.createDropMenu('spellcheckermenu', { + offset_x : p1.x, + offset_y : p1.y, + 'class' : 'mceNoIcons' + }); - // Remove old text node - nl[i].parentNode.replaceChild(nn, nl[i]); + t._menu = m; } - } - }, - _buildMenu : function(sg, max) { - var i, self = TinyMCE_SpellCheckerPlugin, cm = self._contextMenu; + if (dom.hasClass(e.target, 'mceItemHiddenSpellWord')) { + m.removeAll(); + m.add({title : 'spellchecker.wait', 'class' : 'mceMenuItemTitle'}).setDisabled(1); + + t._sendRPC('getSuggestions', [t.selectedLang, dom.decode(e.target.innerHTML)], function(r) { + m.removeAll(); + + if (r.length > 0) { + m.add({title : 'spellchecker.sug', 'class' : 'mceMenuItemTitle'}).setDisabled(1); + each(r, function(v) { + m.add({title : v, onclick : function() { + dom.replace(ed.getDoc().createTextNode(v), e.target); + t._checkDone(); + }}); + }); + + m.addSeparator(); + } else + m.add({title : 'spellchecker.no_sug', 'class' : 'mceMenuItemTitle'}).setDisabled(1); + + m.add({ + title : 'spellchecker.ignore_word', + onclick : function() { + dom.remove(e.target, 1); + t._checkDone(); + } + }); + + m.add({ + title : 'spellchecker.ignore_words', + onclick : function() { + t._removeWords(dom.decode(e.target.innerHTML)); + t._checkDone(); + } + }); + + m.update(); + }); + + ed.selection.select(e.target); + p1 = dom.getPos(e.target); + m.showMenu(p1.x, p1.y + e.target.offsetHeight - vp.y); + + return tinymce.dom.Event.cancel(e); + } else + m.hideMenu(); + }, + + _checkDone : function() { + var t = this, ed = t.editor, dom = ed.dom, o; + + each(dom.select('span'), function(n) { + if (n && dom.hasClass(n, 'mceItemHiddenSpellWord')) { + o = true; + return false; + } + }); - cm.clear(); + if (!o) + t._done(); + }, - if (sg != null) { - cm.addTitle(tinyMCE.getLang('lang_spellchecker_sug', '', true)); + _done : function() { + var t = this, la = t.active; - for (i=0; i