只读模式
group, 分享
评论更多问题
博客标签总是存在一个
This commit is contained in:
lealife committed 2015-06-15 18:01:48 +08:00
1 parent 7e458bb433
commit 6987a38820
1453 files changed
+114558 -91533

No files matched your search

+64 -30
View File
@@ -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,23 @@ tinymce.PluginManager.add('autolink', function(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.which == 41) {
if (e.keyCode == 41) {
return handleEclipse(editor);
}
});
@@ -47,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.
@@ -65,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;
@@ -85,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);
}
}
@@ -101,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();
@@ -143,18 +188,7 @@ tinymce.PluginManager.add('autolink', function(editor) {
editor.selection.setRng(rng);
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);
}
}
}
});