diff --git a/1.0/jquery.linkify-1.0-min.js b/1.0/jquery.linkify-1.0-min.js index c17cb81..1a32d82 100644 --- a/1.0/jquery.linkify-1.0-min.js +++ b/1.0/jquery.linkify-1.0-min.js @@ -1,3 +1,3 @@ // encoding: utf-8 // $.fn.linkify 1.0 - MIT/GPL Licensed - More info: http://github.com/maranomynet/linkify/ -(function(c){var f=/(^|"|<|\s)(www\..+?\..+?)(\s|>|"|$)/g,g=/(^|"|<|\s)(((https?|ftp):\/\/|mailto:).+?)(\s|>|"|$)/g;c.fn.linkify=function(){return this.each(function(){var d=this.childNodes,e=d.length;while(e--){var a=d[e];if(a.nodeType==3){var b=a.nodeValue;if(/\S/.test(b)){b=b.replace(/&/g,'&').replace(//g,'>').replace(f,'$1$2$3').replace(g,'$1$2$5').replace(/"<``>/g,'"http');c(a).after(b).remove()}}else if(a.nodeType==1&&!/^(a|button|textarea)$/i.test(a.tagName)){arguments.callee.call(a)}}})}})(jQuery); +(function(b){var v=/(^|["'(]|<|\s)(www\..+?\..+?)(([:?]|\.+)?(\s|$)|>|[)"',])/g,w=/(^|["'(]|<|\s)(((https?|ftp):\/\/|mailto:).+?)(([:?]|\.+)?(\s|$)|>|[)"',])/g,x=function(h){return h.replace(v,'$1$2$3').replace(w,'$1$2$5').replace(/"<``>/g,'"http')},q=b.fn.linkify=function(e){e=e||{};if(typeof e=='string'){e={use:e}}var c=e.use,k=q.plugins||{},l=[x],f;if(c){c=b.isArray(c)?c:b.trim(c).split(/ *, */);var m,i;for(var n=0,y=c.length;n1&&/\S/.test(a)){var o,p;f=f||b('
')[0];f.innerHTML='';f.appendChild(d.cloneNode(false));var s=f.childNodes;for(var t=0,g;(g=l[t]);t++){var u=s.length,j;while(u--){j=s[u];if(j.nodeType==3){a=j.nodeValue;if(a.length>1&&/\S/.test(a)){p=a;a=a.replace(/&/g,'&').replace(//g,'>');a=b.isFunction(g)?g(a):a.replace(g.re,g.tmpl);o=o||p!=a;p!=a&&b(j).after(a).remove()}}}}a=f.innerHTML;o&&b(d).after(a).remove()}}else if(d.nodeType==1&&!/^(a|button|textarea)$/i.test(d.tagName)){arguments.callee.call(d)}}})};q.plugins={}})(jQuery); diff --git a/1.0/jquery.linkify-1.0-test.html b/1.0/jquery.linkify-1.0-test.html index 71c85e0..b7aa892 100644 --- a/1.0/jquery.linkify-1.0-test.html +++ b/1.0/jquery.linkify-1.0-test.html @@ -37,8 +37,10 @@ isOk = !pTitle ? a.length === 0: - a.length === 1 && (a.attr('href')||'') === pTitle && a.text() === (pLinktext||pTitle); - ok( isOk, p.data('orgHtml')+'\n   ==> '+this.innerHTML ); + a.length === pTitle.split(',').length + && $.map(a, function(a){ return $(a).attr('href')||''; }).join(',') === pTitle + && $.map(a, function(a){ return $(a).text(); }).join(',') === (pLinktext||pTitle); + ok( isOk, p.data('orgHtml')+'\n ==> '+this.innerHTML ); }, prepTest = function (selector) { @@ -131,6 +133,7 @@

http://www.foo.is

http://www.foo.is/ asdf

http://www.foo.is:8080. asd

+

