PageSourceSearch

https://stereolux.org/modules/contrib/views_autosubmit/js/views_autosubmit.js?v=1

js stereolux.org collected 2026-09-24 10:01:45 UTC 2,194 bytes, 66 lines download raw bytes

1/**
2 * Views exposed filter autosubmit js for Drupal 8.
3 */
4
5(function ($, drupalSettings) {
6
7Drupal.behaviors.ViewsAutoSubmit = {
8  attach: function(context) {
9    // 'this' references the form element.
10    function triggerSubmit (e) {
11      var $this = $(this);
12      if (!$this.hasClass('views-ajaxing')) {
13        $this.find('.views-auto-submit-click').click();
14      }
15    }
16
17    // the change event bubbles so we only need to bind it to the outer form
18    $(once('views-auto-submit', 'form.views-auto-submit-full-form, .views-auto-submit-full-form form', context))
19      .add('.views-auto-submit', context)
20      .filter('form, select, input:not(:text, :submit)')
21      .change(function (e) {
22        // don't trigger on text change for full-form.
23        if ($(e.target).is(':not(:text, :submit, [data-autosubmit="false"])')) {
24          triggerSubmit.call(e.target.form);
25        }
26      });
27
28    // e.keyCode: key
29    var discardKeyCode = [
30      16, // shift
31      17, // ctrl
32      18, // alt
33      20, // caps lock
34      33, // page up
35      34, // page down
36      35, // end
37      36, // home
38      37, // left arrow
39      38, // up arrow
40      39, // right arrow
41      40, // down arrow
42       9, // tab
43      13, // enter
44      27  // esc
45    ];
46    // Don't wait for change event on textfields.
47    $(once('views-auto-submit', $(context)
48      .find('.views-auto-submit-full-form input:text:not([data-autosubmit="false"]), input:text.views-auto-submit')))
49      .each(function() {
50        // Each text input element has his own timeout.
51        var timeoutID = 0;
52        $(this)
53          .bind('keydown keyup', function (e) {
54            if ($.inArray(e.keyCode, discardKeyCode) === -1  && (e.target.value.length === 0 || e.target.value.length > 2) ) {
55              timeoutID && clearTimeout(timeoutID);
56            }
57          })
58          .keyup(function(e) {
59            if ($.inArray(e.keyCode, discardKeyCode) === -1  && (e.target.value.length === 0 || e.target.value.length > 2) ) {
60              timeoutID = setTimeout($.proxy(triggerSubmit, this.form), drupalSettings.views_autosubmit.timeout);
61            }
62          });
63      });
64  }
65}
66}(jQuery, drupalSettings));

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.