Update TinyMCE to 3.5.3, enable stripping of Word styles on paste

This commit is contained in:
grahamtriggs 2015-10-14 22:17:16 +01:00
parent 83404c2c80
commit 48790b7525
274 changed files with 25268 additions and 14504 deletions

0
webapp/web/js/tiny_mce/plugins/spellchecker/css/content.css vendored Executable file → Normal file
View file

2
webapp/web/js/tiny_mce/plugins/spellchecker/editor_plugin.js vendored Executable file → Normal file

File diff suppressed because one or more lines are too long

297
webapp/web/js/tiny_mce/plugins/spellchecker/editor_plugin_src.js vendored Executable file → Normal file
View file

@ -1,8 +1,11 @@
/**
* $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() {
@ -24,9 +27,30 @@
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) {
@ -37,17 +61,17 @@
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
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);
@ -89,35 +113,81 @@
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) {
m.add({title : 'spellchecker.langs', 'class' : 'mceMenuItemTitle'}).setDisabled(1);
t.menuItems = {};
each(t.languages, function(v, k) {
var o = {icon : 1}, mi;
o.onclick = function() {
mi.setSelected(1);
t.selectedItem.setSelected(0);
t.selectedItem = mi;
if (v == t.selectedLang) {
return;
}
t._updateMenu(mi);
t.selectedLang = v;
};
o.title = k;
mi = m.add(o);
mi.setSelected(v == t.selectedLang);
t.menuItems[v] = mi;
if (v == t.selectedLang)
t.selectedItem = mi;
})
});
});
return c;
}
},
setLanguage: function(lang) {
var t = this;
if (lang == t.selectedLang) {
// allowed
return;
}
if (tinymce.grep(t.languages, function(v) { return v === lang; }).length === 0) {
throw "Unknown language: " + lang;
}
t.selectedLang = lang;
// if the menu has been shown, update it as well
if (t.menuItems) {
t._updateMenu(t.menuItems[lang]);
}
if (t.active) {
// clear error in the old language.
t._done();
// Don't immediately block the UI to check spelling in the new language, this is an API not a user action.
}
},
// Internal functions
_updateMenu: function(mi) {
mi.setSelected(1);
this.selectedItem.setSelected(0);
this.selectedItem = mi;
},
_walk : function(n, f) {
var d = this.editor.getDoc(), w;
@ -141,7 +211,7 @@
},
_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) {
@ -149,12 +219,19 @@
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;
@ -165,7 +242,7 @@
},
_removeWords : function(w) {
var ed = this.editor, dom = ed.dom, se = ed.selection, b = se.getBookmark();
var ed = this.editor, dom = ed.dom, se = ed.selection, r = se.getRng(true);
each(dom.select('span').reverse(), function(n) {
if (n && (dom.hasClass(n, 'mceItemHiddenSpellWord') || dom.hasClass(n, 'mceItemHidden'))) {
@ -174,25 +251,15 @@
}
});
se.moveToBookmark(b);
se.setRng(r);
},
_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, r = se.getRng(true), 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);
}
@ -200,52 +267,80 @@
// 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;
rx.lastIndex = 0;
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');
dom.replace(dom.create('span', {'class' : 'mceItemHidden'}, v), n);
// 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>');
}
// Finally, replace the node with the container
dom.replace(elem, n);
}
});
se.moveToBookmark(b);
se.setRng(r);
},
_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());
//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;
}
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();
}});
});
@ -254,28 +349,72 @@
} 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();
}
});
if (ed.getParam('show_ignore_words', true)) {
ignoreRpc = t.editor.getParam("spellchecker_enable_ignore_rpc", '');
m.add({
title : 'spellchecker.ignore_word',
onclick : function() {
var word = wordSpan.innerHTML;
m.add({
title : 'spellchecker.ignore_words',
onclick : function() {
t._removeWords(dom.decode(e.target.innerHTML));
t._checkDone();
}
});
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() {
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);
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);
return tinymce.dom.Event.cancel(e);
} else
@ -312,16 +451,10 @@
},
_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,
@ -335,4 +468,4 @@
// Register plugin
tinymce.PluginManager.add('spellchecker', tinymce.plugins.SpellcheckerPlugin);
})();
})();

0
webapp/web/js/tiny_mce/plugins/spellchecker/img/wline.gif vendored Executable file → Normal file
View file

Before

Width:  |  Height:  |  Size: 46 B

After

Width:  |  Height:  |  Size: 46 B

Before After
Before After