jonnybarnes.uk/public/build/assets/bower/Autolinker.min-2cb3468034.js

10 lines
23 KiB
JavaScript
Raw Normal View History

/*!
* Autolinker.js
* 0.24.1
*
* Copyright(c) 2016 Gregory Jacobs <greg@greg-jacobs.com>
* MIT License
*
* https://github.com/gregjacobs/Autolinker.js
*/
!function(t,e){"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?module.exports=e():t.Autolinker=e()}(this,function(){var t=function(t){t=t||{},this.urls=this.normalizeUrlsCfg(t.urls),this.email="boolean"==typeof t.email?t.email:!0,this.twitter="boolean"==typeof t.twitter?t.twitter:!0,this.phone="boolean"==typeof t.phone?t.phone:!0,this.hashtag=t.hashtag||!1,this.newWindow="boolean"==typeof t.newWindow?t.newWindow:!0,this.stripPrefix="boolean"==typeof t.stripPrefix?t.stripPrefix:!0;var e=this.hashtag;if(e!==!1&&"twitter"!==e&&"facebook"!==e&&"instagram"!==e)throw new Error("invalid `hashtag` cfg - see docs");this.truncate=this.normalizeTruncateCfg(t.truncate),this.className=t.className||"",this.replaceFn=t.replaceFn||null,this.htmlParser=null,this.matchers=null,this.tagBuilder=null};return t.prototype={constructor:t,normalizeUrlsCfg:function(t){return null==t&&(t=!0),"boolean"==typeof t?{schemeMatches:t,wwwMatches:t,tldMatches:t}:{schemeMatches:"boolean"==typeof t.schemeMatches?t.schemeMatches:!0,wwwMatches:"boolean"==typeof t.wwwMatches?t.wwwMatches:!0,tldMatches:"boolean"==typeof t.tldMatches?t.tldMatches:!0}},normalizeTruncateCfg:function(e){return"number"==typeof e?{length:e,location:"end"}:t.Util.defaults(e||{},{length:Number.POSITIVE_INFINITY,location:"end"})},parse:function(t){for(var e=this.getHtmlParser(),r=e.parse(t),n=0,s=[],i=0,a=r.length;a>i;i++){var o=r[i],h=o.getType();if("element"===h&&"a"===o.getTagName())o.isClosing()?n=Math.max(n-1,0):n++;else if("text"===h&&0===n){var c=this.parseText(o.getText(),o.getOffset());s.push.apply(s,c)}}return s=this.compactMatches(s),this.hashtag||(s=s.filter(function(t){return"hashtag"!==t.getType()})),this.email||(s=s.filter(function(t){return"email"!==t.getType()})),this.phone||(s=s.filter(function(t){return"phone"!==t.getType()})),this.twitter||(s=s.filter(function(t){return"twitter"!==t.getType()})),this.urls.schemeMatches||(s=s.filter(function(t){return"url"!==t.getType()||"scheme"!==t.getUrlMatchType()})),this.urls.wwwMatches||(s=s.filter(function(t){return"url"!==t.getType()||"www"!==t.getUrlMatchType()})),this.urls.tldMatches||(s=s.filter(function(t){return"url"!==t.getType()||"tld"!==t.getUrlMatchType()})),s},compactMatches:function(t){t.sort(function(t,e){return t.getOffset()-e.getOffset()});for(var e=0;e<t.length-1;e++)for(var r=t[e],n=r.getOffset()+r.getMatchedText().length;e+1<t.length&&t[e+1].getOffset()<=n;)t.splice(e+1,1);return t},parseText:function(t,e){e=e||0;for(var r=this.getMatchers(),n=[],s=0,i=r.length;i>s;s++){for(var a=r[s].parseMatches(t),o=0,h=a.length;h>o;o++)a[o].setOffset(e+a[o].getOffset());n.push.apply(n,a)}return n},link:function(t){if(!t)return"";for(var e=this.parse(t),r=[],n=0,s=0,i=e.length;i>s;s++){var a=e[s];r.push(t.substring(n,a.getOffset())),r.push(this.createMatchReturnVal(a)),n=a.getOffset()+a.getMatchedText().length}return r.push(t.substring(n)),r.join("")},createMatchReturnVal:function(e){var r;if(this.replaceFn&&(r=this.replaceFn.call(this,this,e)),"string"==typeof r)return r;if(r===!1)return e.getMatchedText();if(r instanceof t.HtmlTag)return r.toAnchorString();var n=this.getTagBuilder(),s=n.build(e);return s.toAnchorString()},getHtmlParser:function(){var e=this.htmlParser;return e||(e=this.htmlParser=new t.htmlParser.HtmlParser),e},getMatchers:function(){if(this.matchers)return this.matchers;var e=t.matcher,r=[new e.Hashtag({serviceName:this.hashtag}),new e.Email,new e.Phone,new e.Twitter,new e.Url({stripPrefix:this.stripPrefix})];return this.matchers=r},getTagBuilder:function(){var e=this.tagBuilder;return e||(e=this.tagBuilder=new t.AnchorTagBuilder({newWindow:this.newWindow,truncate:this.truncate,className:this.className})),e}},t.link=function(e,r){var n=new t(r);return n.link(e)},t.match={},t.matcher={},t.htmlParser={},t.truncate={},t.Util={abstractMethod:function(){throw"abstract"},trimRegex:/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,assign:function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);return t},defaults:function(t,e){for(var r in e)e.hasOwnProperty(r)&&void 0===t[r]&&(t[r]=e[r]);re