UNPKG

ckeditor4

Version:

JavaScript WYSIWYG web text editor.

8 lines 2.04 kB
/* Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved. For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license */ (function(){CKEDITOR.plugins.add("autolink",{requires:"clipboard,textmatch,link",isSupportedEnvironment:function(){return!CKEDITOR.env.ie||CKEDITOR.env.edge},init:function(d){function e(a){a=CKEDITOR.tools.htmlDecodeAttr(a);var b=new CKEDITOR.dom.element("a"),c=a.replace(/"/g,"%22"),c=c.match(CKEDITOR.config.autolink_urlRegex)?c:"mailto:"+c;b.setText(a);b.setAttribute("href",c);a=CKEDITOR.plugins.link.parseLinkAttributes(d,b);a=CKEDITOR.plugins.link.getLinkAttributes(d,a);CKEDITOR.tools.isEmpty(a.set)|| b.setAttributes(a.set);a.removed.length&&b.removeAttributes(a.removed);b.removeAttribute("data-cke-saved-href");return b.getOuterHtml()}function g(a,b){var c=a.slice(0,b).split(/\s+/);return(c=c[c.length-1])&&f(c)?{start:a.lastIndexOf(c),end:b}:null}function f(a){return a.match(d.config.autolink_urlRegex)||a.match(d.config.autolink_emailRegex)}this.isSupportedEnvironment()&&(d.on("paste",function(a){if(a.data.dataTransfer.getTransferType(d)!=CKEDITOR.DATA_TRANSFER_INTERNAL){var b=a.data.dataValue; -1<b.indexOf("\x3c")||!f(b)||(a.data.dataValue=e(b),a.data.type="html")}}),d.on("key",function(a){if("wysiwyg"===d.mode&&-1!=CKEDITOR.tools.indexOf(d.config.autolink_commitKeystrokes,a.data.keyCode)){var b=CKEDITOR.plugins.textMatch.match(d.getSelection().getRanges()[0],g);if(b&&(a=d.getSelection(),!a.getRanges()[0].startContainer.getAscendant("a",!0)&&(a.selectRanges([b.range]),d.insertHtml(e(b.text),"text"),!CKEDITOR.env.webkit))){var b=a.getRanges()[0],c=d.createRange();c.setStartAfter(b.startContainer); a.selectRanges([c])}}}))}});CKEDITOR.config.autolink_commitKeystrokes=[13,32];CKEDITOR.config.autolink_urlRegex=/^(https?|ftp):\/\/(-\.)?([^\s\/?\.#]\.?)+(\/[^\s]*)?[^\s\.,]$/i;CKEDITOR.config.autolink_emailRegex=/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/})();