http://www.foo.is:8080. asd (http://www.foo.is/#foo)...

http://www.foo.is:8080/path/?foo=1#arg #asdasdf

http://www.foo.is/#foo ?asddf

should I visit http://www.foo.is/? Sure

@@ -157,6 +160,9 @@

http://www.foo.is

+

blah http://www.foo.is @username blah

+

blah <http://www.foo.is/> blah #hashtag blah

+

blah (http://www.foo.is/) (#hashtag) blah

@username

blah @username blah

(@username)

diff --git a/1.0/jquery.linkify-1.0.js b/1.0/jquery.linkify-1.0.js index e451f4e..916fc41 100644 --- a/1.0/jquery.linkify-1.0.js +++ b/1.0/jquery.linkify-1.0.js @@ -55,6 +55,13 @@ var noProtocolUrl = /(^|["'(]|<|\s)(www\..+?\..+?)(([:?]|\.+)?(\s|$)|>|[)"',])/g, httpOrMailtoUrl = /(^|["'(]|<|\s)(((https?|ftp):\/\/|mailto:).+?)(([:?]|\.+)?(\s|$)|>|[)"',])/g, + linkifier = function ( html ) { + return html + .replace( noProtocolUrl, '$1$2$3' ) // NOTE: we escape `"http` as `"<``>` to make sure `httpOrMailtoUrl` below doesn't find it as a false-positive + .replace( httpOrMailtoUrl, '$1$2$5' ) + .replace( /"<``>/g, '"http' ); // reinsert `"http` + }, + linkify = $.fn.linkify = function ( cfg ) { cfg = cfg || {}; @@ -63,17 +70,30 @@ cfg = { use:cfg }; } var use = cfg.use, - plugins = linkify.plugins||{}; + allPlugins = linkify.plugins || {}, + plugins = [linkifier], + tmpCont; if ( use ) { use = $.isArray( use ) ? use : $.trim(use).split( / *, */ ); - var pluginShortlist = {}; - for ( var i=0, l=use.length, name; i1 && /\S/.test(html) ) { - html = html - .replace( /&/g, '&' ) - .replace( //g, '>' ); - var preHtml = html; - html = html - .replace( noProtocolUrl, '$1$2$3' ) // NOTE: we escape `"http` as `"<``>` to make sure `httpOrMailtoUrl` below doesn't find it as a false-positive - .replace( httpOrMailtoUrl, '$1$2$5' ) - .replace( /"<``>/g, '"http' ); // reinsert `"http` - - for ( var name in plugins ) - { - var plugin = plugins[name] || {}; - html = $.isFunction( plugin ) ? - plugin( html ): - html.replace( plugin.re, plugin.tmpl ); - } - if (html != preHtml) + var htmlChanged, + preHtml; + tmpCont = tmpCont || $('
')[0]; + tmpCont.innerHTML = ''; + tmpCont.appendChild( n.cloneNode(false) ); + var tmpContNodes = tmpCont.childNodes; + + for (var j=0, plugin; (plugin = plugins[j]); j++) { - $(n).after(html).remove(); + var k = tmpContNodes.length, + tmpNode; + while ( k-- ) + { + tmpNode = tmpContNodes[k]; + if ( tmpNode.nodeType == 3 ) + { + html = tmpNode.nodeValue; + if ( html.length>1 && /\S/.test(html) ) + { + preHtml = html; + html = html + .replace( /&/g, '&' ) + .replace( //g, '>' ); + html = $.isFunction( plugin ) ? + plugin( html ): + html.replace( plugin.re, plugin.tmpl ); + htmlChanged = htmlChanged || preHtml!=html; + preHtml!=html && $(tmpNode).after(html).remove(); + } + } + } } + html = tmpCont.innerHTML; + htmlChanged && $(n).after(html).remove(); } } else if ( n.nodeType == 1 && !/^(a|button|textarea)$/i.test(n.tagName) )