| | |
| | | /**
|
| | | * $Id: editor_plugin_src.js 425 2007-11-21 15:17:39Z spocke $
|
| | | * editor_plugin_src.js
|
| | | *
|
| | | * @author Moxiecode
|
| | | * @copyright Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved.
|
| | | * Copyright 2009, Moxiecode Systems AB
|
| | | * Released under LGPL License.
|
| | | *
|
| | | * License: http://tinymce.moxiecode.com/license
|
| | | * Contributing: http://tinymce.moxiecode.com/contributing
|
| | | */
|
| | |
|
| | | (function() {
|
| | |
| | |
|
| | | t.url = url;
|
| | | t.editor = ed;
|
| | | t.rpcUrl = ed.getParam("spellchecker_rpc_url", "{backend}");
|
| | |
|
| | | if (t.rpcUrl == '{backend}') {
|
| | | // Sniff if the browser supports native spellchecking (Don't know of a better way)
|
| | | if (tinymce.isIE)
|
| | | return;
|
| | |
|
| | | t.hasSupport = true;
|
| | |
|
| | | // Disable the context menu when spellchecking is active
|
| | | ed.onContextMenu.addToTop(function(ed, e) {
|
| | | if (t.active)
|
| | | return false;
|
| | | });
|
| | | }
|
| | |
|
| | | // Register commands
|
| | | ed.addCommand('mceSpellCheck', function() {
|
| | | if (t.rpcUrl == '{backend}') {
|
| | | // Enable/disable native spellchecker
|
| | | t.editor.getBody().spellcheck = t.active = !t.active;
|
| | | return;
|
| | | }
|
| | |
|
| | | if (!t.active) {
|
| | | ed.setProgressState(1);
|
| | | t._sendRPC('checkWords', [t.selectedLang, t._getWords()], function(r) {
|
| | |
| | | ed.nodeChanged();
|
| | | } else {
|
| | | ed.setProgressState(0);
|
| | | ed.windowManager.alert('spellchecker.no_mpell');
|
| | |
|
| | | if (ed.getParam('spellchecker_report_no_misspellings', true))
|
| | | ed.windowManager.alert('spellchecker.no_mpell');
|
| | | }
|
| | | });
|
| | | } else
|
| | |
| | | var t = this, c, ed = t.editor;
|
| | |
|
| | | if (n == 'spellchecker') {
|
| | | // Use basic button if we use the native spellchecker
|
| | | if (t.rpcUrl == '{backend}') {
|
| | | // Create simple toggle button if we have native support
|
| | | if (t.hasSupport)
|
| | | c = cm.createButton(n, {title : 'spellchecker.desc', cmd : 'mceSpellCheck', scope : t});
|
| | |
|
| | | return c;
|
| | | }
|
| | |
|
| | | c = cm.createSplitButton(n, {title : 'spellchecker.desc', cmd : 'mceSpellCheck', scope : t});
|
| | |
|
| | | c.onRenderMenu.add(function(c, m) {
|
| | |
| | | },
|
| | |
|
| | | _getWords : function() {
|
| | | var ed = this.editor, wl = [], tx = '', lo = {};
|
| | | var ed = this.editor, wl = [], tx = '', lo = {}, rawWords = [];
|
| | |
|
| | | // Get area text
|
| | | this._walk(ed.getBody(), function(n) {
|
| | |
| | | tx += n.nodeValue + ' ';
|
| | | });
|
| | |
|
| | | // Split words by separator
|
| | | tx = tx.replace(new RegExp('([0-9]|[' + this._getSeparators() + '])', 'g'), ' ');
|
| | | tx = tinymce.trim(tx.replace(/(\s+)/g, ' '));
|
| | | // split the text up into individual words
|
| | | if (ed.getParam('spellchecker_word_pattern')) {
|
| | | // look for words that match the pattern
|
| | | rawWords = tx.match('(' + ed.getParam('spellchecker_word_pattern') + ')', 'gi');
|
| | | } else {
|
| | | // Split words by separator
|
| | | tx = tx.replace(new RegExp('([0-9]|[' + this._getSeparators() + '])', 'g'), ' ');
|
| | | tx = tinymce.trim(tx.replace(/(\s+)/g, ' '));
|
| | | rawWords = tx.split(' ');
|
| | | }
|
| | |
|
| | | // Build word array and remove duplicates
|
| | | each(tx.split(' '), function(v) {
|
| | | each(rawWords, function(v) {
|
| | | if (!lo[v]) {
|
| | | wl.push(v);
|
| | | lo[v] = 1;
|
| | |
| | | },
|
| | |
|
| | | _showMenu : function(ed, e) {
|
| | | var t = this, ed = t.editor, m = t._menu, p1, dom = ed.dom, vp = dom.getViewPort(ed.getWin());
|
| | | var t = this, ed = t.editor, m = t._menu, p1, dom = ed.dom, vp = dom.getViewPort(ed.getWin()), wordSpan = e.target;
|
| | |
|
| | | e = 0; // Fixes IE memory leak
|
| | |
|
| | | if (!m) {
|
| | | p1 = DOM.getPos(ed.getContentAreaContainer());
|
| | |
| | | t._menu = m;
|
| | | }
|
| | |
|
| | | if (dom.hasClass(e.target, 'mceItemHiddenSpellWord')) {
|
| | | if (dom.hasClass(wordSpan, 'mceItemHiddenSpellWord')) {
|
| | | m.removeAll();
|
| | | m.add({title : 'spellchecker.wait', 'class' : 'mceMenuItemTitle'}).setDisabled(1);
|
| | |
|
| | | t._sendRPC('getSuggestions', [t.selectedLang, dom.decode(e.target.innerHTML)], function(r) {
|
| | | t._sendRPC('getSuggestions', [t.selectedLang, dom.decode(wordSpan.innerHTML)], function(r) {
|
| | | var ignoreRpc;
|
| | |
|
| | | 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);
|
| | | dom.replace(ed.getDoc().createTextNode(v), wordSpan);
|
| | | t._checkDone();
|
| | | }});
|
| | | });
|
| | |
| | | } else
|
| | | m.add({title : 'spellchecker.no_sug', 'class' : 'mceMenuItemTitle'}).setDisabled(1);
|
| | |
|
| | | ignoreRpc = t.editor.getParam("spellchecker_enable_ignore_rpc", '');
|
| | | m.add({
|
| | | title : 'spellchecker.ignore_word',
|
| | | onclick : function() {
|
| | | dom.remove(e.target, 1);
|
| | | var word = wordSpan.innerHTML;
|
| | |
|
| | | dom.remove(wordSpan, 1);
|
| | | t._checkDone();
|
| | |
|
| | | // tell the server if we need to
|
| | | if (ignoreRpc) {
|
| | | ed.setProgressState(1);
|
| | | t._sendRPC('ignoreWord', [t.selectedLang, word], function(r) {
|
| | | ed.setProgressState(0);
|
| | | });
|
| | | }
|
| | | }
|
| | | });
|
| | |
|
| | | m.add({
|
| | | title : 'spellchecker.ignore_words',
|
| | | onclick : function() {
|
| | | t._removeWords(dom.decode(e.target.innerHTML));
|
| | | var word = wordSpan.innerHTML;
|
| | |
|
| | | t._removeWords(dom.decode(word));
|
| | | t._checkDone();
|
| | |
|
| | | // tell the server if we need to
|
| | | if (ignoreRpc) {
|
| | | ed.setProgressState(1);
|
| | | t._sendRPC('ignoreWords', [t.selectedLang, word], function(r) {
|
| | | ed.setProgressState(0);
|
| | | });
|
| | | }
|
| | | }
|
| | | });
|
| | |
|
| | |
|
| | | if (t.editor.getParam("spellchecker_enable_learn_rpc")) {
|
| | | m.add({
|
| | | title : 'spellchecker.learn_word',
|
| | | onclick : function() {
|
| | | var word = wordSpan.innerHTML;
|
| | |
|
| | | dom.remove(wordSpan, 1);
|
| | | t._checkDone();
|
| | |
|
| | | ed.setProgressState(1);
|
| | | t._sendRPC('learnWord', [t.selectedLang, word], function(r) {
|
| | | ed.setProgressState(0);
|
| | | });
|
| | | }
|
| | | });
|
| | | }
|
| | |
|
| | | m.update();
|
| | | });
|
| | |
|
| | | ed.selection.select(e.target);
|
| | | p1 = dom.getPos(e.target);
|
| | | m.showMenu(p1.x, p1.y + e.target.offsetHeight - vp.y);
|
| | | ed.selection.select(wordSpan);
|
| | | p1 = dom.getPos(wordSpan);
|
| | | m.showMenu(p1.x, p1.y + wordSpan.offsetHeight - vp.y);
|
| | |
|
| | | return tinymce.dom.Event.cancel(e);
|
| | | } else
|
| | |
| | | },
|
| | |
|
| | | _sendRPC : function(m, p, cb) {
|
| | | var t = this, url = t.editor.getParam("spellchecker_rpc_url", "{backend}");
|
| | |
|
| | | if (url == '{backend}') {
|
| | | t.editor.setProgressState(0);
|
| | | alert('Please specify: spellchecker_rpc_url');
|
| | | return;
|
| | | }
|
| | | var t = this;
|
| | |
|
| | | JSONRequest.sendRPC({
|
| | | url : url,
|
| | | url : t.rpcUrl,
|
| | | method : m,
|
| | | params : p,
|
| | | success : cb,
|
| | |
| | |
|
| | | // Register plugin
|
| | | tinymce.PluginManager.add('spellchecker', tinymce.plugins.SpellcheckerPlugin);
|
| | | })(); |
| | | })();
|