pastebin

Paste Search Dynamic
Recent pastes
/spamspan.js
  1. /*
  2. --------------------------------------------------------------------------
  3. (c) 2007 Lawrence Akka
  4.  - jquery version of the spamspan code (c) 2006 SpamSpan (www.spamspan.com)
  5.  
  6. This program is distributed under the terms of the GNU General Public
  7. Licence version 2, available at http://www.gnu.org/licenses/gpl.txt
  8. --------------------------------------------------------------------------
  9. */
  10.  
  11. (function ($) { //Standard drupal jQuery wrapper.  See http://drupal.org/update/modules/6/7#javascript_compatibility
  12. // load SpamSpan
  13. Drupal.behaviors.spamspan = {
  14.   attach: function(context, settings) {
  15.     // get each span with class spamspan
  16.     $("span.spamspan", context).each(function (index) {
  17.       // Replace each <spam class="t"></spam> with .
  18.       if ($('span.t', this).length) {
  19.         $('span.t', this).replaceWith('.');
  20.       }
  21.      
  22.       // For each selected span, set mail to the relevant value, removing spaces
  23.       var _mail = ($("span.u", this).text() +
  24.         "@" +
  25.         $("span.d", this).text())
  26.         .replace(/\s+/g, '');
  27.       // Find the header text, and remove the round brackets from the start and end
  28.       var _headerText = $("span.h", this).text().replace(/^ ?\((.*)\) ?$/, "$1");
  29.       // split into individual headers, and return as an array of header=value pairs
  30.       var _headers = $.map(_headerText.split(/, /), function(n, i){
  31.         return (n.replace(/: /,"="));
  32.       });
  33.       // Find the anchor text, and remove the round brackets from the start and end
  34.       var _anchorText = $("span.t", this).text().replace(/^ \((.*)\)$/, "$1");
  35.       // Build the mailto URI
  36.       var _mailto = "mailto:" + encodeURIComponent(_mail);
  37.       var _headerstring = _headers.join('&');
  38.       _mailto += _headerstring ? ("?" + _headerstring) : '';
  39.       // create the <a> element, and replace the original span contents
  40.       // Issue https://www.drupal.org/node/1540732
  41.       // .attr("href", _mailto) replaced by .attr("href", decodeURIComponent(_mailto))
  42.       $(this).after(
  43.         $("<a></a>")
  44.           .attr("href", decodeURIComponent(_mailto))
  45.           .html(_anchorText ? _anchorText : _mail)
  46.           .addClass("spamspan")
  47.       ).remove();
  48.     });
  49.   }
  50. };
  51. }) (jQuery);
Parsed in 0.021 seconds