Created
April 2, 2012 02:16
-
-
Save slav123/2280030 to your computer and use it in GitHub Desktop.
make active url's from javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery('#last_tweet').urlize(); | |
jQuery.fn.urlize = function() { | |
if (this.length > 0) { | |
this.each(function(i, obj){ | |
// making links active | |
var x = jQuery(obj).html(); | |
var list = x.match( /\b(http:\/\/|www\.|http:\/\/www\.|https:\/\/www\.|https:\/\/)[^ <]{2,200}\b/g ); | |
if (list) { | |
for ( i = 0; i < list.length; i++ ) { | |
var prot = list[i].indexOf('http://') === 0 || list[i].indexOf('https://') === 0 ? '' : 'http://'; | |
x = x.replace( list[i], "<a target='_blank' href='" + prot + list[i] + "'>"+ list[i] + "</a>" ); | |
} | |
} | |
jQuery(obj).html(x); | |
}); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment