1/** 2 * @file 3 * JavaScript behaviors for preventing duplicate webform submissions. 4 */ 5 6(function ($, Drupal, once) { 7 /** 8 * Submit once. 9 * 10 * @type {Drupal~behavior} 11 * 12 * @prop {Drupal~behaviorAttach} attach 13 * Attaches the behavior for preventing duplicate webform submissions. 14 */ 15 Drupal.behaviors.webformSubmitOnce = { 16 clear: function () { 17 var $form = $('.js-webform-submit-once'); 18 $form.removeData('webform-submitted'); 19 $form.find('.js-webform-wizard-pages-links :submit, .form-actions :submit').removeClass('is-disabled'); 20 $form.find('.form-actions .ajax-progress.ajax-progress-throbber').remove(); 21 }, 22 attach(context) { 23 $(once('webform-submit-once', '.js-webform-submit-once', context)).each(function () { 24 var $form = $(this); 25 // Remove data-webform-submitted. 26 $form.removeData('webform-submitted'); 27 // Remove .js-webform-submit-clicked. 28 $form.find('.js-webform-wizard-pages-links :submit, .form-actions :submit').removeClass('js-webform-submit-clicked'); 29 30 // Track which submit button was clicked. 31 // @see http://stackoverflow.com/questions/5721724/jquery-how-to-get-which-button-was-clicked-upon-form-submission 32 $form.find('.js-webform-wizard-pages-links :submit, .form-actions :submit').on('click', function () { 33 $form.find('.js-webform-wizard-pages-links :submit, .form-actions :submit') 34 .removeClass('js-webform-submit-clicked'); 35 $(this) 36 .addClass('js-webform-submit-clicked'); 37 }); 38 39 $(this).on('submit', function () { 40 // Find clicked button 41 var $clickedButton = $form.find('.js-webform-wizard-pages-links :submit.js-webform-submit-clicked, .form-actions :submit.js-webform-submit-clicked'); 42 43 // Don't submit if client-side validation has failed. 44 if (!$clickedButton.attr('formnovalidate') && (typeof jQuery.fn.valid === 'function') && !($form.valid())) { 45 return false; 46 } 47 48 // Track webform submitted. 49 if ($form.data('webform-submitted')) { 50 return false; 51 } 52 $form.data('webform-submitted', 'true'); 53 54 // Visually disable all submit buttons. 55 // Submit buttons can't disabled because their op(eration) must to be posted back to the server. 56 $form.find('.js-webform-wizard-pages-links :submit, .form-actions :submit').addClass('is-disabled'); 57 58 // Set the throbber progress indicator. 59 $clickedButton.after(Drupal.theme.ajaxProgressThrobber()); 60 }); 61 }); 62 } 63 }; 64 65})(jQuery, Drupal, once);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.