| | |
| | | init : function(ed, url) { |
| | | var t = this; |
| | | |
| | | // Internet Explorer has built-in automatic linking |
| | | if (tinyMCE.isIE) |
| | | return; |
| | | |
| | | // Add a key down handler |
| | | ed.onKeyDown.add(function(ed, e) { |
| | | 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) |
| | |
| | | |
| | | // 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().cloneRange(); |
| | | 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. |
| | |
| | | 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\.)(.+)$/i); |
| | | 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) { |