trln-chosen-rails 1.30.0.pre.beta → 1.30.0.pre.beta2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9a2a519cd6aabeb11949e84b419f7164bcd407377edf9af4ec681d17755754b1
4
- data.tar.gz: e116100e66af2f9f17c3b3c4434d628d32382dd40c4f48286e6ee3c5fdd7e071
3
+ metadata.gz: 23826cc4c7f94087e884b174932078085d21c9a61287b6824fc9aea92e5137ce
4
+ data.tar.gz: 439977a37a3af72dbdc3fcefd80af1c108183d3a3ccab3256cf2b63dd5a71960
5
5
  SHA512:
6
- metadata.gz: 73b2361856eae6fff2672e74e4b3f6fb09914e0f09f77654513a9b012ce7c75c270dcd7a5e9315588390c0e7cbe3a6a6c842863638b58414d14da0e685a86a60
7
- data.tar.gz: 55f49773c020454fbb6cf02197f456e1b7ecc672f859fe32905842d729501e9957761d158b24842c1a200557275aec83b7aed997c69c91d46252568add892d32
6
+ metadata.gz: e50707c2e0747debf9b7061afc3e24ade8fe594e60d0c22e4590293f48ee93495830e0675296edfe12d7f6586559a97976b010f56b8778c8991958cd3d49dba3
7
+ data.tar.gz: 3955af4f2ef86168b4b686e7be1bd02ceb64ac6ffaca6d7709d16a012a27733220a8c30a308b9f9882c9f36a9fe805750b8fd831a00e46d123ce6536540c28be
@@ -10,10 +10,6 @@ class SourceFile < Thor
10
10
  get "#{remote}/raw/#{branch}/public/chosen-sprite.png", 'images/chosen-sprite.png'
11
11
  get "#{remote}/raw/#{branch}/public/chosen-sprite@2x.png", 'images/chosen-sprite@2x.png'
12
12
  get "#{remote}/raw/#{branch}/sass/chosen.scss", 'stylesheets/chosen-base.scss'
13
- get "#{remote}/raw/#{branch}/coffee/lib/abstract-chosen.coffee", 'javascripts/lib/abstract-chosen.coffee'
14
- get "#{remote}/raw/#{branch}/coffee/lib/select-parser.coffee", 'javascripts/lib/select-parser.coffee'
15
- get "#{remote}/raw/#{branch}/coffee/chosen.jquery.coffee", 'javascripts/chosen.jquery.coffee'
16
- get "#{remote}/raw/#{branch}/coffee/chosen.proto.coffee", 'javascripts/chosen.proto.coffee'
17
13
  get "#{remote}/raw/#{branch}/package.json", 'package.json'
18
14
  bump_version
19
15
  end
@@ -21,11 +17,10 @@ class SourceFile < Thor
21
17
  desc 'eject class from closure', 'eject javascript library class from closure'
22
18
  def eject_javascript_class_from_closure
23
19
  self.destination_root = 'vendor/assets'
24
- inside destination_root do
25
- append_to_file 'javascripts/lib/abstract-chosen.coffee' do
20
+ append_to_file 'javascripts/lib/abstract-chosen.js' do
26
21
  "\nwindow.AbstractChosen = AbstractChosen\n"
27
22
  end
28
- append_to_file 'javascripts/lib/select-parser.coffee' do
23
+ append_to_file 'javascripts/lib/select-parser.js' do
29
24
  "\n\nwindow.SelectParser = SelectParser\n"
30
25
  end
31
26
  end
@@ -1,6 +1,6 @@
1
1
  module Chosen
2
2
  module Rails
3
- VERSION = '1.30.0-beta'
3
+ VERSION = '1.30.0-beta2'
4
4
  CHOSEN_VERSION = '1.8.7'
5
5
  end
6
6
  end
@@ -13,12 +13,13 @@ Gem::Specification.new do |gem|
13
13
  gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
14
  gem.name = 'trln-chosen-rails'
15
15
  gem.require_paths = ['lib']
16
+ gem.required_ruby_version = '>= 3.0'
16
17
  gem.version = Chosen::Rails::VERSION
17
18
  gem.license = 'MIT'
18
19
 
