您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

replacement.js 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /**
  2. * Processes links and smileys in "body"
  3. */
  4. function processReplacements(body)
  5. {
  6. //make links clickable
  7. body = linkify(body);
  8. //add smileys
  9. body = smilify(body);
  10. return body;
  11. }
  12. /**
  13. * Finds and replaces all links in the links in "body"
  14. * with their <a href=""></a>
  15. */
  16. function linkify(inputText)
  17. {
  18. var replacedText, replacePattern1, replacePattern2, replacePattern3;
  19. //URLs starting with http://, https://, or ftp://
  20. replacePattern1 = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim;
  21. replacedText = inputText.replace(replacePattern1, '<a href="$1" target="_blank">$1</a>');
  22. //URLs starting with "www." (without // before it, or it'd re-link the ones done above).
  23. replacePattern2 = /(^|[^\/])(www\.[\S]+(\b|$))/gim;
  24. replacedText = replacedText.replace(replacePattern2, '$1<a href="http://$2" target="_blank">$2</a>');
  25. //Change email addresses to mailto:: links.
  26. replacePattern3 = /(([a-zA-Z0-9\-\_\.])+@[a-zA-Z\_]+?(\.[a-zA-Z]{2,6})+)/gim;
  27. replacedText = replacedText.replace(replacePattern3, '<a href="mailto:$1">$1</a>');
  28. return replacedText;
  29. }
  30. /**
  31. * Replaces common smiley strings with images
  32. */
  33. function smilify(body)
  34. {
  35. if(!body) {
  36. return body;
  37. }
  38. for(var smiley in regexs) {
  39. if(regexs.hasOwnProperty(smiley)) {
  40. body = body.replace(regexs[smiley],
  41. '<img class="smiley" src="images/smileys/' + smiley + '.svg">');
  42. }
  43. }
  44. return body;
  45. }