PageSourceSearch

https://atheistrepublic.com/misc/form-single-submit.js?v=7.103

js atheistrepublic.com collected 2026-09-24 09:21:46 UTC 2,619 bytes, 60 lines download raw bytes

1(function ($) {
2
3/**
4 * Prevents consecutive form submissions of identical form values.
5 *
6 * Repetitive form submissions that would submit the identical form values are
7 * prevented, unless the form values are different from the previously
8 * submitted values.
9 *
10 * This is a simplified re-implementation of a user-agent behavior that should
11 * be natively supported by major web browsers, but at this time, only Firefox
12 * has a built-in protection.
13 *
14 * A form value-based approach ensures that the constraint is triggered for
15 * consecutive, identical form submissions only. Compared to that, a form
16 * button-based approach would (1) rely on [visible] buttons to exist where
17 * technically not required and (2) require more complex state management if
18 * there are multiple buttons in a form.
19 *
20 * This implementation is based on form-level submit events only and relies on
21 * jQuery's serialize() method to determine submitted form values. As such, the
22 * following limitations exist:
23 *
24 * - Event handlers on form buttons that preventDefault() do not receive a
25 *   double-submit protection. That is deemed to be fine, since such button
26 *   events typically trigger reversible client-side or server-side operations
27 *   that are local to the context of a form only.
28 * - Changed values in advanced form controls, such as file inputs, are not part
29 *   of the form values being compared between consecutive form submits (due to
30 *   limitations of jQuery.serialize()). That is deemed to be acceptable,
31 *   because if the user forgot to attach a file, then the size of HTTP payload
32 *   will most likely be small enough to be fully passed to the server endpoint
33 *   within (milli)seconds. If a user mistakenly attached a wrong file and is
34 *   technically versed enough to cancel the form submission (and HTTP payload)
35 *   in order to attach a different file, then that edge-case is not supported
36 *   here.
37 *
38 * Lastly, all forms submitted via HTTP GET are idempotent by definition of HTTP
39 * standards, so excluded in this implementation.
40 */
41Drupal.behaviors.formSingleSubmit = {
42  attach: function () {
43    function onFormSubmit (e) {
44      var $form = $(e.currentTarget);
45      var formValues = $form.serialize();
46      var previousValues = $form.attr('data-drupal-form-submit-last');
47      if (previousValues === formValues) {
48        e.preventDefault();
49      }
50      else {
51        $form.attr('data-drupal-form-submit-last', formValues);
52      }
53    }
54
55    $('body').once('form-single-submit')
56      .delegate('form:not([method~="GET"])', 'submit.singleSubmit', onFormSubmit);
57  }
58};
59
60})(jQuery);

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.