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