summaryrefslogtreecommitdiffstats
path: root/public/js/libs/autolink.js
blob: 3a9c0d4bcb104721a9cc7ca5fd0238cdc872dd25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
jQuery.fn.autolink = function() {
	var re = /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[\-;:&=\+\$,\w]+@)?[A-Za-z0-9\.\-]+|(?:www\.|[\-;:&=\+\$,\w]+@)[A-Za-z0-9\.\-]+)((?:\/[\+~%\/\.\w\-]*)?\??(?:[\-\+:=&;%@\.\w]*)#?(?:[\.\!\/\\\w]*))?)/g;
	return this.find('*').contents()
		.filter(function () { return this.nodeType === 3; })
		.each(function() {
			$(this).each(function() {
				if (re.test($(this).text()))
					$(this).replaceWith(
						$("<span />").html(
							this.nodeValue.replace(re, "<a href='$1'>$1</a>")
						)
					);
			});
		});
};