%PDF- <> %âãÏÓ endobj 2 0 obj <> endobj 3 0 obj <>/ExtGState<>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI] >>/Annots[ 28 0 R 29 0 R] /MediaBox[ 0 0 595.5 842.25] /Contents 4 0 R/Group<>/Tabs/S>> endobj ºaâÚÎΞ-ÌE1ÍØÄ÷{òò2ÿ ÛÖ^ÔÀá TÎ{¦?§®¥kuµùÕ5sLOšuY>endobj 2 0 obj<>endobj 2 0 obj<>endobj 2 0 obj<>endobj 2 0 obj<> endobj 2 0 obj<>endobj 2 0 obj<>es 3 0 R>> endobj 2 0 obj<> ox[ 0.000000 0.000000 609.600000 935.600000]/Fi endobj 3 0 obj<> endobj 7 1 obj<>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI]>>/Subtype/Form>> stream
import $ from 'jquery';
import lists from '../core/lists';
import key from '../core/key';
const defaultScheme = 'http://';
const linkPattern = /^([A-Za-z][A-Za-z0-9+-.]*\:[\/]{2}|tel:|mailto:[A-Z0-9._%+-]+@)?(www\.)?(.+)$/i;
export default class AutoLink {
constructor(context) {
this.context = context;
this.events = {
'summernote.keyup': (we, e) => {
if (!e.isDefaultPrevented()) {
this.handleKeyup(e);
}
},
'summernote.keydown': (we, e) => {
this.handleKeydown(e);
},
};
}
initialize() {
this.lastWordRange = null;
}
destroy() {
this.lastWordRange = null;
}
replace() {
if (!this.lastWordRange) {
return;
}
const keyword = this.lastWordRange.toString();
const match = keyword.match(linkPattern);
if (match && (match[1] || match[2])) {
const link = match[1] ? keyword : defaultScheme + keyword;
const urlText = keyword.replace(/^(?:https?:\/\/)?(?:tel?:?)?(?:mailto?:?)?(?:www\.)?/i, '').split('/')[0];
const node = $('<a />').html(urlText).attr('href', link)[0];
if (this.context.options.linkTargetBlank) {
$(node).attr('target', '_blank');
}
this.lastWordRange.insertNode(node);
this.lastWordRange = null;
this.context.invoke('editor.focus');
}
}
handleKeydown(e) {
if (lists.contains([key.code.ENTER, key.code.SPACE], e.keyCode)) {
const wordRange = this.context.invoke('editor.createRange').getWordRange();
this.lastWordRange = wordRange;
}
}
handleKeyup(e) {
if (lists.contains([key.code.ENTER, key.code.SPACE], e.keyCode)) {
this.replace();
}
}
}