Upgrade to TinyMCE 4.5.1
- New flat theme (with padding tightened a bit from the default to fit in right-hand pane) - Adds search/replace within notes - Adds URL autolinking - Image pasting/dragging is now properly disallowed (though TinyMCE 4 has hooks that may allow us to actually support this by automatically creating attachments) - New blockquote style with color bar - Replaces custom context menu on link click with built-in version To-do: - Fix display of pop-ups, which are now modal dialogs within the note frame instead of pop-up windows, to stay fully within the frame - Localize (more important now that there are tooltips) - Support image dragging - Update elements list for HTML5, for better drag-and-drop? - Move directionality control to context menu instead of taking up toolbar space? - Evaluate other plugins for potential inclusion - Show additional controls in separate note window? - Fix opacity of text in tooltips Closes #451, closes #421
This commit is contained in:
parent
ab959cd858
commit
dc04a1231c
67 changed files with 54823 additions and 25007 deletions
|
@ -1,184 +0,0 @@
|
|||
/**
|
||||
* editor_plugin_src.js
|
||||
*
|
||||
* Copyright 2011, Moxiecode Systems AB
|
||||
* Released under LGPL License.
|
||||
*
|
||||
* License: http://tinymce.moxiecode.com/license
|
||||
* Contributing: http://tinymce.moxiecode.com/contributing
|
||||
*/
|
||||
|
||||
(function() {
|
||||
tinymce.create('tinymce.plugins.AutolinkPlugin', {
|
||||
/**
|
||||
* Initializes the plugin, this will be executed after the plugin has been created.
|
||||
* This call is done before the editor instance has finished it's initialization so use the onInit event
|
||||
* of the editor instance to intercept that event.
|
||||
*
|
||||
* @param {tinymce.Editor} ed Editor instance that the plugin is initialized in.
|
||||
* @param {string} url Absolute URL to where the plugin is located.
|
||||
*/
|
||||
|
||||
init : function(ed, url) {
|
||||
var t = this;
|
||||
|
||||
// Add a key down handler
|
||||
ed.onKeyDown.addToTop(function(ed, e) {
|
||||
if (e.keyCode == 13)
|
||||
return t.handleEnter(ed);
|
||||
});
|
||||
|
||||
// Internet Explorer has built-in automatic linking for most cases
|
||||
if (tinyMCE.isIE)
|
||||
return;
|
||||
|
||||
ed.onKeyPress.add(function(ed, e) {
|
||||
if (e.which == 41)
|
||||
return t.handleEclipse(ed);
|
||||
});
|
||||
|
||||
// Add a key up handler
|
||||
ed.onKeyUp.add(function(ed, e) {
|
||||
if (e.keyCode == 32)
|
||||
return t.handleSpacebar(ed);
|
||||
});
|
||||
},
|
||||
|
||||
handleEclipse : function(ed) {
|
||||
this.parseCurrentLine(ed, -1, '(', true);
|
||||
},
|
||||
|
||||
handleSpacebar : function(ed) {
|
||||
this.parseCurrentLine(ed, 0, '', true);
|
||||
},
|
||||
|
||||
handleEnter : function(ed) {
|
||||
this.parseCurrentLine(ed, -1, '', false);
|
||||
},
|
||||
|
||||
parseCurrentLine : function(ed, end_offset, delimiter, goback) {
|
||||
var r, end, start, endContainer, bookmark, text, matches, prev, len;
|
||||
|
||||
// We need at least five characters to form a URL,
|
||||
// hence, at minimum, five characters from the beginning of the line.
|
||||
r = ed.selection.getRng(true).cloneRange();
|
||||
if (r.startOffset < 5) {
|
||||
// During testing, the caret is placed inbetween two text nodes.
|
||||
// The previous text node contains the URL.
|
||||
prev = r.endContainer.previousSibling;
|
||||
if (prev == null) {
|
||||
if (r.endContainer.firstChild == null || r.endContainer.firstChild.nextSibling == null)
|
||||
return;
|
||||
|
||||
prev = r.endContainer.firstChild.nextSibling;
|
||||
}
|
||||
len = prev.length;
|
||||
r.setStart(prev, len);
|
||||
r.setEnd(prev, len);
|
||||
|
||||
if (r.endOffset < 5)
|
||||
return;
|
||||
|
||||
end = r.endOffset;
|
||||
endContainer = prev;
|
||||
} else {
|
||||
endContainer = r.endContainer;
|
||||
|
||||
// Get a text node
|
||||
if (endContainer.nodeType != 3 && endContainer.firstChild) {
|
||||
while (endContainer.nodeType != 3 && endContainer.firstChild)
|
||||
endContainer = endContainer.firstChild;
|
||||
|
||||
// Move range to text node
|
||||
if (endContainer.nodeType == 3) {
|
||||
r.setStart(endContainer, 0);
|
||||
r.setEnd(endContainer, endContainer.nodeValue.length);
|
||||
}
|
||||
}
|
||||
|
||||
if (r.endOffset == 1)
|
||||
end = 2;
|
||||
else
|
||||
end = r.endOffset - 1 - end_offset;
|
||||
}
|
||||
|
||||
start = end;
|
||||
|
||||
do
|
||||
{
|
||||
// Move the selection one character backwards.
|
||||
r.setStart(endContainer, end - 2);
|
||||
r.setEnd(endContainer, end - 1);
|
||||
end -= 1;
|
||||
|
||||
// Loop until one of the following is found: a blank space, , delimeter, (end-2) >= 0
|
||||
} while (r.toString() != ' ' && r.toString() != '' && r.toString().charCodeAt(0) != 160 && (end -2) >= 0 && r.toString() != delimiter);
|
||||
|
||||
if (r.toString() == delimiter || r.toString().charCodeAt(0) == 160) {
|
||||
r.setStart(endContainer, end);
|
||||
r.setEnd(endContainer, start);
|
||||
end += 1;
|
||||
} else if (r.startOffset == 0) {
|
||||
r.setStart(endContainer, 0);
|
||||
r.setEnd(endContainer, start);
|
||||
}
|
||||
else {
|
||||
r.setStart(endContainer, end);
|
||||
r.setEnd(endContainer, start);
|
||||
}
|
||||
|
||||
// Exclude last . from word like "www.site.com."
|
||||
var text = r.toString();
|
||||
if (text.charAt(text.length - 1) == '.') {
|
||||
r.setEnd(endContainer, start - 1);
|
||||
}
|
||||
|
||||
text = r.toString();
|
||||
matches = text.match(/^(https?:\/\/|ssh:\/\/|ftp:\/\/|file:\/|www\.|(?:mailto:)?[A-Z0-9._%+-]+@)(.+)$/i);
|
||||
|
||||
if (matches) {
|
||||
if (matches[1] == 'www.') {
|
||||
matches[1] = 'http://www.';
|
||||
} else if (/@$/.test(matches[1]) && !/^mailto:/.test(matches[1])) {
|
||||
matches[1] = 'mailto:' + matches[1];
|
||||
}
|
||||
|
||||
bookmark = ed.selection.getBookmark();
|
||||
|
||||
ed.selection.setRng(r);
|
||||
tinyMCE.execCommand('createlink',false, matches[1] + matches[2]);
|
||||
ed.selection.moveToBookmark(bookmark);
|
||||
ed.nodeChanged();
|
||||
|
||||
// TODO: Determine if this is still needed.
|
||||
if (tinyMCE.isWebKit) {
|
||||
// move the caret to its original position
|
||||
ed.selection.collapse(false);
|
||||
var max = Math.min(endContainer.length, start + 1);
|
||||
r.setStart(endContainer, max);
|
||||
r.setEnd(endContainer, max);
|
||||
ed.selection.setRng(r);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns information about the plugin as a name/value array.
|
||||
* The current keys are longname, author, authorurl, infourl and version.
|
||||
*
|
||||
* @return {Object} Name/value array containing information about the plugin.
|
||||
*/
|
||||
getInfo : function() {
|
||||
return {
|
||||
longname : 'Autolink',
|
||||
author : 'Moxiecode Systems AB',
|
||||
authorurl : 'http://tinymce.moxiecode.com',
|
||||
infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/autolink',
|
||||
version : tinymce.majorVersion + "." + tinymce.minorVersion
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
// Register plugin
|
||||
tinymce.PluginManager.add('autolink', tinymce.plugins.AutolinkPlugin);
|
||||
})();
|
209
resource/tinymce/plugins/autolink/plugin.js
Normal file
209
resource/tinymce/plugins/autolink/plugin.js
Normal file
|
@ -0,0 +1,209 @@
|
|||
/**
|
||||
* plugin.js
|
||||
*
|
||||
* Released under LGPL License.
|
||||
* Copyright (c) 1999-2015 Ephox Corp. All rights reserved
|
||||
*
|
||||
* License: http://www.tinymce.com/license
|
||||
* Contributing: http://www.tinymce.com/contributing
|
||||
*/
|
||||
|
||||
/*global tinymce:true */
|
||||
|
||||
tinymce.PluginManager.add('autolink', function(editor) {
|
||||
var AutoUrlDetectState;
|
||||
var AutoLinkPattern = /^(https?:\/\/|ssh:\/\/|ftp:\/\/|file:\/|www\.|(?:mailto:)?[A-Z0-9._%+\-]+@)(.+)$/i;
|
||||
|
||||
if (editor.settings.autolink_pattern) {
|
||||
AutoLinkPattern = editor.settings.autolink_pattern;
|
||||
}
|
||||
|
||||
editor.on("keydown", function(e) {
|
||||
if (e.keyCode == 13) {
|
||||
return handleEnter(editor);
|
||||
}
|
||||
});
|
||||
|
||||
// Internet Explorer has built-in automatic linking for most cases
|
||||
if (tinymce.Env.ie) {
|
||||
editor.on("focus", function() {
|
||||
if (!AutoUrlDetectState) {
|
||||
AutoUrlDetectState = true;
|
||||
|
||||
try {
|
||||
editor.execCommand('AutoUrlDetect', false, true);
|
||||
} catch (ex) {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
editor.on("keypress", function(e) {
|
||||
if (e.keyCode == 41) {
|
||||
return handleEclipse(editor);
|
||||
}
|
||||
});
|
||||
|
||||
editor.on("keyup", function(e) {
|
||||
if (e.keyCode == 32) {
|
||||
return handleSpacebar(editor);
|
||||
}
|
||||
});
|
||||
|
||||
function handleEclipse(editor) {
|
||||
parseCurrentLine(editor, -1, '(', true);
|
||||
}
|
||||
|
||||
function handleSpacebar(editor) {
|
||||
parseCurrentLine(editor, 0, '', true);
|
||||
}
|
||||
|
||||
function handleEnter(editor) {
|
||||
parseCurrentLine(editor, -1, '', false);
|
||||
}
|
||||
|
||||
function parseCurrentLine(editor, end_offset, delimiter) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
// Never create a link when we are inside a link
|
||||
if (editor.selection.getNode().tagName == 'A') {
|
||||
return;
|
||||
}
|
||||
|
||||
// We need at least five characters to form a URL,
|
||||
// hence, at minimum, five characters from the beginning of the line.
|
||||
rng = editor.selection.getRng(true).cloneRange();
|
||||
if (rng.startOffset < 5) {
|
||||
// During testing, the caret is placed between two text nodes.
|
||||
// The previous text node contains the URL.
|
||||
prev = rng.endContainer.previousSibling;
|
||||
if (!prev) {
|
||||
if (!rng.endContainer.firstChild || !rng.endContainer.firstChild.nextSibling) {
|
||||
return;
|
||||
}
|
||||
|
||||
prev = rng.endContainer.firstChild.nextSibling;
|
||||
}
|
||||
|
||||
len = prev.length;
|
||||
setStart(prev, len);
|
||||
setEnd(prev, len);
|
||||
|
||||
if (rng.endOffset < 5) {
|
||||
return;
|
||||
}
|
||||
|
||||
end = rng.endOffset;
|
||||
endContainer = prev;
|
||||
} else {
|
||||
endContainer = rng.endContainer;
|
||||
|
||||
// Get a text node
|
||||
if (endContainer.nodeType != 3 && endContainer.firstChild) {
|
||||
while (endContainer.nodeType != 3 && endContainer.firstChild) {
|
||||
endContainer = endContainer.firstChild;
|
||||
}
|
||||
|
||||
// Move range to text node
|
||||
if (endContainer.nodeType == 3) {
|
||||
setStart(endContainer, 0);
|
||||
setEnd(endContainer, endContainer.nodeValue.length);
|
||||
}
|
||||
}
|
||||
|
||||
if (rng.endOffset == 1) {
|
||||
end = 2;
|
||||
} else {
|
||||
end = rng.endOffset - 1 - end_offset;
|
||||
}
|
||||
}
|
||||
|
||||
start = end;
|
||||
|
||||
do {
|
||||
// Move the selection one character backwards.
|
||||
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, , delimiter, (end-2) >= 0
|
||||
} while (rngText != ' ' && rngText !== '' && rngText.charCodeAt(0) != 160 && (end - 2) >= 0 && rngText != delimiter);
|
||||
|
||||
if (rng.toString() == delimiter || rng.toString().charCodeAt(0) == 160) {
|
||||
setStart(endContainer, end);
|
||||
setEnd(endContainer, start);
|
||||
end += 1;
|
||||
} else if (rng.startOffset === 0) {
|
||||
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) == '.') {
|
||||
setEnd(endContainer, start - 1);
|
||||
}
|
||||
|
||||
text = rng.toString();
|
||||
matches = text.match(AutoLinkPattern);
|
||||
|
||||
if (matches) {
|
||||
if (matches[1] == 'www.') {
|
||||
matches[1] = 'http://www.';
|
||||
} else if (/@$/.test(matches[1]) && !/^mailto:/.test(matches[1])) {
|
||||
matches[1] = 'mailto:' + matches[1];
|
||||
}
|
||||
|
||||
bookmark = editor.selection.getBookmark();
|
||||
|
||||
editor.selection.setRng(rng);
|
||||
editor.execCommand('createlink', false, matches[1] + matches[2]);
|
||||
|
||||
if (editor.settings.default_link_target) {
|
||||
editor.dom.setAttrib(editor.selection.getNode(), 'target', editor.settings.default_link_target);
|
||||
}
|
||||
|
||||
editor.selection.moveToBookmark(bookmark);
|
||||
editor.nodeChanged();
|
||||
}
|
||||
}
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue