You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

autolink.js 540 B

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