Merge branch 'hotfix/21.56.9' into master
[gitter.git] / public / repo / autolink / autolink.js
blobe9e87d5634098be7716ffc8f89a6dd1967c8951f
1 !(function(e) {
2 function t(e) {
3 for (
4 var t,
5 n = document.createNodeIterator(
6 e,
7 NodeFilter.SHOW_TEXT | NodeFilter.SHOW_ELEMENT,
8 function(e) {
9 return 1 !== e.nodeType
10 ? NodeFilter.FILTER_ACCEPT
11 : 'A' === e.tagName
12 ? NodeFilter.FILTER_REJECT
13 : NodeFilter.FILTER_SKIP;
17 null !== (t = n.nextNode());
19 ) {
20 var r = /\b((?:https?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>“”‘’'"]+|\(([^\s()<>“”‘’'"]+|(\([^\s()<>“”‘’'"]+\)))*\))+(?:\(([^\s()<>“”‘’'"]+|(\([^\s()<>“”‘’'"]+\)))*\)|[^\s`!()\[\]{};:.,<>?«»“”‘’'"]))/i,
21 o = r.exec(t.data);
22 if (o) {
23 var i = o[0],
24 a = document.createElement('a');
25 a.setAttribute('target', '_blank'),
26 a.setAttribute('rel', 'nofollow'),
27 (a.textContent = i),
28 i.match(/^https?:\/\//)
29 ? a.setAttribute('href', i)
30 : a.setAttribute('href', 'http://' + i);
31 var d = t.splitText(o.index);
32 (d.nodeValue = d.nodeValue.substr(i.length)), t.parentNode.insertBefore(a, d), n.nextNode();
36 return (
37 (e.autolink = t),
38 'function' == typeof define &&
39 define.amd &&
40 define([], function() {
41 return t;
42 }),
45 })(window);