19
- gem.add_dependency 'railties', '>= 3.0'
20
- gem.add_dependency 'coffee-rails', '>= 3.2'
21
- gem.add_development_dependency 'bundler', '>= 1.0'
22
- gem.add_development_dependency 'rails', '>= 3.0'
23
- gem.add_development_dependency 'thor', '>= 0.14'
20
+ gem.add_dependency 'railties', '>= 6.0', '< 8'
21
+ #gem.add_dependency 'coffee-rails', '>= 3.2'
22
+ gem.add_development_dependency 'bundler', '>= 2.0', '< 3'
23
+ gem.add_development_dependency 'rails', '>= 6.0', '< 8'
24
+ gem.add_development_dependency 'thor', '>= 0.14', '< 2'
24
25
  end
@@ -0,0 +1,616 @@
1
+ /*
2
+ * decaffeinate suggestions:
3
+ * DS101: Remove unnecessary use of Array.from
4
+ * DS102: Remove unnecessary code created because of implicit returns
5
+ * DS207: Consider shorter variations of null checks
6
+ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
7
+ */
8
+ const $ = jQuery;
9
+
10
+ $.fn.extend({
11
+ chosen(options) {
12
+ // Do no harm and return as soon as possible for unsupported browsers, namely IE6 and IE7
13
+ // Continue on if running IE document type but in compatibility mode
14
+ if (!AbstractChosen.browser_is_supported()) { return this; }
15
+ return this.each(function(input_field) {
16
+ const $this = $(this);
17
+ const chosen = $this.data('chosen');
18
+ if (options === 'destroy') {
19
+ if (chosen instanceof Chosen) {
20
+ chosen.destroy();
21
+ }
22
+ return;
23
+ }
24
+ if (!(chosen instanceof Chosen)) {
25
+ $this.data('chosen', new Chosen(this, options));
26
+ }
27
+
28
+ });
29
+ }
30
+
31
+ });
32
+
33
+ class Chosen extends AbstractChosen {
34
+
35
+ setup() {
36
+ this.form_field_jq = $(this.form_field);
37
+ return this.current_selectedIndex = this.form_field.selectedIndex;
38
+ }
39
+
40
+ set_up_html() {
41
+ const container_classes = ["chosen-container"];
42
+ container_classes.push("chosen-container-" + (this.is_multiple ? "multi" : "single"));
43
+ if (this.inherit_select_classes && this.form_field.className) { container_classes.push(this.form_field.className); }
44
+ if (this.is_rtl) { container_classes.push("chosen-rtl"); }
45
+
46
+ const container_props = {
47
+ 'class': container_classes.join(' '),
48
+ 'title': this.form_field.title
49
+ };
50
+
51
+ if (this.form_field.id.length) { container_props.id = this.form_field.id.replace(/[^\w]/g, '_') + "_chosen"; }
52
+
53
+ this.container = ($("<div />", container_props));
54
+
55
+ // CSP without 'unsafe-inline' doesn't allow setting the style attribute directly
56
+ this.container.width(this.container_width());
57
+
58
+ if (this.is_multiple) {
59
+ this.container.html(this.get_multi_html());
60
+ } else {
61
+ this.container.html(this.get_single_html());
62
+ }
63
+
64
+ this.form_field_jq.hide().after(this.container);
65
+ this.dropdown = this.container.find('div.chosen-drop').first();
66
+
67
+ this.search_field = this.container.find('input').first();
68
+ this.search_results = this.container.find('ul.chosen-results').first();
69
+ this.search_field_scale();
70
+
71
+ this.search_no_results = this.container.find('li.no-results').first();
72
+
73
+ if (this.is_multiple) {
74
+ this.search_choices = this.container.find('ul.chosen-choices').first();
75
+ this.search_container = this.container.find('li.search-field').first();
76
+ } else {
77
+ this.search_container = this.container.find('div.chosen-search').first();
78
+ this.selected_item = this.container.find('.chosen-single').first();
79
+ }
80
+
81
+ this.results_build();
82
+ this.set_tab_index();
83
+ return this.set_label_behavior();
84
+ }
85
+
86
+ on_ready() {
87
+ return this.form_field_jq.trigger("chosen:ready", {chosen: this});
88
+ }
89
+
90
+ register_observers() {
91
+ this.container.on('touchstart.chosen', evt => { this.container_mousedown(evt); });
92
+ this.container.on('touchend.chosen', evt => { this.container_mouseup(evt); });
93
+
94
+ this.container.on('mousedown.chosen', evt => { this.container_mousedown(evt); });
95
+ this.container.on('mouseup.chosen', evt => { this.container_mouseup(evt); });
96
+ this.container.on('mouseenter.chosen', evt => { this.mouse_enter(evt); });
97
+ this.container.on('mouseleave.chosen', evt => { this.mouse_leave(evt); });
98
+
99
+ this.search_results.on('mouseup.chosen', evt => { this.search_results_mouseup(evt); });
100
+ this.search_results.on('mouseover.chosen', evt => { this.search_results_mouseover(evt); });
101
+ this.search_results.on('mouseout.chosen', evt => { this.search_results_mouseout(evt); });
102
+ this.search_results.on('mousewheel.chosen DOMMouseScroll.chosen', evt => { this.search_results_mousewheel(evt); });
103
+
104
+ this.search_results.on('touchstart.chosen', evt => { this.search_results_touchstart(evt); });
105
+ this.search_results.on('touchmove.chosen', evt => { this.search_results_touchmove(evt); });
106
+ this.search_results.on('touchend.chosen', evt => { this.search_results_touchend(evt); });
107
+
108
+ this.form_field_jq.on("chosen:updated.chosen", evt => { this.results_update_field(evt); });
109
+ this.form_field_jq.on("chosen:activate.chosen", evt => { this.activate_field(evt); });
110
+ this.form_field_jq.on("chosen:open.chosen", evt => { this.container_mousedown(evt); });
111
+ this.form_field_jq.on("chosen:close.chosen", evt => { this.close_field(evt); });
112
+
113
+ this.search_field.on('blur.chosen', evt => { this.input_blur(evt); });
114
+ this.search_field.on('keyup.chosen', evt => { this.keyup_checker(evt); });
115
+ this.search_field.on('keydown.chosen', evt => { this.keydown_checker(evt); });
116
+ this.search_field.on('focus.chosen', evt => { this.input_focus(evt); });
117
+ this.search_field.on('cut.chosen', evt => { this.clipboard_event_checker(evt); });
118
+ this.search_field.on('paste.chosen', evt => { this.clipboard_event_checker(evt); });
119
+
120
+ if (this.is_multiple) {
121
+ return this.search_choices.on('click.chosen', evt => { this.choices_click(evt); });
122
+ } else {
123
+ return this.container.on('click.chosen', function(evt) { evt.preventDefault(); }); // gobble click of anchor
124
+ }
125
+ }
126
+
127
+ destroy() {
128
+ $(this.container[0].ownerDocument).off('click.chosen', this.click_test_action);
129
+ if (this.form_field_label.length > 0) { this.form_field_label.off('click.chosen'); }
130
+
131
+ if (this.search_field[0].tabIndex) {
132
+ this.form_field_jq[0].tabIndex = this.search_field[0].tabIndex;
133
+ }
134
+
135
+ this.container.remove();
136
+ this.form_field_jq.removeData('chosen');
137
+ return this.form_field_jq.show();
138
+ }
139
+
140
+ search_field_disabled() {
141
+ this.is_disabled = this.form_field.disabled || this.form_field_jq.parents('fieldset').is(':disabled');
142
+
143
+ this.container.toggleClass('chosen-disabled', this.is_disabled);
144
+ this.search_field[0].disabled = this.is_disabled;
145
+
146
+ if (!this.is_multiple) {
147
+ this.selected_item.off('focus.chosen', this.activate_field);
148
+ }
149
+
150
+ if (this.is_disabled) {
151
+ return this.close_field();
152
+ } else if (!this.is_multiple) {
153
+ return this.selected_item.on('focus.chosen', this.activate_field);
154
+ }
155
+ }
156
+
157
+ container_mousedown(evt) {
158
+ if (this.is_disabled) { return; }
159
+
160
+ if (evt && ['mousedown', 'touchstart'].includes(evt.type) && !this.results_showing) {
161
+ evt.preventDefault();
162
+ }
163
+
164
+ if (!((evt != null) && ($(evt.target)).hasClass("search-choice-close"))) {
165
+ if (!this.active_field) {
166
+ if (this.is_multiple) { this.search_field.val(""); }
167
+ $(this.container[0].ownerDocument).on('click.chosen', this.click_test_action);
168
+ this.results_show();
169
+ } else if (!this.is_multiple && evt && (($(evt.target)[0] === this.selected_item[0]) || $(evt.target).parents("a.chosen-single").length)) {
170
+ evt.preventDefault();
171
+ this.results_toggle();
172
+ }
173
+
174
+ return this.activate_field();
175
+ }
176
+ }
177
+
178
+ container_mouseup(evt) {
179
+ if ((evt.target.nodeName === "ABBR") && !this.is_disabled) { return this.results_reset(evt); }
180
+ }
181
+
182
+ search_results_mousewheel(evt) {
183
+ let delta;
184
+ if (evt.originalEvent) { delta = evt.originalEvent.deltaY || -evt.originalEvent.wheelDelta || evt.originalEvent.detail; }
185
+ if (delta != null) {
186
+ evt.preventDefault();
187
+ if (evt.type === 'DOMMouseScroll') { delta = delta * 40; }
188
+ return this.search_results.scrollTop(delta + this.search_results.scrollTop());
189
+ }
190
+ }
191
+
192
+ blur_test(evt) {
193
+ if (!this.active_field && this.container.hasClass("chosen-container-active")) { return this.close_field(); }
194
+ }
195
+
196
+ close_field() {
197
+ $(this.container[0].ownerDocument).off("click.chosen", this.click_test_action);
198
+
199
+ this.active_field = false;
200
+ this.results_hide();
201
+
202
+ this.container.removeClass("chosen-container-active");
203
+ this.clear_backstroke();
204
+
205
+ this.show_search_field_default();
206
+ this.search_field_scale();
207
+ return this.search_field.blur();
208
+ }
209
+
210
+ activate_field() {
211
+ if (this.is_disabled) { return; }
212
+
213
+ this.container.addClass("chosen-container-active");
214
+ this.active_field = true;
215
+
216
+ this.search_field.val(this.search_field.val());
217
+ return this.search_field.focus();
218
+ }
219
+
220
+
221
+ test_active_click(evt) {
222
+ const active_container = $(evt.target).closest('.chosen-container');
223
+ if (active_container.length && (this.container[0] === active_container[0])) {
224
+ return this.active_field = true;
225
+ } else {
226
+ return this.close_field();
227
+ }
228
+ }
229
+
230
+ results_build() {
231
+ this.parsing = true;
232
+ this.selected_option_count = null;
233
+
234
+ this.results_data = SelectParser.select_to_array(this.form_field);
235
+
236
+ if (this.is_multiple) {
237
+ this.search_choices.find("li.search-choice").remove();
238
+ } else {
239
+ this.single_set_selected_text();
240
+ if (this.disable_search || (this.form_field.options.length <= this.disable_search_threshold)) {
241
+ this.search_field[0].readOnly = true;
242
+ this.container.addClass("chosen-container-single-nosearch");
243
+ } else {
244
+ this.search_field[0].readOnly = false;
245
+ this.container.removeClass("chosen-container-single-nosearch");
246
+ }
247
+ }
248
+
249
+ this.update_results_content(this.results_option_build({first:true}));
250
+
251
+ this.search_field_disabled();
252
+ this.show_search_field_default();
253
+ this.search_field_scale();
254
+
255
+ return this.parsing = false;
256
+ }
257
+
258
+ result_do_highlight(el) {
259
+ if (el.length) {
260
+ this.result_clear_highlight();
261
+
262
+ this.result_highlight = el;
263
+ this.result_highlight.addClass("highlighted");
264
+
265
+ const maxHeight = parseInt(this.search_results.css("maxHeight"), 10);
266
+ const visible_top = this.search_results.scrollTop();
267
+ const visible_bottom = maxHeight + visible_top;
268
+
269
+ const high_top = this.result_highlight.position().top + this.search_results.scrollTop();
270
+ const high_bottom = high_top + this.result_highlight.outerHeight();
271
+
272
+ if (high_bottom >= visible_bottom) {
273
+ return this.search_results.scrollTop((high_bottom - maxHeight) > 0 ? (high_bottom - maxHeight) : 0);
274
+ } else if (high_top < visible_top) {
275
+ return this.search_results.scrollTop(high_top);
276
+ }
277
+ }
278
+ }
279
+
280
+ result_clear_highlight() {
281
+ if (this.result_highlight) { this.result_highlight.removeClass("highlighted"); }
282
+ return this.result_highlight = null;
283
+ }
284
+
285
+ results_show() {
286
+ if (this.is_multiple && (this.max_selected_options <= this.choices_count())) {
287
+ this.form_field_jq.trigger("chosen:maxselected", {chosen: this});
288
+ return false;
289
+ }
290
+
291
+ this.container.addClass("chosen-with-drop");
292
+ this.results_showing = true;
293
+
294
+ this.search_field.focus();
295
+ this.search_field.val(this.get_search_field_value());
296
+
297
+ this.winnow_results();
298
+ return this.form_field_jq.trigger("chosen:showing_dropdown", {chosen: this});
299
+ }
300
+
301
+ update_results_content(content) {
302
+ return this.search_results.html(content);
303
+ }
304
+
305
+ results_hide() {
306
+ if (this.results_showing) {
307
+ this.result_clear_highlight();
308
+
309
+ this.container.removeClass("chosen-with-drop");
310
+ this.form_field_jq.trigger("chosen:hiding_dropdown", {chosen: this});
311
+ }
312
+
313
+ return this.results_showing = false;
314
+ }
315
+
316
+
317
+ set_tab_index(el) {
318
+ if (this.form_field.tabIndex) {
319
+ const ti = this.form_field.tabIndex;
320
+ this.form_field.tabIndex = -1;
321
+ return this.search_field[0].tabIndex = ti;
322
+ }
323
+ }
324
+
325
+ set_label_behavior() {
326
+ this.form_field_label = this.form_field_jq.parents("label"); // first check for a parent label
327
+ if (!this.form_field_label.length && this.form_field.id.length) {
328
+ this.form_field_label = $(`label[for='${this.form_field.id}']`); //next check for a for=#{id}
329
+ }
330
+
331
+ if (this.form_field_label.length > 0) {
332
+ return this.form_field_label.on('click.chosen', this.label_click_handler);
333
+ }
334
+ }
335
+
336
+ show_search_field_default() {
337
+ if (this.is_multiple && (this.choices_count() < 1) && !this.active_field) {
338
+ this.search_field.val(this.default_text);
339
+ return this.search_field.addClass("default");
340
+ } else {
341
+ this.search_field.val("");
342
+ return this.search_field.removeClass("default");
343
+ }
344
+ }
345
+
346
+ search_results_mouseup(evt) {
347
+ const target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
348
+ if (target.length) {
349
+ this.result_highlight = target;
350
+ this.result_select(evt);
351
+ return this.search_field.focus();
352
+ }
353
+ }
354
+
355
+ search_results_mouseover(evt) {
356
+ const target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
357
+ if (target) { return this.result_do_highlight( target ); }
358
+ }
359
+
360
+ search_results_mouseout(evt) {
361
+ if ($(evt.target).hasClass("active-result") || $(evt.target).parents('.active-result').first()) { return this.result_clear_highlight(); }
362
+ }
363
+
364
+ choice_build(item) {
365
+ const choice = $('<li />', { class: "search-choice" }).html(`<span>${this.choice_label(item)}</span>`);
366
+
367
+ if (item.disabled) {
368
+ choice.addClass('search-choice-disabled');
369
+ } else {
370
+ const close_link = $('<a />', { class: 'search-choice-close', 'data-option-array-index': item.array_index });
371
+ close_link.on('click.chosen', evt => this.choice_destroy_link_click(evt));
372
+ choice.append(close_link);
373
+ }
374
+
375
+ return this.search_container.before(choice);
376
+ }
377
+
378
+ choice_destroy_link_click(evt) {
379
+ evt.preventDefault();
380
+ evt.stopPropagation();
381
+ if (!this.is_disabled) { return this.choice_destroy($(evt.target)); }
382
+ }
383
+
384
+ choice_destroy(link) {
385
+ if (this.result_deselect( link[0].getAttribute("data-option-array-index") )) {
386
+ if (this.active_field) {
387
+ this.search_field.focus();
388
+ } else {
389
+ this.show_search_field_default();
390
+ }
391
+
392
+ if (this.is_multiple && (this.choices_count() > 0) && (this.get_search_field_value().length < 1)) { this.results_hide(); }
393
+
394
+ link.parents('li').first().remove();
395
+
396
+ return this.search_field_scale();
397
+ }
398
+ }
399
+
400
+ results_reset() {
401
+ this.reset_single_select_options();
402
+ this.form_field.options[0].selected = true;
403
+ this.single_set_selected_text();
404
+ this.show_search_field_default();
405
+ this.results_reset_cleanup();
406
+ this.trigger_form_field_change();
407
+ if (this.active_field) { return this.results_hide(); }
408
+ }
409
+
410
+ results_reset_cleanup() {
411
+ this.current_selectedIndex = this.form_field.selectedIndex;
412
+ return this.selected_item.find("abbr").remove();
413
+ }
414
+
415
+ result_select(evt) {
416
+ if (this.result_highlight) {
417
+ const high = this.result_highlight;
418
+
419
+ this.result_clear_highlight();
420
+
421
+ if (this.is_multiple && (this.max_selected_options <= this.choices_count())) {
422
+ this.form_field_jq.trigger("chosen:maxselected", {chosen: this});
423
+ return false;
424
+ }
425
+
426
+ if (this.is_multiple) {
427
+ high.removeClass("active-result");
428
+ } else {
429
+ this.reset_single_select_options();
430
+ }
431
+
432
+ high.addClass("result-selected");
433
+
434
+ const item = this.results_data[ high[0].getAttribute("data-option-array-index") ];
435
+ item.selected = true;
436
+
437
+ this.form_field.options[item.options_index].selected = true;
438
+ this.selected_option_count = null;
439
+
440
+ if (this.is_multiple) {
441
+ this.choice_build(item);
442
+ } else {
443
+ this.single_set_selected_text(this.choice_label(item));
444
+ }
445
+
446
+ if (this.is_multiple && (!this.hide_results_on_select || (evt.metaKey || evt.ctrlKey))) {
447
+ if (evt.metaKey || evt.ctrlKey) {
448
+ this.winnow_results({skip_highlight: true});
449
+ } else {
450
+ this.search_field.val("");
451
+ this.winnow_results();
452
+ }
453
+ } else {
454
+ this.results_hide();
455
+ this.show_search_field_default();
456
+ }
457
+
458
+ if (this.is_multiple || (this.form_field.selectedIndex !== this.current_selectedIndex)) { this.trigger_form_field_change({selected: this.form_field.options[item.options_index].value}); }
459
+ this.current_selectedIndex = this.form_field.selectedIndex;
460
+
461
+ evt.preventDefault();
462
+
463
+ return this.search_field_scale();
464
+ }
465
+ }
466
+
467
+ single_set_selected_text(text) {
468
+ if (text == null) { text = this.default_text; }
469
+ if (text === this.default_text) {
470
+ this.selected_item.addClass("chosen-default");
471
+ } else {
472
+ this.single_deselect_control_build();
473
+ this.selected_item.removeClass("chosen-default");
474
+ }
475
+
476
+ return this.selected_item.find("span").html(text);
477
+ }
478
+
479
+ result_deselect(pos) {
480
+ const result_data = this.results_data[pos];
481
+
482
+ if (!this.form_field.options[result_data.options_index].disabled) {
483
+ result_data.selected = false;
484
+
485
+ this.form_field.options[result_data.options_index].selected = false;
486
+ this.selected_option_count = null;
487
+
488
+ this.result_clear_highlight();
489
+ if (this.results_showing) { this.winnow_results(); }
490
+
491
+ this.trigger_form_field_change({deselected: this.form_field.options[result_data.options_index].value});
492
+ this.search_field_scale();
493
+
494
+ return true;
495
+ } else {
496
+ return false;
497
+ }
498
+ }
499
+
500
+ single_deselect_control_build() {
501
+ if (!this.allow_single_deselect) { return; }
502
+ if (!this.selected_item.find("abbr").length) { this.selected_item.find("span").first().after("<abbr class=\"search-choice-close\"></abbr>"); }
503
+ return this.selected_item.addClass("chosen-single-with-deselect");
504
+ }
505
+
506
+ get_search_field_value() {
507
+ return this.search_field.val();
508
+ }
509
+
510
+ get_search_text() {
511
+ return $.trim(this.get_search_field_value());
512
+ }
513
+
514
+ escape_html(text) {
515
+ return $('<div/>').text(text).html();
516
+ }
517
+
518
+ winnow_results_set_highlight() {
519
+ const selected_results = !this.is_multiple ? this.search_results.find(".result-selected.active-result") : [];
520
+ const do_high = selected_results.length ? selected_results.first() : this.search_results.find(".active-result").first();
521
+
522
+ if (do_high != null) { return this.result_do_highlight(do_high); }
523
+ }
524
+
525
+ no_results(terms) {
526
+ const no_results_html = this.get_no_results_html(terms);
527
+ this.search_results.append(no_results_html);
528
+ return this.form_field_jq.trigger("chosen:no_results", {chosen:this});
529
+ }
530
+
531
+ no_results_clear() {
532
+ return this.search_results.find(".no-results").remove();
533
+ }
534
+
535
+ keydown_arrow() {
536
+ if (this.results_showing && this.result_highlight) {
537
+ const next_sib = this.result_highlight.nextAll("li.active-result").first();
538
+ if (next_sib) { return this.result_do_highlight(next_sib); }
539
+ } else {
540
+ return this.results_show();
541
+ }
542
+ }
543
+
544
+ keyup_arrow() {
545
+ if (!this.results_showing && !this.is_multiple) {
546
+ return this.results_show();
547
+ } else if (this.result_highlight) {
548
+ const prev_sibs = this.result_highlight.prevAll("li.active-result");
549
+
550
+ if (prev_sibs.length) {
551
+ return this.result_do_highlight(prev_sibs.first());
552
+ } else {
553
+ if (this.choices_count() > 0) { this.results_hide(); }
554
+ return this.result_clear_highlight();
555
+ }
556
+ }
557
+ }
558
+
559
+ keydown_backstroke() {
560
+ if (this.pending_backstroke) {
561
+ this.choice_destroy(this.pending_backstroke.find("a").first());
562
+ return this.clear_backstroke();
563
+ } else {
564
+ const next_available_destroy = this.search_container.siblings("li.search-choice").last();
565
+ if (next_available_destroy.length && !next_available_destroy.hasClass("search-choice-disabled")) {
566
+ this.pending_backstroke = next_available_destroy;
567
+ if (this.single_backstroke_delete) {
568
+ return this.keydown_backstroke();
569
+ } else {
570
+ return this.pending_backstroke.addClass("search-choice-focus");
571
+ }
572
+ }
573
+ }
574
+ }
575
+
576
+ clear_backstroke() {
577
+ if (this.pending_backstroke) { this.pending_backstroke.removeClass("search-choice-focus"); }
578
+ return this.pending_backstroke = null;
579
+ }
580
+
581
+ search_field_scale() {
582
+ if (!this.is_multiple) { return; }
583
+
584
+ const style_block = {
585
+ position: 'absolute',
586
+ left: '-1000px',
587
+ top: '-1000px',
588
+ display: 'none',
589
+ whiteSpace: 'pre'
590
+ };
591
+
592
+ const styles = ['fontSize', 'fontStyle', 'fontWeight', 'fontFamily', 'lineHeight', 'textTransform', 'letterSpacing'];
593
+
594
+ for (var style of Array.from(styles)) {
595
+ style_block[style] = this.search_field.css(style);
596
+ }
597
+
598
+ const div = $('<div />').css(style_block);
599
+ div.text(this.get_search_field_value());
600
+ $('body').append(div);
601
+
602
+ let width = div.width() + 25;
603
+ div.remove();
604
+
605
+ if (this.container.is(':visible')) {
606
+ width = Math.min(this.container.outerWidth() - 10, width);
607
+ }
608
+
609
+ return this.search_field.width(width);
610
+ }
611
+
612
+ trigger_form_field_change(extra) {
613
+ this.form_field_jq.trigger("input", extra);
614
+ return this.form_field_jq.trigger("change", extra);
615
+ }
616
+ }