[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/mollom/ -> mollom.js (source)

   1  // $Id: mollom.js,v 1.2.2.13 2010/08/07 02:49:44 dries Exp $
   2  (function ($) {
   3  
   4  /**
   5   * Open Mollom privacy policy link in a new window.
   6   *
   7   * Required for valid XHTML Strict markup.
   8   */
   9  Drupal.behaviors.mollomPrivacy = function (context) {
  10    $('.mollom-privacy a', context).click(function () {
  11      this.target = '_blank';
  12    });
  13  };
  14  
  15  /**
  16   * Attach click event handlers for CAPTCHA links.
  17   */
  18  Drupal.behaviors.mollomCaptcha = function (context) {
  19    $('a.mollom-switch-captcha', context).click(getMollomCaptcha);
  20  };
  21  
  22  /**
  23   * Fetch a Mollom CAPTCHA and output the image or audio into the form.
  24   */
  25  function getMollomCaptcha() {
  26    // Get the current requested CAPTCHA type from the clicked link.
  27    var newCaptchaType = $(this).hasClass('mollom-audio-captcha') ? 'audio' : 'image';
  28  
  29    var context = $(this).parents('form');
  30  
  31    // Extract the Mollom session id from the form.
  32    var mollomSessionId = $('input.mollom-session-id', context).val();
  33  
  34    // Retrieve a CAPTCHA:
  35    $.getJSON(Drupal.settings.basePath + 'mollom/captcha/' + newCaptchaType + '/' + mollomSessionId,
  36      function (data) {
  37        if (!(data && data.content)) {
  38          return;
  39        }
  40        // Inject new CAPTCHA.
  41        $('.mollom-captcha-content', context).parent().html(data.content);
  42        // Update session id.
  43        $('input.mollom-session-id', context).val(data.session_id);
  44        // Add an onclick-event handler for the new link.
  45        Drupal.attachBehaviors(context);
  46        // Focus on the CATPCHA input.
  47        $('input[name="mollom[captcha]"]', context).focus();
  48      }
  49    );
  50    return false;
  51  }
  52  
  53  })(jQuery);


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7