Commit c92411cc authored by Robert Lyon's avatar Robert Lyon Committed by Gerrit Code Review
Browse files

Merge "Update TinyMCE to 4.1.9"

parents 312f65f0 f719cd35
......@@ -2,7 +2,7 @@ TinyMCE
========
Website: http://tinymce.moxiecode.com/
Version: 4.0.16
Version: 4.1.9
Based on development version
......
......@@ -18,7 +18,9 @@ tinymce.PluginManager.add('advlist', function(editor) {
tinymce.each(styleValues.split(/[ ,]/), function(styleValue) {
items.push({
text: styleValue.replace(/\-/g, ' ').replace(/\b\w/g, function(chr) {return chr.toUpperCase();}),
text: styleValue.replace(/\-/g, ' ').replace(/\b\w/g, function(chr) {
return chr.toUpperCase();
}),
data: styleValue == 'default' ? '' : styleValue
});
});
......@@ -34,27 +36,29 @@ tinymce.PluginManager.add('advlist', function(editor) {
ulMenuItems = buildMenuItems('UL', editor.getParam("advlist_bullet_styles", "default,circle,disc,square"));
function applyListFormat(listName, styleValue) {
var list, dom = editor.dom, sel = editor.selection;
editor.undoManager.transact(function() {
var list, dom = editor.dom, sel = editor.selection;
// Check for existing list element
list = dom.getParent(sel.getNode(), 'ol,ul');
// Check for existing list element
list = dom.getParent(sel.getNode(), 'ol,ul');
// Switch/add list type if needed
if (!list || list.nodeName != listName || styleValue === false) {
editor.execCommand(listName == 'UL' ? 'InsertUnorderedList' : 'InsertOrderedList');
}
// Switch/add list type if needed
if (!list || list.nodeName != listName || styleValue === false) {
editor.execCommand(listName == 'UL' ? 'InsertUnorderedList' : 'InsertOrderedList');
}
// Set style
styleValue = styleValue === false ? lastStyles[listName] : styleValue;
lastStyles[listName] = styleValue;
// Set style
styleValue = styleValue === false ? lastStyles[listName] : styleValue;
lastStyles[listName] = styleValue;
list = dom.getParent(sel.getNode(), 'ol,ul');
if (list) {
dom.setStyle(list, 'listStyleType', styleValue);
list.removeAttribute('data-mce-style');
}
list = dom.getParent(sel.getNode(), 'ol,ul');
if (list) {
dom.setStyle(list, 'listStyleType', styleValue ? styleValue : null);
list.removeAttribute('data-mce-style');
}
editor.focus();
editor.focus();
});
}
function updateSelection(e) {
......
......@@ -12,11 +12,15 @@
tinymce.PluginManager.add('anchor', function(editor) {
function showDialog() {
var selectedNode = editor.selection.getNode();
var selectedNode = editor.selection.getNode(), name = '';
if (selectedNode.tagName == 'A') {
name = selectedNode.name || selectedNode.id || '';
}
editor.windowManager.open({
title: 'Anchor',
body: {type: 'textbox', name: 'name', size: 40, label: 'Name', value: selectedNode.name || selectedNode.id},
body: {type: 'textbox', name: 'name', size: 40, label: 'Name', value: name},
onsubmit: function(e) {
editor.execCommand('mceInsertContent', false, editor.dom.createHTML('a', {
id: e.data.name
......
......@@ -11,6 +11,8 @@
/*global tinymce:true */
tinymce.PluginManager.add('autolink', function(editor) {
var AutoUrlDetectState;
editor.on("keydown", function(e) {
if (e.keyCode == 13) {
return handleEnter(editor);
......@@ -19,11 +21,15 @@ tinymce.PluginManager.add('autolink', function(editor) {
// Internet Explorer has built-in automatic linking for most cases
if (tinymce.Env.ie) {
editor.on("init", function() {
try {
editor.execCommand('AutoUrlDetect', false, true);
} catch (ex) {
// Ignore
editor.on("focus", function() {
if (!AutoUrlDetectState) {
AutoUrlDetectState = true;
try {
editor.execCommand('AutoUrlDetect', false, true);
} catch (ex) {
// Ignore
}
}
});
......@@ -31,7 +37,7 @@ tinymce.PluginManager.add('autolink', function(editor) {
}
editor.on("keypress", function(e) {
if (e.which == 41) {
if (e.keyCode == 41) {
return handleEclipse(editor);
}
});
......@@ -55,7 +61,39 @@ tinymce.PluginManager.add('autolink', function(editor) {
}
function parseCurrentLine(editor, end_offset, delimiter) {
var rng, end, start, endContainer, bookmark, text, matches, prev, len;
var rng, end, start, endContainer, bookmark, text, matches, prev, len, rngText;
function scopeIndex(container, index) {
if (index < 0) {
index = 0;
}
if (container.nodeType == 3) {
var len = container.data.length;
if (index > len) {
index = len;
}
}
return index;
}
function setStart(container, offset) {
if (container.nodeType != 1 || container.hasChildNodes()) {
rng.setStart(container, scopeIndex(container, offset));
} else {
rng.setStartBefore(container);
}
}
function setEnd(container, offset) {
if (container.nodeType != 1 || container.hasChildNodes()) {
rng.setEnd(container, scopeIndex(container, offset));
} else {
rng.setEndAfter(container);
}
}
// We need at least five characters to form a URL,
// hence, at minimum, five characters from the beginning of the line.
......@@ -73,8 +111,8 @@ tinymce.PluginManager.add('autolink', function(editor) {
}
len = prev.length;
rng.setStart(prev, len);
rng.setEnd(prev, len);
setStart(prev, len);
setEnd(prev, len);
if (rng.endOffset < 5) {
return;
......@@ -93,8 +131,8 @@ tinymce.PluginManager.add('autolink', function(editor) {
// Move range to text node
if (endContainer.nodeType == 3) {
rng.setStart(endContainer, 0);
rng.setEnd(endContainer, endContainer.nodeValue.length);
setStart(endContainer, 0);
setEnd(endContainer, endContainer.nodeValue.length);
}
}
......@@ -109,31 +147,30 @@ tinymce.PluginManager.add('autolink', function(editor) {
do {
// Move the selection one character backwards.
rng.setStart(endContainer, end >= 2 ? end - 2 : 0);
rng.setEnd(endContainer, end >= 1 ? end - 1 : 0);
setStart(endContainer, end >= 2 ? end - 2 : 0);
setEnd(endContainer, end >= 1 ? end - 1 : 0);
end -= 1;
rngText = rng.toString();
// Loop until one of the following is found: a blank space, &nbsp;, delimiter, (end-2) >= 0
} while (rng.toString() != ' ' && rng.toString() !== '' &&
rng.toString().charCodeAt(0) != 160 && (end -2) >= 0 && rng.toString() != delimiter);
} while (rngText != ' ' && rngText !== '' && rngText.charCodeAt(0) != 160 && (end - 2) >= 0 && rngText != delimiter);
if (rng.toString() == delimiter || rng.toString().charCodeAt(0) == 160) {
rng.setStart(endContainer, end);
rng.setEnd(endContainer, start);
setStart(endContainer, end);
setEnd(endContainer, start);
end += 1;
} else if (rng.startOffset === 0) {
rng.setStart(endContainer, 0);
rng.setEnd(endContainer, start);
}
else {
rng.setStart(endContainer, end);
rng.setEnd(endContainer, start);
setStart(endContainer, 0);
setEnd(endContainer, start);
} else {
setStart(endContainer, end);
setEnd(endContainer, start);
}
// Exclude last . from word like "www.site.com."
text = rng.toString();
if (text.charAt(text.length - 1) == '.') {
rng.setEnd(endContainer, start - 1);
setEnd(endContainer, start - 1);
}
text = rng.toString();
......@@ -152,16 +189,6 @@ tinymce.PluginManager.add('autolink', function(editor) {
editor.execCommand('createlink', false, matches[1] + matches[2]);
editor.selection.moveToBookmark(bookmark);
editor.nodeChanged();
// TODO: Determine if this is still needed.
if (tinymce.Env.webkit) {
// move the caret to its original position
editor.selection.collapse(false);
var max = Math.min(endContainer.length, start + 1);
rng.setStart(endContainer, max);
rng.setEnd(endContainer, max);
editor.selection.setRng(rng);
}
}
}
});
......@@ -9,6 +9,7 @@
*/
/*global tinymce:true */
/*eslint no-nested-ternary:0 */
/**
* Auto Resize
......@@ -20,6 +21,10 @@
tinymce.PluginManager.add('autoresize', function(editor) {
var settings = editor.settings, oldSize = 0;
function isFullscreen() {
return editor.plugins.fullscreen && editor.plugins.fullscreen.isFullscreen();
}
if (editor.settings.inline) {
return;
}
......@@ -28,18 +33,37 @@ tinymce.PluginManager.add('autoresize', function(editor) {
* This method gets executed each time the editor needs to resize.
*/
function resize(e) {
var deltaSize, d = editor.getDoc(), body = d.body, de = d.documentElement, DOM = tinymce.DOM,
resizeHeight = settings.autoresize_min_height, myHeight, marginTop, marginBottom;
var deltaSize, doc, body, docElm, DOM = tinymce.DOM, resizeHeight, myHeight,
marginTop, marginBottom, paddingTop, paddingBottom, borderTop, borderBottom;
doc = editor.getDoc();
if (!doc) {
return;
}
body = doc.body;
docElm = doc.documentElement;
resizeHeight = settings.autoresize_min_height;
if (!body || (e && e.type === "setcontent" && e.initial) || isFullscreen()) {
if (body && docElm) {
body.style.overflowY = "auto";
docElm.style.overflowY = "auto"; // Old IE
}
if (!body || !e || (e.type === "setcontent" && e.initial) ||
(editor.plugins.fullscreen && editor.plugins.fullscreen.isFullscreen())) {
return;
}
// Calculate outer height of the body element using CSS styles
marginTop = editor.dom.getStyle(body, 'margin-top', true);
marginBottom = editor.dom.getStyle(body, 'margin-bottom', true);
myHeight = body.offsetHeight + parseInt(marginTop, 10) + parseInt(marginBottom, 10);
paddingTop = editor.dom.getStyle(body, 'padding-top', true);
paddingBottom = editor.dom.getStyle(body, 'padding-bottom', true);
borderTop = editor.dom.getStyle(body, 'border-top-width', true);
borderBottom = editor.dom.getStyle(body, 'border-bottom-width', true);
myHeight = body.offsetHeight + parseInt(marginTop, 10) + parseInt(marginBottom, 10) +
parseInt(paddingTop, 10) + parseInt(paddingBottom, 10) +
parseInt(borderTop, 10) + parseInt(borderBottom, 10);
// Make sure we have a valid height
if (isNaN(myHeight) || myHeight <= 0) {
......@@ -56,17 +80,17 @@ tinymce.PluginManager.add('autoresize', function(editor) {
if (settings.autoresize_max_height && myHeight > settings.autoresize_max_height) {
resizeHeight = settings.autoresize_max_height;
body.style.overflowY = "auto";
de.style.overflowY = "auto"; // Old IE
docElm.style.overflowY = "auto"; // Old IE
} else {
body.style.overflowY = "hidden";
de.style.overflowY = "hidden"; // Old IE
docElm.style.overflowY = "hidden"; // Old IE
body.scrollTop = 0;
}
// Resize content element
if (resizeHeight !== oldSize) {
deltaSize = resizeHeight - oldSize;
DOM.setStyle(DOM.get(editor.id + '_ifr'), 'height', resizeHeight + 'px');
DOM.setStyle(editor.iframeElement, 'height', resizeHeight + 'px');
oldSize = resizeHeight;
// WebKit doesn't decrease the size of the body element until the iframe gets resized
......@@ -101,17 +125,27 @@ tinymce.PluginManager.add('autoresize', function(editor) {
// Add padding at the bottom for better UX
editor.on("init", function() {
var overflowPadding = editor.getParam('autoresize_overflow_padding', 1);
var overflowPadding, bottomMargin;
editor.dom.setStyles(editor.getBody(), {
paddingBottom: editor.getParam('autoresize_bottom_margin', 50),
paddingLeft: overflowPadding,
paddingRight: overflowPadding
});
overflowPadding = editor.getParam('autoresize_overflow_padding', 1);
bottomMargin = editor.getParam('autoresize_bottom_margin', 50);
if (overflowPadding !== false) {
editor.dom.setStyles(editor.getBody(), {
paddingLeft: overflowPadding,
paddingRight: overflowPadding
});
}
if (bottomMargin !== false) {
editor.dom.setStyles(editor.getBody(), {
paddingBottom: bottomMargin
});
}
});
// Add appropriate listeners for resizing content area
editor.on("change setcontent paste keyup", resize);
editor.on("nodechange setcontent keyup FullscreenStateChanged", resize);
if (editor.getParam('autoresize_on_init', true)) {
editor.on('init', function() {
......
......@@ -10,6 +10,28 @@
/*global tinymce:true */
// Internal unload handler will be called before the page is unloaded
// Needs to be outside the plugin since it would otherwise keep
// a reference to editor in closue scope
/*eslint no-func-assign:0 */
tinymce._beforeUnloadHandler = function() {
var msg;
tinymce.each(tinymce.editors, function(editor) {
// Store a draft for each editor instance
if (editor.plugins.autosave) {
editor.plugins.autosave.storeDraft();
}
// Setup a return message if the editor is dirty
if (!msg && editor.isDirty() && editor.getParam("autosave_ask_before_unload", true)) {
msg = editor.translate("You have unsaved changes are you sure you want to navigate away?");
}
});
return msg;
};
tinymce.PluginManager.add('autosave', function(editor) {
var settings = editor.settings, LocalStorage = tinymce.util.LocalStorage, prefix, started;
......@@ -111,29 +133,10 @@ tinymce.PluginManager.add('autosave', function(editor) {
context: 'file'
});
// Internal unload handler will be called before the page is unloaded
function beforeUnloadHandler() {
var msg;
tinymce.each(tinymce.editors, function(editor) {
// Store a draft for each editor instance
if (editor.plugins.autosave) {
editor.plugins.autosave.storeDraft();
}
// Setup a return message if the editor is dirty
if (!msg && editor.isDirty() && editor.getParam("autosave_ask_before_unload", true)) {
msg = editor.translate("You have unsaved changes are you sure you want to navigate away?");
}
});
return msg;
}
function isEmpty(html) {
var forcedRootBlockName = editor.settings.forced_root_block;
html = tinymce.trim(typeof(html) == "undefined" ? editor.getBody().innerHTML : html);
html = tinymce.trim(typeof html == "undefined" ? editor.getBody().innerHTML : html);
return html === '' || new RegExp(
'^<' + forcedRootBlockName + '[^>]*>((\u00a0|&nbsp;|[ \t]|<br[^>]*>)+?|)<\/' + forcedRootBlockName + '>|<br>$', 'i'
......@@ -152,7 +155,7 @@ tinymce.PluginManager.add('autosave', function(editor) {
});
}
window.onbeforeunload = beforeUnloadHandler;
window.onbeforeunload = tinymce._beforeUnloadHandler;
this.hasDraft = hasDraft;
this.storeDraft = storeDraft;
......
......@@ -12,20 +12,20 @@
(function() {
tinymce.create('tinymce.plugins.BBCodePlugin', {
init : function(ed) {
var t = this, dialect = ed.getParam('bbcode_dialect', 'punbb').toLowerCase();
init: function(ed) {
var self = this, dialect = ed.getParam('bbcode_dialect', 'punbb').toLowerCase();
ed.on('beforeSetContent', function(e) {
e.content = t['_' + dialect + '_bbcode2html'](e.content);
e.content = self['_' + dialect + '_bbcode2html'](e.content);
});
ed.on('postProcess', function(e) {
if (e.set) {
e.content = t['_' + dialect + '_bbcode2html'](e.content);
e.content = self['_' + dialect + '_bbcode2html'](e.content);
}
if (e.get) {
e.content = t['_' + dialect + '_html2bbcode'](e.content);
e.content = self['_' + dialect + '_html2bbcode'](e.content);
}
});
},
......@@ -42,7 +42,7 @@
// Private methods
// HTML -> BBCode in PunBB dialect
_punbb_html2bbcode : function(s) {
_punbb_html2bbcode: function(s) {
s = tinymce.trim(s);
function rep(re, str) {
......@@ -50,49 +50,49 @@
}
// example: <strong> to [b]
rep(/<a.*?href=\"(.*?)\".*?>(.*?)<\/a>/gi,"[url=$1]$2[/url]");
rep(/<font.*?color=\"(.*?)\".*?class=\"codeStyle\".*?>(.*?)<\/font>/gi,"[code][color=$1]$2[/color][/code]");
rep(/<font.*?color=\"(.*?)\".*?class=\"quoteStyle\".*?>(.*?)<\/font>/gi,"[quote][color=$1]$2[/color][/quote]");
rep(/<font.*?class=\"codeStyle\".*?color=\"(.*?)\".*?>(.*?)<\/font>/gi,"[code][color=$1]$2[/color][/code]");
rep(/<font.*?class=\"quoteStyle\".*?color=\"(.*?)\".*?>(.*?)<\/font>/gi,"[quote][color=$1]$2[/color][/quote]");
rep(/<span style=\"color: ?(.*?);\">(.*?)<\/span>/gi,"[color=$1]$2[/color]");
rep(/<font.*?color=\"(.*?)\".*?>(.*?)<\/font>/gi,"[color=$1]$2[/color]");
rep(/<span style=\"font-size:(.*?);\">(.*?)<\/span>/gi,"[size=$1]$2[/size]");
rep(/<font>(.*?)<\/font>/gi,"$1");
rep(/<img.*?src=\"(.*?)\".*?\/>/gi,"[img]$1[/img]");
rep(/<span class=\"codeStyle\">(.*?)<\/span>/gi,"[code]$1[/code]");
rep(/<span class=\"quoteStyle\">(.*?)<\/span>/gi,"[quote]$1[/quote]");
rep(/<strong class=\"codeStyle\">(.*?)<\/strong>/gi,"[code][b]$1[/b][/code]");
rep(/<strong class=\"quoteStyle\">(.*?)<\/strong>/gi,"[quote][b]$1[/b][/quote]");
rep(/<em class=\"codeStyle\">(.*?)<\/em>/gi,"[code][i]$1[/i][/code]");
rep(/<em class=\"quoteStyle\">(.*?)<\/em>/gi,"[quote][i]$1[/i][/quote]");
rep(/<u class=\"codeStyle\">(.*?)<\/u>/gi,"[code][u]$1[/u][/code]");
rep(/<u class=\"quoteStyle\">(.*?)<\/u>/gi,"[quote][u]$1[/u][/quote]");
rep(/<\/(strong|b)>/gi,"[/b]");
rep(/<(strong|b)>/gi,"[b]");
rep(/<\/(em|i)>/gi,"[/i]");
rep(/<(em|i)>/gi,"[i]");
rep(/<\/u>/gi,"[/u]");
rep(/<span style=\"text-decoration: ?underline;\">(.*?)<\/span>/gi,"[u]$1[/u]");
rep(/<u>/gi,"[u]");
rep(/<blockquote[^>]*>/gi,"[quote]");
rep(/<\/blockquote>/gi,"[/quote]");
rep(/<br \/>/gi,"\n");
rep(/<br\/>/gi,"\n");
rep(/<br>/gi,"\n");
rep(/<p>/gi,"");
rep(/<\/p>/gi,"\n");
rep(/&nbsp;|\u00a0/gi," ");
rep(/&quot;/gi,"\"");
rep(/&lt;/gi,"<");
rep(/&gt;/gi,">");
rep(/&amp;/gi,"&");
rep(/<a.*?href=\"(.*?)\".*?>(.*?)<\/a>/gi, "[url=$1]$2[/url]");
rep(/<font.*?color=\"(.*?)\".*?class=\"codeStyle\".*?>(.*?)<\/font>/gi, "[code][color=$1]$2[/color][/code]");
rep(/<font.*?color=\"(.*?)\".*?class=\"quoteStyle\".*?>(.*?)<\/font>/gi, "[quote][color=$1]$2[/color][/quote]");
rep(/<font.*?class=\"codeStyle\".*?color=\"(.*?)\".*?>(.*?)<\/font>/gi, "[code][color=$1]$2[/color][/code]");
rep(/<font.*?class=\"quoteStyle\".*?color=\"(.*?)\".*?>(.*?)<\/font>/gi, "[quote][color=$1]$2[/color][/quote]");
rep(/<span style=\"color: ?(.*?);\">(.*?)<\/span>/gi, "[color=$1]$2[/color]");
rep(/<font.*?color=\"(.*?)\".*?>(.*?)<\/font>/gi, "[color=$1]$2[/color]");
rep(/<span style=\"font-size:(.*?);\">(.*?)<\/span>/gi, "[size=$1]$2[/size]");
rep(/<font>(.*?)<\/font>/gi, "$1");
rep(/<img.*?src=\"(.*?)\".*?\/>/gi, "[img]$1[/img]");
rep(/<span class=\"codeStyle\">(.*?)<\/span>/gi, "[code]$1[/code]");
rep(/<span class=\"quoteStyle\">(.*?)<\/span>/gi, "[quote]$1[/quote]");
rep(/<strong class=\"codeStyle\">(.*?)<\/strong>/gi, "[code][b]$1[/b][/code]");
rep(/<strong class=\"quoteStyle\">(.*?)<\/strong>/gi, "[quote][b]$1[/b][/quote]");
rep(/<em class=\"codeStyle\">(.*?)<\/em>/gi, "[code][i]$1[/i][/code]");
rep(/<em class=\"quoteStyle\">(.*?)<\/em>/gi, "[quote][i]$1[/i][/quote]");
rep(/<u class=\"codeStyle\">(.*?)<\/u>/gi, "[code][u]$1[/u][/code]");
rep(/<u class=\"quoteStyle\">(.*?)<\/u>/gi, "[quote][u]$1[/u][/quote]");
rep(/<\/(strong|b)>/gi, "[/b]");
rep(/<(strong|b)>/gi, "[b]");
rep(/<\/(em|i)>/gi, "[/i]");
rep(/<(em|i)>/gi, "[i]");
rep(/<\/u>/gi, "[/u]");
rep(/<span style=\"text-decoration: ?underline;\">(.*?)<\/span>/gi, "[u]$1[/u]");
rep(/<u>/gi, "[u]");
rep(/<blockquote[^>]*>/gi, "[quote]");
rep(/<\/blockquote>/gi, "[/quote]");
rep(/<br \/>/gi, "\n");
rep(/<br\/>/gi, "\n");
rep(/<br>/gi, "\n");
rep(/<p>/gi, "");
rep(/<\/p>/gi, "\n");
rep(/&nbsp;|\u00a0/gi, " ");
rep(/&quot;/gi, "\"");
rep(/&lt;/gi, "<");
rep(/&gt;/gi, ">");
rep(/&amp;/gi, "&");
return s;
},
// BBCode -> HTML from PunBB dialect
_punbb_bbcode2html : function(s) {
_punbb_bbcode2html: function(s) {
s = tinymce.trim(s);
function rep(re, str) {
......@@ -100,19 +100,19 @@
}
// example: [b] to <strong>
rep(/\n/gi,"<br />");
rep(/\[b\]/gi,"<strong>");
rep(/\[\/b\]/gi,"</strong>");
rep(/\[i\]/gi,"<em>");
rep(/\[\/i\]/gi,"</em>");
rep(/\[u\]/gi,"<u>");
rep(/\[\/u\]/gi,"</u>");
rep(/\[url=([^\]]+)\](.*?)\[\/url\]/gi,"<a href=\"$1\">$2</a>");
rep(/\[url\](.*?)\[\/url\]/gi,"<a href=\"$1\">$1</a>");
rep(/\[img\](.*?)\[\/img\]/gi,"<img src=\"$1\" />");
rep(/\[color=(.*?)\](.*?)\[\/color\]/gi,"<font color=\"$1\">$2</font>");
rep(/\[code\](.*?)\[\/code\]/gi,"<span class=\"codeStyle\">$1</span>&nbsp;");