mirror of
https://github.com/documize/community.git
synced 2025-07-21 14:19:43 +02:00
1 line
No EOL
2.2 KiB
JavaScript
1 line
No EOL
2.2 KiB
JavaScript
!function(){"use strict";var e=tinymce.util.Tools.resolve("tinymce.PluginManager"),t=tinymce.util.Tools.resolve("tinymce.Env"),n=function(e){return e.getParam("autolink_pattern",/^(https?:\/\/|ssh:\/\/|ftp:\/\/|file:\/|www\.|(?:mailto:)?[A-Z0-9._%+\-]+@)(.+)$/i)},i=function(e){return e.getParam("default_link_target","")},o=function(e,t){if(t<0&&(t=0),3===e.nodeType){var n=e.data.length;t>n&&(t=n)}return t},r=function(e,t,n){1!==t.nodeType||t.hasChildNodes()?e.setStart(t,o(t,n)):e.setStartBefore(t)},f=function(e,t,n){1!==t.nodeType||t.hasChildNodes()?e.setEnd(t,o(t,n)):e.setEndAfter(t)},a=function(e,t,o){var a,d,s,l,c,u,g,h,C,m,y=n(e),k=i(e);if("A"!==e.selection.getNode().tagName){if((a=e.selection.getRng(!0).cloneRange()).startOffset<5){if(!(h=a.endContainer.previousSibling)){if(!a.endContainer.firstChild||!a.endContainer.firstChild.nextSibling)return;h=a.endContainer.firstChild.nextSibling}if(C=h.length,r(a,h,C),f(a,h,C),a.endOffset<5)return;d=a.endOffset,l=h}else{if(3!==(l=a.endContainer).nodeType&&l.firstChild){for(;3!==l.nodeType&&l.firstChild;)l=l.firstChild;3===l.nodeType&&(r(a,l,0),f(a,l,l.nodeValue.length))}d=1===a.endOffset?2:a.endOffset-1-t}s=d;do{r(a,l,d>=2?d-2:0),f(a,l,d>=1?d-1:0),d-=1,m=a.toString()}while(" "!==m&&""!==m&&160!==m.charCodeAt(0)&&d-2>=0&&m!==o);!function(e,t){return e===t||" "===e||160===e.charCodeAt(0)}(a.toString(),o)?0===a.startOffset?(r(a,l,0),f(a,l,s)):(r(a,l,d),f(a,l,s)):(r(a,l,d),f(a,l,s),d+=1),"."===(u=a.toString()).charAt(u.length-1)&&f(a,l,s-1),(g=(u=a.toString().trim()).match(y))&&("www."===g[1]?g[1]="http://www.":/@$/.test(g[1])&&!/^mailto:/.test(g[1])&&(g[1]="mailto:"+g[1]),c=e.selection.getBookmark(),e.selection.setRng(a),e.execCommand("createlink",!1,g[1]+g[2]),k&&e.dom.setAttrib(e.selection.getNode(),"target",k),e.selection.moveToBookmark(c),e.nodeChanged())}},d=function(e){var n;e.on("keydown",function(t){if(13===t.keyCode)return function(e){a(e,-1,"")}(e)}),t.ie?e.on("focus",function(){if(!n){n=!0;try{e.execCommand("AutoUrlDetect",!1,!0)}catch(t){}}}):(e.on("keypress",function(t){if(41===t.keyCode)return function(e){a(e,-1,"(")}(e)}),e.on("keyup",function(t){if(32===t.keyCode)return function(e){a(e,0,"")}(e)}))};e.add("autolink",function(e){d(e)})}(); |