Index: mollom.js =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/mollom/mollom.js,v retrieving revision 1.2.2.5 diff -u -p -r1.2.2.5 mollom.js --- mollom.js 12 Apr 2009 19:29:20 -0000 1.2.2.5 +++ mollom.js 3 Jul 2009 23:00:23 -0000 @@ -2,8 +2,9 @@ Drupal.behaviors.mollom = function() { // Add onclick.event handlers for CAPTCHA links: - $('a#mollom-audio-captcha').click(getAudioCaptcha); - $('a#mollom-image-captcha').click(getImageCaptcha); + $('a#mollom-switch-audio').click(getAudioCaptcha); + $('a#mollom-switch-image').click(getImageCaptcha); + $('a#mollom-refresh-captcha').click(refreshCaptcha); } function getAudioCaptcha() { @@ -15,10 +16,11 @@ function getAudioCaptcha() { function(data) { // When data is successfully loaded, replace // contents of captcha-div with an audio CAPTCHA: - $('a#mollom-captcha').parent().html(data); + $('a#mollom-captcha').replaceWith(data); + $('a#mollom-switch-audio').replaceWith('' + Drupal.t('Use image CAPTCHA') + ''); // Add an onclick-event handler for the new link: - $('a#mollom-image-captcha').click(getImageCaptcha); + $('a#mollom-switch-image').click(getImageCaptcha); }); return false; } @@ -32,10 +34,22 @@ function getImageCaptcha() { function(data) { // When data is successfully loaded, replace // contents of captcha-div with an image CAPTCHA: - $('a#mollom-captcha').parent().html(data); + $('a#mollom-captcha').replaceWith(data); + $('a#mollom-switch-image').replaceWith('' + Drupal.t('Play audio CAPTCHA') + ''); // Add an onclick-event handler for the new link: - $('a#mollom-audio-captcha').click(getAudioCaptcha); + $('a#mollom-switch-audio').click(getAudioCaptcha); }); return false; } + +function refreshCaptcha() { + if ($('a#mollom-captcha').hasClass('mollom-image')) { + getImageCaptcha(); + return false; + } + else if ($('a#mollom-captcha').hasClass('mollom-audio')) { + getAudioCaptcha(); + return false; + } +} Index: mollom.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/mollom/mollom.module,v retrieving revision 1.2.2.64 diff -u -p -r1.2.2.64 mollom.module --- mollom.module 18 Jun 2009 10:04:46 -0000 1.2.2.64 +++ mollom.module 3 Jul 2009 23:00:25 -0000 @@ -124,25 +124,20 @@ function mollom_perm() { * AJAX callback to retrieve a CAPTCHA. */ function mollom_captcha_js($type, $session_id) { - // TODO: add error handling. $output = ''; if ($type == 'audio') { $response = mollom('mollom.getAudioCaptcha', array('author_ip' => ip_address(), 'session_id' => $session_id)); - if ($response) { - $output = ''; - $output .= ' ('. t('use image CAPTCHA') .')'; + $output = ''; } } if ($type == 'image') { $response = mollom('mollom.getImageCaptcha', array('author_ip' => ip_address(), 'session_id' => $session_id)); - if ($response) { - $output = 'Mollom CAPTCHA'; - $output .= ' ('. t('play audio CAPTCHA') .')'; + $output = 'Mollom CAPTCHA'; } } @@ -276,8 +271,8 @@ function mollom_report_node_submit($form function mollom_mail_alter(&$message) { if (isset($GLOBALS['mollom_response']) && isset($GLOBALS['mollom_response']['session_id'])) { $report_link = t('Report as inappropriate: @link', array('@link' => url('mollom/contact/'. $GLOBALS['mollom_response']['session_id'], array('absolute' => TRUE)))); - // The _mail_alter hook seems to accept both arrays as strings so we - // need to handle both. TODO: it seems like something we want to clean + // The _mail_alter hook seems to accept both arrays as strings so we + // need to handle both. TODO: it seems like something we want to clean // up upstream. if (is_array($message['body'])) { $message['body'][] = $report_link; @@ -1037,7 +1032,8 @@ function _mollom_insert_captcha(&$mollom '#type' => 'textfield', '#processed' => TRUE, '#title' => t('Word verification'), - '#field_prefix' => 'Mollom CAPTCHA ('. t('play audio CAPTCHA') .')', + '#field_prefix' => 'Mollom CAPTCHA', + '#field_suffix' => '' . t('Refresh CAPTCHA') . ' | '. t('Play audio CAPTCHA') .'', '#required' => TRUE, '#size' => 10, // The previously entered value is useless because the captcha is regenerated at each form rebuild. @@ -1092,9 +1088,9 @@ function _mollom_retrieve_server_list() * Call a remote procedure at the Mollom server. This function * automatically adds the information required to authenticate against * Mollom. - * + * * TODO: currently this function's return value mixes actual values and - * error values. We should rewrite the error handling so that calling + * error values. We should rewrite the error handling so that calling * functions can properly handle error situations. */ function mollom($method, $data = array()) { @@ -1181,7 +1177,7 @@ function mollom($method, $data = array() // Report this error: watchdog('mollom', 'No Mollom servers could be reached or all servers returned an error -- the server list was emptied.', NULL, WATCHDOG_ERROR); - + return NETWORK_ERROR; }