PageSourceSearch

https://www.onespan.com/modules/contrib/multiselect_dropdown/js/dist/multiselect-dropdown.js?v=1.2.2

js onespan.com collected 2026-10-01 09:06:51 UTC 5,508 bytes, 172 lines download raw bytes

1/**
2 * @file
3 * Behaviors for Multiselect Dropdowns.
4 */
5
6'use strict';
7
8import MultiselectDropdowns from './multiselect-dropdowns.js';
9window.MultiselectDropdowns = new MultiselectDropdowns();
10((Drupal, once, dropdowns) => {
11  /**
12   * Open or close the multiselect dropdown when the toggle button is clicked.
13   */
14  Drupal.behaviors.multiselectDropdownToggle = {
15    attach: context => {
16      once('multiselect-dropdown-toggle', dropdowns.getInstances(context)).forEach(multiselect => {
17        const toggle = dropdowns.getToggle(multiselect);
18        if (toggle) {
19          toggle.addEventListener('click', event => {
20            event.preventDefault();
21            dropdowns.toggle(multiselect, true);
22          });
23        }
24      });
25    }
26  };
27
28  /**
29   * Update the multiselect dropdown toggle label when the checked items change.
30   */
31  Drupal.behaviors.multiselectDropdownToggleLabel = {
32    attach: context => {
33      once('multiselect-dropdown-label', dropdowns.getInstances(context)).forEach(multiselect => {
34        MultiselectDropdowns.getCheckboxes(multiselect).forEach(checkbox => {
35          // Set the number of checked items on load.
36          dropdowns.updateLabel(multiselect);
37          checkbox.addEventListener('change', () => {
38            dropdowns.updateLabel(multiselect);
39          });
40        });
41      });
42    }
43  };
44
45  /**
46   * Close the multiselect dropdown dialog when the dialog button is clicked.
47   */
48  Drupal.behaviors.multiselectDropdownDialogClose = {
49    attach: context => {
50      once('multiselect-dropdown-dialog-close', dropdowns.getInstances(context)).forEach(multiselect => {
51        const close = dropdowns.getDialogClose(multiselect);
52        if (close) {
53          close.addEventListener('click', event => {
54            event.preventDefault();
55            dropdowns.close(multiselect);
56          });
57        }
58      });
59    }
60  };
61
62  /**
63   * Close all multiselect dropdown dialogs when the escape key is pressed.
64   */
65  Drupal.behaviors.multiselectDropdownEscapeClose = {
66    attach: () => {
67      if (once('multiselect-dropdown-escape-close', 'html').length) {
68        window.addEventListener('keydown', event => {
69          if (event.key === 'Escape') {
70            dropdowns.getInstances(document).forEach(multiselect => {
71              dropdowns.close(multiselect);
72            });
73          }
74        });
75      }
76    }
77  };
78
79  /**
80   * Close a multiselect dropdown dialog when clicking outside it.
81   */
82  Drupal.behaviors.multiselectDropdownClickClose = {
83    attach: () => {
84      if (once('multiselect-dropdown-click-close', 'html').length) {
85        window.addEventListener('click', event => {
86          const clickedMultiselect = dropdowns.getInstance(event.target);
87          dropdowns.getInstances(document).forEach(multiselect => {
88            if (multiselect !== clickedMultiselect) {
89              dropdowns.close(multiselect);
90            }
91          });
92        });
93      }
94    }
95  };
96
97  /**
98   * Clear a multiselect dropdown and submit the form.
99   */
100  Drupal.behaviors.multiselectDropdownClearButton = {
101    attach: context => {
102      once('multiselect-dropdown-clear-button', dropdowns.getInstances(context)).forEach(multiselect => {
103        const clear = dropdowns.getClear(multiselect);
104        if (clear) {
105          clear.addEventListener('click', event => {
106            event.preventDefault();
107            MultiselectDropdowns.getCheckboxes(multiselect).forEach(checkbox => {
108              checkbox.checked = false;
109            });
110            dropdowns.submit(multiselect);
111          });
112        }
113      });
114    }
115  };
116
117  /**
118   * Select all multiselect dropdown items when the all button is clicked.
119   */
120  Drupal.behaviors.multiselectDropdownSelectAll = {
121    attach: context => {
122      once('multiselect-dropdown-select-all', dropdowns.getInstances(context)).forEach(multiselect => {
123        const selectAll = dropdowns.getSelectAll(multiselect);
124        if (selectAll) {
125          const changeEvent = new Event('change');
126          selectAll.addEventListener('click', () => {
127            MultiselectDropdowns.getCheckboxes(multiselect).forEach(checkbox => {
128              checkbox.checked = true;
129              checkbox.dispatchEvent(changeEvent);
130            });
131          });
132        }
133      });
134    }
135  };
136
137  /**
138   * Deselect all multiselect dropdown items when the none button is clicked.
139   */
140  Drupal.behaviors.multiselectDropdownSelectNone = {
141    attach: context => {
142      once('multiselect-dropdown-select-none', dropdowns.getInstances(context)).forEac
142h(multiselect => {
143        const selectNone = dropdowns.getSelectNone(multiselect);
144        if (selectNone) {
145          const changeEvent = new Event('change');
146          selectNone.addEventListener('click', () => {
147            MultiselectDropdowns.getCheckboxes(multiselect).forEach(checkbox => {
148              checkbox.checked = false;
149              checkbox.dispatchEvent(changeEvent);
150            });
151          });
152        }
153      });
154    }
155  };
156
157  /**
158   * Search in multiselect dropdown item lists.
159   */
160  Drupal.behaviors.multiselectDropdownSearch = {
161    attach: context => {
162      once('multiselect-dropdown-search', dropdowns.getInstances(context)).forEach(multiselect => {
163        const search = dropdowns.getSearchInput(multiselect);
164        if (search) {
165          search.addEventListener('input', () => {
166            dropdowns.filter(multiselect);
167          });
168        }
169      });
170    }
171  };
172})(Drupal, once, window.MultiselectDropdowns);

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.