diff -u b/hide_submit.js b/hide_submit.js --- b/hide_submit.js +++ b/hide_submit.js @@ -1,66 +1,88 @@ -(function ($) { +(function ($, win) { Drupal.behaviors.hideSubmitBlockit = { attach: function(context) { - $('form').each(function (i) { - var form = $(this); - $('input.form-submit', form).click(function (e) { + var timeoutId = null; + $('form', context).once('hideSubmitButton', function () { + var $form = $(this); + + // Bind to input elements. + $('input.form-submit', $form).click(function (e) { var el = $(this); el.after(''); return true; }); - }); - $('form').submit(function (e) { - var settings = Drupal.settings.hide_submit; - var inp; - if (settings.hide_submit_method == 'disable') { - $('input.form-submit', $(this)).attr('disabled', 'disabled').each(function (i) { - if (settings.hide_submit_css) { - $(this).addClass(settings.hide_submit_css); + // Bind to form submit. + $form.submit(function (e) { + var settings = Drupal.settings.hide_submit; + var $inp; + if (!e.isPropagationStopped()) { + if (settings.hide_submit_method == 'disable') { + $('input.form-submit', $form).attr('disabled', 'disabled').each(function (i) { + var $button = $(this); + if (settings.hide_submit_css) { + $button.addClass(settings.hide_submit_css); + } + if (settings.hide_submit_abtext) { + $button.val($button.val() + ' ' + settings.hide_submit_abtext); + } + $inp = $button; + }); + + if ($inp && settings.hide_submit_atext) { + $inp.after('' + Drupal.checkPlain(settings.hide_submit_atext) + ''); + } } - if (settings.hide_submit_abtext) { - $(this).val($(this).val() + ' ' + settings.hide_submit_abtext); + else { + var pdiv = '
' + Drupal.checkPlain(settings.hide_submit_hide_text) + '
'; + if (settings.hide_submit_hide_fx) { + $('input.form-submit', $form).addClass(settings.hide_submit_css).fadeOut(100).eq(0).after(pdiv); + $('input.form-submit', $form).next().fadeIn(100); + } + else { + $('input.form-submit', $form).addClass(settings.hide_submit_css).hide().eq(0).after(pdiv); + } + } + // Add a timeout to rerset the buttons (if needed). + if (settings.hide_submit_reset_time) { + timeoutId = window.setTimeout(function() { + hideSubmitResetButtons(null, $form); + }, settings.hide_submit_reset_time); } - inp = $(this); - }); - - if (inp && settings.hide_submit_atext) { - inp.after('' + Drupal.checkPlain(settings.hide_submit_atext) + ''); - } - } - else { - var pdiv = '
' + Drupal.checkPlain(settings.hide_submit_hide_text) + '
'; - if (settings.hide_submit_hide_fx) { - $('input.form-submit', $(this)).addClass(settings.hide_submit_css).fadeOut(100).eq(0).after(pdiv); - $('input.form-submit', $(this)).next().fadeIn(100); - } - else { - $('input.form-submit', $(this)).addClass(settings.hide_submit_css).hide().eq(0).after(pdiv); } - } - return true; + return true; + }); }); // Bind to clientsideValidationFormHasErrors to support clientside validation. $(document).bind('clientsideValidationFormHasErrors', function(event, form) { + //hideSubmitResetButtons(event, form.form); + }); + + // Reset all buttons. + function hideSubmitResetButtons(event, form) { + // Clear timer. + window.clearTimeout(timeoutId); + timeoutId = null; + var settings = Drupal.settings.hide_submit; if (settings.hide_submit_method == 'disable') { - $('input.' + Drupal.checkPlain(settings.hide_submit_css), form.form) + $('input.' + Drupal.checkPlain(settings.hide_submit_css), form) .removeClass(Drupal.checkPlain(settings.hide_submit_hide_css)) .removeAttr('disabled'); - $('.hide-submit-text', form.form).remove(); + $('.hide-submit-text', form).remove(); } else { - $('input.' + Drupal.checkPlain(settings.hide_submit_css), form.form) + $('input.' + Drupal.checkPlain(settings.hide_submit_css), form) .stop() .removeClass(Drupal.checkPlain(settings.hide_submit_hide_css)) .show(); - $('.hide-submit-text', form.form).remove(); + $('.hide-submit-text', form).remove(); } - }); + } } }; -})(jQuery); +})(jQuery, window); only in patch2: unchanged: --- a/hide_submit.admin.inc +++ b/hide_submit.admin.inc @@ -22,6 +22,15 @@ function hide_submit_settings() { '#description' => t('Choose the blocking method.'), ); + $form['hide_submit_reset_time'] = array( + '#type' => 'textfield', + '#title' => t('Reset buttons after some time (ms).'), + '#description' => t('Enter a value in milliseconds after which all buttons will be enabled. To disable this enter 0.'), + '#default_value' => variable_get('hide_submit_reset_time', 5000), + '#element_validate' => array('_hide_submit_is_numeric'), + '#required' => TRUE, + ); + $form['hide_submit_disable'] = array( '#type' => 'fieldset', '#title' => t('Disabling settings'), @@ -66,3 +75,9 @@ function hide_submit_settings() { return system_settings_form($form); } + +function _hide_submit_is_numeric($element, &$form_state, $form) { + if (!is_numeric($element['#value']) || !ctype_digit($element['#value'])) { + form_error($element, t('This field only accepts integers.')); + } +} only in patch2: unchanged: --- a/hide_submit.install +++ b/hide_submit.install @@ -19,4 +19,5 @@ function hide_submit_uninstall() { variable_del('hide_submit_hide_css'); variable_del('hide_submit_hide_text'); variable_del('hide_submit_hide_fx'); + variable_del('hide_submit_reset_time'); } only in patch2: unchanged: --- a/hide_submit.module +++ b/hide_submit.module @@ -21,6 +21,7 @@ function hide_submit_init() { 'hide_submit_hide_css' => variable_get('hide_submit_hide_css', 'hide-submit-processing'), 'hide_submit_hide_text' => t(variable_get('hide_submit_hide_text', 'Processing...')), 'hide_submit_hide_fx' => t(variable_get('hide_submit_hide_fx', FALSE)), + 'hide_submit_reset_time' => (int)variable_get('hide_submit_reset_time', 5000), )); // Allow other modules to modify this behavior.