tom-select-rails 0.2.0 → 2.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tom-select-rails/version.rb +1 -1
- data/vendor/assets/javascripts/tom-select-rails/cjs/tom-select.complete.js +761 -273
- data/vendor/assets/javascripts/tom-select-rails/cjs/tom-select.complete.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/cjs/tom-select.js +756 -272
- data/vendor/assets/javascripts/tom-select-rails/cjs/tom-select.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/cjs/tom-select.popular.js +753 -269
- data/vendor/assets/javascripts/tom-select-rails/cjs/tom-select.popular.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/cjs/utils.js +1 -1
- data/vendor/assets/javascripts/tom-select-rails/cjs/utils.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/esm/plugins/caret_position/plugin.js +9 -5
- data/vendor/assets/javascripts/tom-select-rails/esm/plugins/caret_position/plugin.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/esm/plugins/change_listener/plugin.js +1 -1
- data/vendor/assets/javascripts/tom-select-rails/esm/plugins/change_listener/plugin.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/esm/plugins/checkbox_options/plugin.js +12 -7
- data/vendor/assets/javascripts/tom-select-rails/esm/plugins/checkbox_options/plugin.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/esm/plugins/clear_button/plugin.js +13 -8
- data/vendor/assets/javascripts/tom-select-rails/esm/plugins/clear_button/plugin.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/esm/plugins/drag_drop/plugin.js +1 -1
- data/vendor/assets/javascripts/tom-select-rails/esm/plugins/drag_drop/plugin.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/esm/plugins/dropdown_header/plugin.js +12 -7
- data/vendor/assets/javascripts/tom-select-rails/esm/plugins/dropdown_header/plugin.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/esm/plugins/dropdown_input/plugin.js +12 -8
- data/vendor/assets/javascripts/tom-select-rails/esm/plugins/dropdown_input/plugin.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/esm/plugins/input_autogrow/plugin.js +1 -1
- data/vendor/assets/javascripts/tom-select-rails/esm/plugins/input_autogrow/plugin.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/esm/plugins/no_active_items/plugin.js +1 -1
- data/vendor/assets/javascripts/tom-select-rails/esm/plugins/no_active_items/plugin.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/esm/plugins/no_backspace_delete/plugin.js +1 -1
- data/vendor/assets/javascripts/tom-select-rails/esm/plugins/no_backspace_delete/plugin.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/esm/plugins/optgroup_columns/plugin.js +9 -4
- data/vendor/assets/javascripts/tom-select-rails/esm/plugins/optgroup_columns/plugin.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/esm/plugins/remove_button/plugin.js +12 -7
- data/vendor/assets/javascripts/tom-select-rails/esm/plugins/remove_button/plugin.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/esm/plugins/restore_on_backspace/plugin.js +1 -1
- data/vendor/assets/javascripts/tom-select-rails/esm/plugins/restore_on_backspace/plugin.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/esm/plugins/virtual_scroll/plugin.js +16 -8
- data/vendor/assets/javascripts/tom-select-rails/esm/plugins/virtual_scroll/plugin.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/esm/tom-select.complete.js +761 -273
- data/vendor/assets/javascripts/tom-select-rails/esm/tom-select.complete.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/esm/tom-select.js +756 -272
- data/vendor/assets/javascripts/tom-select-rails/esm/tom-select.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/esm/tom-select.popular.js +753 -269
- data/vendor/assets/javascripts/tom-select-rails/esm/tom-select.popular.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/esm/utils.js +1 -1
- data/vendor/assets/javascripts/tom-select-rails/esm/utils.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/js/plugins/caret_position.js +164 -160
- data/vendor/assets/javascripts/tom-select-rails/js/plugins/caret_position.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/js/plugins/change_listener.js +1 -1
- data/vendor/assets/javascripts/tom-select-rails/js/plugins/change_listener.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/js/plugins/checkbox_options.js +12 -7
- data/vendor/assets/javascripts/tom-select-rails/js/plugins/checkbox_options.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/js/plugins/clear_button.js +94 -89
- data/vendor/assets/javascripts/tom-select-rails/js/plugins/clear_button.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/js/plugins/drag_drop.js +1 -1
- data/vendor/assets/javascripts/tom-select-rails/js/plugins/drag_drop.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/js/plugins/dropdown_header.js +121 -116
- data/vendor/assets/javascripts/tom-select-rails/js/plugins/dropdown_header.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/js/plugins/dropdown_input.js +234 -230
- data/vendor/assets/javascripts/tom-select-rails/js/plugins/dropdown_input.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/js/plugins/input_autogrow.js +1 -1
- data/vendor/assets/javascripts/tom-select-rails/js/plugins/input_autogrow.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/js/plugins/no_active_items.js +1 -1
- data/vendor/assets/javascripts/tom-select-rails/js/plugins/no_active_items.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/js/plugins/no_backspace_delete.js +1 -1
- data/vendor/assets/javascripts/tom-select-rails/js/plugins/no_backspace_delete.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/js/plugins/optgroup_columns.js +112 -107
- data/vendor/assets/javascripts/tom-select-rails/js/plugins/optgroup_columns.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/js/plugins/remove_button.js +149 -144
- data/vendor/assets/javascripts/tom-select-rails/js/plugins/remove_button.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/js/plugins/restore_on_backspace.js +1 -1
- data/vendor/assets/javascripts/tom-select-rails/js/plugins/restore_on_backspace.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/js/plugins/virtual_scroll.js +277 -269
- data/vendor/assets/javascripts/tom-select-rails/js/plugins/virtual_scroll.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/js/tom-select.base.js +756 -272
- data/vendor/assets/javascripts/tom-select-rails/js/tom-select.base.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/js/tom-select.base.min.js +329 -272
- data/vendor/assets/javascripts/tom-select-rails/js/tom-select.base.min.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/js/tom-select.complete.js +761 -273
- data/vendor/assets/javascripts/tom-select-rails/js/tom-select.complete.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/js/tom-select.complete.min.js +268 -209
- data/vendor/assets/javascripts/tom-select-rails/js/tom-select.complete.min.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/js/tom-select.popular.js +753 -269
- data/vendor/assets/javascripts/tom-select-rails/js/tom-select.popular.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/js/tom-select.popular.min.js +348 -291
- data/vendor/assets/javascripts/tom-select-rails/js/tom-select.popular.min.js.map +1 -1
- data/vendor/assets/javascripts/tom-select-rails/types/tom-select.d.ts +6 -6
- data/vendor/assets/javascripts/tom-select-rails/types/types/settings.d.ts +19 -22
- data/vendor/assets/javascripts/tom-select-rails/types/utils.d.ts +5 -5
- data/vendor/assets/javascripts/tom-select-rails/types/vanilla.d.ts +2 -2
- data/vendor/assets/stylesheets/tom-select-rails/css/tom-select.bootstrap4.css +41 -19
- data/vendor/assets/stylesheets/tom-select-rails/css/tom-select.bootstrap4.css.map +1 -1
- data/vendor/assets/stylesheets/tom-select-rails/css/tom-select.bootstrap4.min.css +1 -1
- data/vendor/assets/stylesheets/tom-select-rails/css/tom-select.bootstrap4.min.css.map +1 -1
- data/vendor/assets/stylesheets/tom-select-rails/css/tom-select.bootstrap5.css +61 -34
- data/vendor/assets/stylesheets/tom-select-rails/css/tom-select.bootstrap5.css.map +1 -1
- data/vendor/assets/stylesheets/tom-select-rails/css/tom-select.bootstrap5.min.css +1 -1
- data/vendor/assets/stylesheets/tom-select-rails/css/tom-select.bootstrap5.min.css.map +1 -1
- data/vendor/assets/stylesheets/tom-select-rails/css/tom-select.css +39 -17
- data/vendor/assets/stylesheets/tom-select-rails/css/tom-select.css.map +1 -1
- data/vendor/assets/stylesheets/tom-select-rails/css/tom-select.default.css +41 -19
- data/vendor/assets/stylesheets/tom-select-rails/css/tom-select.default.css.map +1 -1
- data/vendor/assets/stylesheets/tom-select-rails/css/tom-select.default.min.css +1 -1
- data/vendor/assets/stylesheets/tom-select-rails/css/tom-select.default.min.css.map +1 -1
- data/vendor/assets/stylesheets/tom-select-rails/css/tom-select.min.css +1 -1
- data/vendor/assets/stylesheets/tom-select-rails/css/tom-select.min.css.map +1 -1
- data/vendor/assets/stylesheets/tom-select-rails/scss/plugins/clear_button.scss +11 -10
- data/vendor/assets/stylesheets/tom-select-rails/scss/plugins/remove_button.scss +34 -8
- data/vendor/assets/stylesheets/tom-select-rails/scss/tom-select.bootstrap4.scss +1 -1
- data/vendor/assets/stylesheets/tom-select-rails/scss/tom-select.bootstrap5.scss +20 -10
- data/vendor/assets/stylesheets/tom-select-rails/scss/tom-select.default.scss +1 -1
- data/vendor/assets/stylesheets/tom-select-rails/scss/tom-select.scss +11 -2
- metadata +3 -3
@@ -1,279 +1,287 @@
|
|
1
1
|
/**
|
2
|
-
* Tom Select v2.1
|
2
|
+
* Tom Select v2.2.1
|
3
3
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
*/
|
5
5
|
|
6
6
|
(function (global, factory) {
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
8
|
+
typeof define === 'function' && define.amd ? define(factory) :
|
9
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.virtual_scroll = factory());
|
10
10
|
})(this, (function () { 'use strict';
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
12
|
+
/*! @orchidjs/unicode-variants | https://github.com/orchidjs/unicode-variants | Apache License (v2) */
|
13
|
+
const accent_pat = '[\u0300-\u036F\u{b7}\u{2be}]'; // \u{2bc}
|
14
|
+
/** @type {TUnicodeMap} */
|
15
|
+
|
16
|
+
const latin_convert = {
|
17
|
+
'æ': 'ae',
|
18
|
+
'ⱥ': 'a',
|
19
|
+
'ø': 'o',
|
20
|
+
'⁄': '/',
|
21
|
+
'∕': '/'
|
22
|
+
};
|
23
|
+
new RegExp(Object.keys(latin_convert).join('|') + '|' + accent_pat, 'gu');
|
24
|
+
|
25
|
+
/**
|
26
|
+
* Iterates over arrays and hashes.
|
27
|
+
*
|
28
|
+
* ```
|
29
|
+
* iterate(this.items, function(item, id) {
|
30
|
+
* // invoked for each item
|
31
|
+
* });
|
32
|
+
* ```
|
33
|
+
*
|
34
|
+
*/
|
35
|
+
|
36
|
+
const iterate = (object, callback) => {
|
37
|
+
if (Array.isArray(object)) {
|
38
|
+
object.forEach(callback);
|
39
|
+
} else {
|
40
|
+
for (var key in object) {
|
41
|
+
if (object.hasOwnProperty(key)) {
|
42
|
+
callback(object[key], key);
|
43
|
+
}
|
44
|
+
}
|
45
|
+
}
|
46
|
+
};
|
47
|
+
|
48
|
+
/**
|
49
|
+
* Add css classes
|
50
|
+
*
|
51
|
+
*/
|
52
|
+
|
53
|
+
const addClasses = (elmts, ...classes) => {
|
54
|
+
var norm_classes = classesArray(classes);
|
55
|
+
elmts = castAsArray(elmts);
|
56
|
+
elmts.map(el => {
|
57
|
+
norm_classes.map(cls => {
|
58
|
+
el.classList.add(cls);
|
59
|
+
});
|
60
|
+
});
|
61
|
+
};
|
62
|
+
/**
|
63
|
+
* Return arguments
|
64
|
+
*
|
65
|
+
*/
|
66
|
+
|
67
|
+
const classesArray = args => {
|
68
|
+
var classes = [];
|
69
|
+
iterate(args, _classes => {
|
70
|
+
if (typeof _classes === 'string') {
|
71
|
+
_classes = _classes.trim().split(/[\11\12\14\15\40]/);
|
72
|
+
}
|
73
|
+
|
74
|
+
if (Array.isArray(_classes)) {
|
75
|
+
classes = classes.concat(_classes);
|
76
|
+
}
|
77
|
+
});
|
78
|
+
return classes.filter(Boolean);
|
79
|
+
};
|
80
|
+
/**
|
81
|
+
* Create an array from arg if it's not already an array
|
82
|
+
*
|
83
|
+
*/
|
84
|
+
|
85
|
+
const castAsArray = arg => {
|
86
|
+
if (!Array.isArray(arg)) {
|
87
|
+
arg = [arg];
|
88
|
+
}
|
89
|
+
|
90
|
+
return arg;
|
91
|
+
};
|
92
|
+
|
93
|
+
/**
|
94
|
+
* Plugin: "restore_on_backspace" (Tom Select)
|
95
|
+
* Copyright (c) contributors
|
96
|
+
*
|
97
|
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
|
98
|
+
* file except in compliance with the License. You may obtain a copy of the License at:
|
99
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
100
|
+
*
|
101
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
102
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
103
|
+
* ANY KIND, either express or implied. See the License for the specific language
|
104
|
+
* governing permissions and limitations under the License.
|
105
|
+
*
|
106
|
+
*/
|
107
|
+
function plugin () {
|
108
|
+
const self = this;
|
109
|
+
const orig_canLoad = self.canLoad;
|
110
|
+
const orig_clearActiveOption = self.clearActiveOption;
|
111
|
+
const orig_loadCallback = self.loadCallback;
|
112
|
+
var pagination = {};
|
113
|
+
var dropdown_content;
|
114
|
+
var loading_more = false;
|
115
|
+
var load_more_opt;
|
116
|
+
var default_values = [];
|
117
|
+
|
118
|
+
if (!self.settings.shouldLoadMore) {
|
119
|
+
// return true if additional results should be loaded
|
120
|
+
self.settings.shouldLoadMore = () => {
|
121
|
+
const scroll_percent = dropdown_content.clientHeight / (dropdown_content.scrollHeight - dropdown_content.scrollTop);
|
122
|
+
|
123
|
+
if (scroll_percent > 0.9) {
|
124
|
+
return true;
|
125
|
+
}
|
126
|
+
|
127
|
+
if (self.activeOption) {
|
128
|
+
var selectable = self.selectable();
|
129
|
+
var index = Array.from(selectable).indexOf(self.activeOption);
|
130
|
+
|
131
|
+
if (index >= selectable.length - 2) {
|
132
|
+
return true;
|
133
|
+
}
|
134
|
+
}
|
135
|
+
|
136
|
+
return false;
|
137
|
+
};
|
138
|
+
}
|
139
|
+
|
140
|
+
if (!self.settings.firstUrl) {
|
141
|
+
throw 'virtual_scroll plugin requires a firstUrl() method';
|
142
|
+
} // in order for virtual scrolling to work,
|
143
|
+
// options need to be ordered the same way they're returned from the remote data source
|
144
|
+
|
145
|
+
|
146
|
+
self.settings.sortField = [{
|
147
|
+
field: '$order'
|
148
|
+
}, {
|
149
|
+
field: '$score'
|
150
|
+
}]; // can we load more results for given query?
|
151
|
+
|
152
|
+
const canLoadMore = query => {
|
153
|
+
if (typeof self.settings.maxOptions === 'number' && dropdown_content.children.length >= self.settings.maxOptions) {
|
154
|
+
return false;
|
155
|
+
}
|
156
|
+
|
157
|
+
if (query in pagination && pagination[query]) {
|
158
|
+
return true;
|
159
|
+
}
|
160
|
+
|
161
|
+
return false;
|
162
|
+
};
|
163
|
+
|
164
|
+
const clearFilter = (option, value) => {
|
165
|
+
if (self.items.indexOf(value) >= 0 || default_values.indexOf(value) >= 0) {
|
166
|
+
return true;
|
167
|
+
}
|
168
|
+
|
169
|
+
return false;
|
170
|
+
}; // set the next url that will be
|
171
|
+
|
172
|
+
|
173
|
+
self.setNextUrl = (value, next_url) => {
|
174
|
+
pagination[value] = next_url;
|
175
|
+
}; // getUrl() to be used in settings.load()
|
176
|
+
|
177
|
+
|
178
|
+
self.getUrl = query => {
|
179
|
+
if (query in pagination) {
|
180
|
+
const next_url = pagination[query];
|
181
|
+
pagination[query] = false;
|
182
|
+
return next_url;
|
183
|
+
} // if the user goes back to a previous query
|
184
|
+
// we need to load the first page again
|
185
|
+
|
186
|
+
|
187
|
+
pagination = {};
|
188
|
+
return self.settings.firstUrl.call(self, query);
|
189
|
+
}; // don't clear the active option (and cause unwanted dropdown scroll)
|
190
|
+
// while loading more results
|
191
|
+
|
192
|
+
|
193
|
+
self.hook('instead', 'clearActiveOption', () => {
|
194
|
+
if (loading_more) {
|
195
|
+
return;
|
196
|
+
}
|
197
|
+
|
198
|
+
return orig_clearActiveOption.call(self);
|
199
|
+
}); // override the canLoad method
|
200
|
+
|
201
|
+
self.hook('instead', 'canLoad', query => {
|
202
|
+
// first time the query has been seen
|
203
|
+
if (!(query in pagination)) {
|
204
|
+
return orig_canLoad.call(self, query);
|
205
|
+
}
|
206
|
+
|
207
|
+
return canLoadMore(query);
|
208
|
+
}); // wrap the load
|
209
|
+
|
210
|
+
self.hook('instead', 'loadCallback', (options, optgroups) => {
|
211
|
+
if (!loading_more) {
|
212
|
+
self.clearOptions(clearFilter);
|
213
|
+
} else if (load_more_opt) {
|
214
|
+
const first_option = options[0];
|
215
|
+
|
216
|
+
if (first_option !== undefined) {
|
217
|
+
load_more_opt.dataset.value = first_option[self.settings.valueField];
|
218
|
+
}
|
219
|
+
}
|
220
|
+
|
221
|
+
orig_loadCallback.call(self, options, optgroups);
|
222
|
+
loading_more = false;
|
223
|
+
}); // add templates to dropdown
|
224
|
+
// loading_more if we have another url in the queue
|
225
|
+
// no_more_results if we don't have another url in the queue
|
226
|
+
|
227
|
+
self.hook('after', 'refreshOptions', () => {
|
228
|
+
const query = self.lastValue;
|
229
|
+
var option;
|
230
|
+
|
231
|
+
if (canLoadMore(query)) {
|
232
|
+
option = self.render('loading_more', {
|
233
|
+
query: query
|
234
|
+
});
|
235
|
+
|
236
|
+
if (option) {
|
237
|
+
option.setAttribute('data-selectable', ''); // so that navigating dropdown with [down] keypresses can navigate to this node
|
238
|
+
|
239
|
+
load_more_opt = option;
|
240
|
+
}
|
241
|
+
} else if (query in pagination && !dropdown_content.querySelector('.no-results')) {
|
242
|
+
option = self.render('no_more_results', {
|
243
|
+
query: query
|
244
|
+
});
|
245
|
+
}
|
246
|
+
|
247
|
+
if (option) {
|
248
|
+
addClasses(option, self.settings.optionClass);
|
249
|
+
dropdown_content.append(option);
|
250
|
+
}
|
251
|
+
}); // add scroll listener and default templates
|
252
|
+
|
253
|
+
self.on('initialize', () => {
|
254
|
+
default_values = Object.keys(self.options);
|
255
|
+
dropdown_content = self.dropdown_content; // default templates
|
256
|
+
|
257
|
+
self.settings.render = Object.assign({}, {
|
258
|
+
loading_more: () => {
|
259
|
+
return `<div class="loading-more-results">Loading more results ... </div>`;
|
260
|
+
},
|
261
|
+
no_more_results: () => {
|
262
|
+
return `<div class="no-more-results">No more results</div>`;
|
263
|
+
}
|
264
|
+
}, self.settings.render); // watch dropdown content scroll position
|
265
|
+
|
266
|
+
dropdown_content.addEventListener('scroll', () => {
|
267
|
+
if (!self.settings.shouldLoadMore.call(self)) {
|
268
|
+
return;
|
269
|
+
} // !important: this will get checked again in load() but we still need to check here otherwise loading_more will be set to true
|
270
|
+
|
271
|
+
|
272
|
+
if (!canLoadMore(self.lastValue)) {
|
273
|
+
return;
|
274
|
+
} // don't call load() too much
|
275
|
+
|
276
|
+
|
277
|
+
if (loading_more) return;
|
278
|
+
loading_more = true;
|
279
|
+
self.load.call(self, self.lastValue);
|
280
|
+
});
|
281
|
+
});
|
282
|
+
}
|
283
|
+
|
284
|
+
return plugin;
|
277
285
|
|
278
286
|
}));
|
279
287
|
//# sourceMappingURL=virtual_scroll.js.map
|