Skip to content
This repository
Browse code

adding linkify

  • Loading branch information...
commit 600ede7bca72b2917cf388999a3eef5a0fd64c61 1 parent 49b992f
markmacgillivray markmacgillivray authored
3  vendor/linkify/1.0/jquery.linkify-1.0-min.js
... ... @@ -0,0 +1,3 @@
  1 +// encoding: utf-8
  2 +// $.fn.linkify 1.0 - MIT/GPL Licensed - More info: http://github.com/maranomynet/linkify/
  3 +(function(b){var x=/(^|["'(\s]|&lt;)(www\..+?\..+?)((?:[:?]|\.+)?(?:\s|$)|&gt;|[)"',])/g,y=/(^|["'(\s]|&lt;)((?:(?:https?|ftp):\/\/|mailto:).+?)((?:[:?]|\.+)?(?:\s|$)|&gt;|[)"',])/g,z=function(h){return h.replace(x,'$1<a href="<``>://$2">$2</a>$3').replace(y,'$1<a href="$2">$2</a>$3').replace(/"<``>/g,'"http')},s=b.fn.linkify=function(c){if(!b.isPlainObject(c)){c={use:(typeof c=='string')?c:undefined,handleLinks:b.isFunction(c)?c:arguments[1]}}var d=c.use,k=s.plugins||{},l=[z],f,m=[],n=c.handleLinks;if(d==undefined||d=='*'){for(var i in k){l.push(k[i])}}else{d=b.isArray(d)?d:b.trim(d).split(/ *, */);var o,i;for(var p=0,A=d.length;p<A;p++){i=d[p];o=k[i];if(o){l.push(o)}}}this.each(function(){var h=this.childNodes,t=h.length;while(t--){var e=h[t];if(e.nodeType==3){var a=e.nodeValue;if(a.length>1&&/\S/.test(a)){var q,r;f=f||b('<div/>')[0];f.innerHTML='';f.appendChild(e.cloneNode(false));var u=f.childNodes;for(var v=0,g;(g=l[v]);v++){var w=u.length,j;while(w--){j=u[w];if(j.nodeType==3){a=j.nodeValue;if(a.length>1&&/\S/.test(a)){r=a;a=a.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');a=b.isFunction(g)?g(a):a.replace(g.re,g.tmpl);q=q||r!=a;r!=a&&b(j).after(a).remove()}}}}a=f.innerHTML;if(n){a=b('<div/>').html(a);m=m.concat(a.find('a').toArray().reverse());a=a.contents()}q&&b(e).after(a).remove()}}else if(e.nodeType==1&&!/^(a|button|textarea)$/i.test(e.tagName)){arguments.callee.call(e)}}});n&&n(b(m.reverse()));return this};s.plugins={mailto:{re:/(^|["'(\s]|&lt;)([^"'(\s&]+?@.+\.[a-z]{2,7})(([:?]|\.+)?(\s|$)|&gt;|[)"',])/gi,tmpl:'$1<a href="mailto:$2">$2</a>$3'}}})(jQuery);
192 vendor/linkify/1.0/jquery.linkify-1.0.js
... ... @@ -0,0 +1,192 @@
  1 +/* encoding: utf-8
  2 +
  3 + **** linkify plugin for jQuery - automatically finds and changes URLs in text content into proper hyperlinks ****
  4 +
  5 + Version: 1.0
  6 +
  7 + Copyright (c) 2009
  8 + Már Örlygsson (http://mar.anomy.net/) &
  9 + Hugsmiðjan ehf. (http://www.hugsmidjan.is)
  10 +
  11 + Dual licensed under a MIT licence (http://en.wikipedia.org/wiki/MIT_License)
  12 + and GPL 2.0 or above (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html).
  13 +
  14 +-----------------------------------------------------------------------------
  15 +
  16 + Demo and Qunit-tests:
  17 + * <./jquery.linkify-1.0-demo.html>
  18 + * <./jquery.linkify-1.0-test.html>
  19 +
  20 + Documentation:
  21 + * ...
  22 +
  23 + Get updates from:
  24 + * <http://github.com/maranomynet/linkify/>
  25 + * <git://github.com/maranomynet/linkify.git>
  26 +
  27 +-----------------------------------------------------------------------------
  28 +
  29 + Requires:
  30 + * jQuery (1.2.6 or later)
  31 +
  32 + Usage:
  33 +
  34 + jQuery('.articlebody').linkify();
  35 +
  36 + // adding plugins:
  37 + jQuery.extend( jQuery.fn.linkify.plugins, {
  38 + name1: {
  39 + re: RegExp
  40 + tmpl: String/Function
  41 + },
  42 + name2: function(html){ return html; }
  43 + });
  44 +
  45 + // Uses all plugins by default:
  46 + jQuery('.articlebody').linkify();
  47 +
  48 + // Use only certain plugins:
  49 + jQuery('.articlebody').linkify( 'name1,name2' );
  50 + jQuery('.articlebody').linkify({ use: 'name1,name2' });
  51 + jQuery('.articlebody').linkify({ use: ['name1','name2'] });
  52 +
  53 + // Explicitly use all plugins:
  54 + jQuery('.articlebody').linkify('*');
  55 + jQuery('.articlebody').linkify({ use: '*' });
  56 + jQuery('.articlebody').linkify({ use: ['*'] });
  57 +
  58 + // Use no plugins:
  59 + jQuery('.articlebody').linkify('');
  60 + jQuery('.articlebody').linkify({ use: '' });
  61 + jQuery('.articlebody').linkify({ use: [] });
  62 + jQuery('.articlebody').linkify({ use: [''] });
  63 +
  64 + // Perfmorm actions on all newly created links:
  65 + jQuery('.articlebody').linkify( function (links){ links.addClass('linkified'); } );
  66 + jQuery('.articlebody').linkify({ handleLinks: function (links){ links.addClass('linkified'); } });
  67 +
  68 +*/
  69 +
  70 +(function($){
  71 +
  72 + var noProtocolUrl = /(^|["'(\s]|&lt;)(www\..+?\..+?)((?:[:?]|\.+)?(?:\s|$)|&gt;|[)"',])/g,
  73 + httpOrMailtoUrl = /(^|["'(\s]|&lt;)((?:(?:https?|ftp):\/\/|mailto:).+?)((?:[:?]|\.+)?(?:\s|$)|&gt;|[)"',])/g,
  74 + linkifier = function ( html ) {
  75 + return html
  76 + .replace( noProtocolUrl, '$1<a href="<``>://$2">$2</a>$3' ) // NOTE: we escape `"http` as `"<``>` to make sure `httpOrMailtoUrl` below doesn't find it as a false-positive
  77 + .replace( httpOrMailtoUrl, '$1<a href="$2">$2</a>$3' )
  78 + .replace( /"<``>/g, '"http' ); // reinsert `"http`
  79 + },
  80 +
  81 +
  82 + linkify = $.fn.linkify = function ( cfg ) {
  83 + if ( !$.isPlainObject( cfg ) )
  84 + {
  85 + cfg = {
  86 + use: (typeof cfg == 'string') ? cfg : undefined,
  87 + handleLinks: $.isFunction(cfg) ? cfg : arguments[1]
  88 + };
  89 + }
  90 + var use = cfg.use,
  91 + allPlugins = linkify.plugins || {},
  92 + plugins = [linkifier],
  93 + tmpCont,
  94 + newLinks = [],
  95 + callback = cfg.handleLinks;
  96 + if ( use == undefined || use == '*' ) // use === undefined || use === null
  97 + {
  98 + for ( var name in allPlugins )
  99 + {
  100 + plugins.push( allPlugins[name] );
  101 + }
  102 + }
  103 + else
  104 + {
  105 + use = $.isArray( use ) ? use : $.trim(use).split( / *, */ );
  106 + var plugin,
  107 + name;
  108 + for ( var i=0, l=use.length; i<l; i++ )
  109 + {
  110 + name = use[i];
  111 + plugin = allPlugins[name];
  112 + if ( plugin )
  113 + {
  114 + plugins.push( plugin );
  115 + }
  116 + }
  117 + }
  118 +
  119 + this.each(function () {
  120 + var childNodes = this.childNodes,
  121 + i = childNodes.length;
  122 + while ( i-- )
  123 + {
  124 + var n = childNodes[i];
  125 + if ( n.nodeType == 3 )
  126 + {
  127 + var html = n.nodeValue;
  128 + if ( html.length>1 && /\S/.test(html) )
  129 + {
  130 + var htmlChanged,
  131 + preHtml;
  132 + tmpCont = tmpCont || $('<div/>')[0];
  133 + tmpCont.innerHTML = '';
  134 + tmpCont.appendChild( n.cloneNode(false) );
  135 + var tmpContNodes = tmpCont.childNodes;
  136 +
  137 + for (var j=0, plugin; (plugin = plugins[j]); j++)
  138 + {
  139 + var k = tmpContNodes.length,
  140 + tmpNode;
  141 + while ( k-- )
  142 + {
  143 + tmpNode = tmpContNodes[k];
  144 + if ( tmpNode.nodeType == 3 )
  145 + {
  146 + html = tmpNode.nodeValue;
  147 + if ( html.length>1 && /\S/.test(html) )
  148 + {
  149 + preHtml = html;
  150 + html = html
  151 + .replace( /&/g, '&amp;' )
  152 + .replace( /</g, '&lt;' )
  153 + .replace( />/g, '&gt;' );
  154 + html = $.isFunction( plugin ) ?
  155 + plugin( html ):
  156 + html.replace( plugin.re, plugin.tmpl );
  157 + htmlChanged = htmlChanged || preHtml!=html;
  158 + preHtml!=html && $(tmpNode).after(html).remove();
  159 + }
  160 + }
  161 + }
  162 + }
  163 + html = tmpCont.innerHTML;
  164 + if ( callback )
  165 + {
  166 + html = $('<div/>').html(html);
  167 + //newLinks.push.apply( newLinks, html.find('a').toArray() );
  168 + newLinks = newLinks.concat( html.find('a').toArray().reverse() );
  169 + html = html.contents();
  170 + }
  171 + htmlChanged && $(n).after(html).remove();
  172 + }
  173 + }
  174 + else if ( n.nodeType == 1 && !/^(a|button|textarea)$/i.test(n.tagName) )
  175 + {
  176 + arguments.callee.call( n );
  177 + }
  178 + };
  179 + });
  180 + callback && callback( $(newLinks.reverse()) );
  181 + return this;
  182 + };
  183 +
  184 + linkify.plugins = {
  185 + // default mailto: plugin
  186 + mailto: {
  187 + re: /(^|["'(\s]|&lt;)([^"'(\s&]+?@.+\.[a-z]{2,7})(([:?]|\.+)?(\s|$)|&gt;|[)"',])/gi,
  188 + tmpl: '$1<a href="mailto:$2">$2</a>$3'
  189 + }
  190 + };
  191 +
  192 +})(jQuery);
2  vendor/linkify/1.0/plugins/jquery.linkify-1.0-twitter-min.js
... ... @@ -0,0 +1,2 @@
  1 +// Twitter plugin for jQuery.fn.linkify() 1.0 - MIT/GPL Licensed
  2 +jQuery.extend(jQuery.fn.linkify.plugins,{twitterUser:{re:/(^|["'(]|&lt;|\s)@([a-z0-9_-]+)((?:[:?]|\.+)?(?:\s|$)|&gt;|[)"',])/gi,tmpl:'$1<a href="http://www.twitter.com/$2">@$2</a>$3'},twitterHashtag:{re:/(^|["'(]|&lt;|\s)(#.+?)((?:[:?]|\.+)?(?:\s|$)|&gt;|[)"',])/gi,tmpl:function(d,b,a,c){return b+'<a href="http://www.twitter.com/search?q='+encodeURIComponent(a)+'">'+a+'</a>'+c}}});
27 vendor/linkify/1.0/plugins/jquery.linkify-1.0-twitter.js
... ... @@ -0,0 +1,27 @@
  1 +/* encoding: utf-8
  2 +
  3 + **** Twitter linking plugin for jQuery.fn.linkify() 1.0 ****
  4 +
  5 + Version 1.0
  6 +
  7 + Copyright (c) 2010
  8 + Már Örlygsson (http://mar.anomy.net/) &
  9 + Hugsmiðjan ehf. (http://www.hugsmidjan.is)
  10 +
  11 + Dual licensed under a MIT licence (http://en.wikipedia.org/wiki/MIT_License)
  12 + and GPL 2.0 or above (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html).
  13 +
  14 +*/
  15 +jQuery.extend(jQuery.fn.linkify.plugins, {
  16 + twitterUser: {
  17 + re: /(^|["'(]|&lt;|\s)@([a-z0-9_-]+)((?:[:?]|\.+)?(?:\s|$)|&gt;|[)"',])/gi,
  18 + tmpl: '$1<a href="http://www.twitter.com/$2">@$2</a>$3'
  19 + },
  20 + twitterHashtag: {
  21 + // /\B#\w*[a-zA-Z]+\w*/gi // start at word boundry - must include at least one a-z - ends at word boundry
  22 + re: /(^|["'(]|&lt;|\s)(#.+?)((?:[:?]|\.+)?(?:\s|$)|&gt;|[)"',])/gi,
  23 + tmpl: function (match, pre, hashTag, post) {
  24 + return pre+'<a href="http://www.twitter.com/search?q='+ encodeURIComponent(hashTag) +'">'+hashTag+'</a>'+post;
  25 + }
  26 + }
  27 +});

0 comments on commit 600ede7

Please sign in to comment.
Something went wrong with that request. Please try again.