123456789 |
- /**
- * jquery.linky.js v0.1.8
- * https://github.com/AnSavvides/jquery.linky
- * The MIT License (MIT)
- *
- * Copyright (c) 2013 - 2015 Andreas Savvides
- */
- (function($){"use strict";$.fn.linky=function(options){return this.each(function(){var $el=$(this),linkifiedContent=_linkify($el,options);$el.html(linkifiedContent)})};function _linkify($el,options){var links={twitter:{baseUrl:"https://twitter.com/",hashtagSearchUrl:"hashtag/"},instagram:{baseUrl:"http://instagram.com/",hashtagSearchUrl:null},github:{baseUrl:"https://github.com/",hashtagSearchUrl:null}},defaultOptions={mentions:false,hashtags:false,urls:true,linkTo:"twitter"},extendedOptions=$.extend(defaultOptions,options),elContent=$el.html(),urlRegEx=/((([A-Za-z]{3,9}:(?:\/\/)?)(?:[\-;:&=\+\$,\w]+@)?[A-Za-z0-9\.\-]+|(?:www\.|[\-;:&=\+\$,\w]+@)[A-Za-z0-9\.\-]+)((?:\/[\+~%\/\.\w\-]*)?\??(?:[\-\+=&;%@\.\w]*)#?(?:[\.\!\/\\\w]*))?)/g,matches;if(extendedOptions.urls){matches=elContent.match(urlRegEx);if(matches){elContent=_linkifyUrls(matches,$el)}}if(extendedOptions.mentions){elContent=_linkifyMentions(elContent,links[extendedOptions.linkTo].baseUrl)}if(extendedOptions.hashtags){elContent=_linkifyHashtags(elContent,links[extendedOptions.linkTo])}return elContent}function _linkifyUrls(matches,$el){var elContent=$el.html();$.each(matches,function(){if($el.find("a[href='"+this+"']").length===0){elContent=elContent.replace(this,"<a href='"+this+"' target='_blank'>"+this+"</a>")}});return elContent}function _linkifyMentions(text,baseUrl){return text.replace(/(^|\s|\(|>)@(\w+)/g,"$1<a href='"+baseUrl+"$2' target='_blank'>@$2</a>")}function _linkifyHashtags(text,links){if(links.hashtagSearchUrl===null)return text;return text.replace(/(^|\s|\(|>)#((\w|[\u00A1-\uFFFF])+)/g,"$1<a href='"+links.baseUrl+links.hashtagSearchUrl+"$2' target='_blank'>#$2</a>")}})(jQuery);
|