Created
August 6, 2020 15:59
-
-
Save lazyjerry/e6e54405714840cf72553704211f53d8 to your computer and use it in GitHub Desktop.
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
<script> | |
/**/ | |
(function($){ | |
var url1 = /(^|<|\s)(www\..+?\..+?)(\s|>|$)/g, | |
url2 = /(^|<|\s)(((https?|ftp):\/\/|mailto:).+?)(\s|>|$)/g, | |
linkifyThis = function () { | |
var childNodes = this.childNodes, | |
i = childNodes.length; | |
while(i--) | |
{ | |
var n = childNodes[i]; | |
if (n.nodeType == 3) { | |
var html = $.trim(n.nodeValue); | |
if (html) | |
{ | |
html = html.replace(/&/g, '&') | |
.replace(/</g, '<') | |
.replace(/>/g, '>') | |
.replace(url1, '$1<a href="http://$2">$2</a>$3') | |
.replace(url2, '$1<a href="$2">$2</a>$5'); | |
$(n).after(html).remove(); | |
} | |
} | |
else if (n.nodeType == 1 && !/^(a|button|textarea)$/i.test(n.tagName)) { | |
linkifyThis.call(n); | |
} | |
} | |
}; | |
$.fn.linkify = function () { | |
return this.each(linkifyThis); | |
}; | |
})(jQuery); | |
/**/ | |
$('ID').linkify(); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment