linkify-jquery.min.js 3.2 KB

1
  1. "use strict";!function(e,n,t){var i=function(n){function t(e,n,t){var i=t[t.length-1];e.replaceChild(i,n);for(var a=t.length-2;a>=0;a--)e.insertBefore(t[a],i),i=t[a]}function i(e,n,t){for(var i=[],a=e,r=Array.isArray(a),o=0,a=r?a:a[Symbol.iterator]();;){var l;if(r){if(o>=a.length)break;l=a[o++]}else{if(o=a.next(),o.done)break;l=o.value}var f=l;if("nl"===f.type&&n.nl2br)i.push(t.createElement("br"));else if(f.isLink&&n.check(f)){var s=n.resolve(f),c=s.formatted,u=s.formattedHref,y=s.tagName,d=s.className,m=s.target,k=s.events,h=s.attributes,v=t.createElement(y);if(v.setAttribute("href",u),d&&v.setAttribute("class",d),m&&v.setAttribute("target",m),h)for(var g in h)v.setAttribute(g,h[g]);if(k)for(var b in k)v.addEventListener?v.addEventListener(b,k[b]):v.attachEvent&&v.attachEvent("on"+b,k[b]);v.appendChild(t.createTextNode(c)),i.push(v)}else i.push(t.createTextNode(f.toString()))}return i}function a(e,n,r){if(!e||e.nodeType!==u)throw new Error("Cannot linkify "+e+" - Invalid DOM Node type");var o=n.ignoreTags;if("A"===e.tagName||f.contains(o,e.tagName))return e;for(var s=e.firstChild;s;){var d=void 0,m=void 0,k=void 0;switch(s.nodeType){case u:a(s,n,r);break;case y:if(d=s.nodeValue,m=l(d),0===m.length||1===m.length&&m[0]instanceof c)break;k=i(m,n,r),t(e,s,k),s=k[k.length-1]}s=s.nextSibling}return e}function r(n,t){var i=arguments.length>2&&void 0!==arguments[2]&&arguments[2];try{i=i||document||e&&e.document||global&&global.document}catch(r){}if(!i)throw new Error("Cannot find document implementation. If you are in a non-browser environment like Node.js, pass the document implementation as the third argument to linkifyElement.");return t=new s(t),a(n,t,i)}function o(n){function t(e){return e=r.normalize(e),this.each(function(){r.helper(this,e,i)})}var i=arguments.length>1&&void 0!==arguments[1]&&arguments[1];n.fn=n.fn||{};try{i=i||document||e&&e.document||global&&global.document}catch(a){}if(!i)throw new Error("Cannot find document implementation. If you are in a non-browser environment like Node.js, pass the document implementation as the second argument to linkify/jquery");"function"!=typeof n.fn.linkify&&(n.fn.linkify=t,n(i).ready(function(){n("[data-linkify]").each(function(){var e=n(this),t=e.data(),i=t.linkify,a=t.linkifyNlbr,o={nl2br:!!a&&0!==a&&"false"!==a};"linkifyAttributes"in t&&(o.attributes=t.linkifyAttributes),"linkifyDefaultProtocol"in t&&(o.defaultProtocol=t.linkifyDefaultProtocol),"linkifyEvents"in t&&(o.events=t.linkifyEvents),"linkifyFormat"in t&&(o.format=t.linkifyFormat),"linkifyFormatHref"in t&&(o.formatHref=t.linkifyFormatHref),"linkifyTagname"in t&&(o.tagName=t.linkifyTagname),"linkifyTarget"in t&&(o.target=t.linkifyTarget),"linkifyValidate"in t&&(o.validate=t.linkifyValidate),"linkifyIgnoreTags"in t&&(o.ignoreTags=t.linkifyIgnoreTags),"linkifyClassName"in t?o.className=t.linkifyClassName:"linkifyLinkclass"in t&&(o.className=t.linkifyLinkclass),o=r.normalize(o);var l="this"===i?e:e.find(i);l.linkify(o)})}))}var l=n.tokenize,f=n.options,s=f.Options,c=n.parser.TOKENS.TEXT,u=1,y=3;r.helper=a,r.normalize=function(e){return new s(e)};try{!(void 0).define&&(e.linkifyElement=r)}catch(d){}return o}(n);"function"!=typeof t.fn.linkify&&i(t)}(window,linkify,jQuery);