PageSourceSearch

https://www.anmvioggi.it/plugins/system/helixultimate/assets/js/chosen.jquery.js

js anmvioggi.it collected 2026-10-02 04:23:54 UTC 47,262 bytes, 1,355 lines download raw bytes

vendor: 35,707 bytes, lines 1-1015
1(function() {
2  var $, AbstractChosen, Chosen, SelectParser,
3    bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
4    extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
5    hasProp = {}.hasOwnProperty;
6
7  SelectParser = (function() {
8    function SelectParser() {
9      this.options_index = 0;
10      this.parsed = [];
11    }
12
13    SelectParser.prototype.add_node = function(child) {
14      if (child.nodeName.toUpperCase() === "OPTGROUP") {
15        return this.add_group(child);
16      } else {
17        return this.add_option(child);
18      }
19    };
20
21    SelectParser.prototype.add_group = function(group) {
22      var group_position, i, len, option, ref, results1;
23      group_position = this.parsed.length;
24      this.parsed.push({
25        array_index: group_position,
26        group: true,
27        label: group.label,
28        title: group.title ? group.title : void 0,
29        children: 0,
30        disabled: group.disabled,
31        classes: group.className
32      });
33      ref = group.childNodes;
34      results1 = [];
35      for (i = 0, len = ref.length; i < len; i++) {
36        option = ref[i];
37        results1.push(this.add_option(option, group_position, group.disabled));
38      }
39      return results1;
40    };
41
42    SelectParser.prototype.add_option = function(option, group_position, group_disabled) {
43      if (option.nodeName.toUpperCase() === "OPTION") {
44        if (option.text !== "") {
45          if (group_position != null) {
46            this.parsed[group_position].children += 1;
47          }
48          this.parsed.push({
49            array_index: this.parsed.length,
50            options_index: this.options_index,
51            value: option.value,
52            text: option.text,
53            html: option.innerHTML,
54            title: option.title ? option.title : void 0,
55            selected: option.selected,
56            disabled: group_disabled === true ? group_disabled : option.disabled,
57            group_array_index: group_position,
58            group_label: group_position != null ? this.parsed[group_position].label : null,
59            classes: option.className,
60            style: option.style.cssText
61          });
62        } else {
63          this.parsed.push({
64            array_index: this.parsed.length,
65            options_index: this.options_index,
66            empty: true
67          });
68        }
69        return this.options_index += 1;
70      }
71    };
72
73    return SelectParser;
74
75  })();
76
77  SelectParser.select_to_array = function(select) {
78    var child, i, len, parser, ref;
79    parser = new SelectParser();
80    ref = select.childNodes;
81    for (i = 0, len = ref.length; i < len; i++) {
82      child = ref[i];
83      parser.add_node(child);
84    }
85    return parser.parsed;
86  };
87
88  AbstractChosen = (function() {
89    function AbstractChosen(form_field, options1) {
90      this.form_field = form_field;
91      this.options = options1 != null ? options1 : {};
92      this.label_click_handler = bind(this.label_click_handler, this);
93      if (!AbstractChosen.browser_is_supported()) {
94        return;
95      }
96      this.is_multiple = this.form_field.multiple;
97      this.set_default_text();
98      this.set_default_values();
99      this.setup();
100      this.set_up_html();
101      this.register_observers();
102      this.on_ready();
103    }
104
105    AbstractChosen.prototype.set_default_values = function() {
106      this.click_test_action = (function(_this) {
107        return function(evt) {
108          return _this.test_active_click(evt);
109        };
110      })(this);
111      this.activate_action = (function(_this) {
112        return function(evt) {
113          return _this.activate_field(evt);
114        };
115      })(this);
116      this.active_field = false;
117      this.mouse_on_container = false;
118      this.results_showing = false;
119      this.result_highlighted = null;
120      this.is_rtl = this.options.rtl || /\bchosen-rtl\b/.test(this.form_field.className);
121      this.allow_single_deselect = (this.options.allow_single_deselect != null) && (this.form_field.options[0] != null) && this.form_field.options[0].text === "" ? this.options.allow_single_deselect : false;
122      this.disable_search_threshold = this.options.disable_search_threshold || 0;
123      this.disable_search = this.options.disable_search || false;
124      this.enable_split_word_search = this.options.enable_split_word_search != null ? this.options.enable_split_word_search : true;
125      this.group_search = this.options.group_search != null ? this.options.group_search : true;
126      this.search_contains = this.options.search_contains || false;
127      this.single_backstroke_delete = this.options.single_backstroke_delete != null ? this.options.single_backstroke_delete : true;
128      this.max_selected_options = this.options.max_selected_options || Infinity;
129      this.inherit_select_classes = this.options.inherit_select_classes || false;
130      this.display_selected_options = this.options.display_selected_options != null ? this.options.display_selected_options : true;
131      this.display_disabled_options = this.options.display_disabled_options != null ? this.options.display_disabled_options : true;
132      this.include_group_label_in_selected = this.options.include_group_label_in_selected || false;
133      this.max_shown_results = this.options.max_shown_results || Number.POSITIVE_INFINITY;
134      this.case_sensitive_search = this.options.case_sensitive_search || false;
135      return this.hide_results_on_select = this.options.hide_results_on_select != null ? this.options.hide_results_on_select : true;
136    };
137
138    AbstractChosen.prototype.set_default_text = function() {
139      if (this.form_field.getAttribute("data-placeholder")) {
140        this.default_text = this.form_field.getAttribute("data-placeholder");
141      } else if (this.is_multiple) {
142        this.default_text = this.options.placeholder_text_multiple || this.options.placeholder_text || AbstractChosen.default_multiple_text;
143      } else {
144        this.default_text = this.options.placeholder_text_single || this.options.placeholder_text || AbstractChosen.default_single_text;
145      }
146      this.default_text = this.escape_html(this.default_text);
147      return this.results_none_found = this.form_field.getAttribute("data-no_results_text") || this.options.no_results_text || AbstractChosen.default_no_result_text;
148    };
149
150    AbstractChosen.prototype.choice_label = function(item) {
151      if (this.include_group_label_in_selected && (item.group_label != null)) {
152        return "<b class='group-name'>" + (this.escape_html(item.group_label)) + "</b>" + item.html;
153      } else {
154        return item.html;
155      }
156    };
157
158    AbstractChosen.prototype.mouse_enter = function() {
159      return this.mouse_on_container = true;
160    };
161
162    AbstractChosen.prototype.mouse_leave = function() {
163      return this.mouse_on_container = false;
164    };
165
166    AbstractChosen.prototype.input_focus = function(evt) {
167      if (this.is_multiple) {
168        if (!this.active_field) {
169          return setTimeout(((function(_this) {
170            return function() {
171              return _this.container_mousedown();
172            };
173          })(this)), 50);
174        }
175      } else {
176        if (!this.active_field) {
177          return this.activate_field();
178        }
179      }
180    };
181
182    AbstractChosen.prototype.input_blur = function(evt) {
183      if (!this.mouse_on_container) {
184        this.active_field = false;
185        return setTimeout(((function(_this) {
186          return function() {
187            return _this.blur_test();
188          };
189        })(this)), 100);
190      }
191    };
192
193    AbstractChosen.prototype.label_click_handler = function(evt) {
194      if (this.is_multiple) {
195        return this.container_mousedown(evt);
196      } else {
197        return this.activate_field();
198      }
199    };
200
201    AbstractChosen.prototype.results_option_build = function(options) {
202      var content, data, data_content, i, len, ref, shown_results;
203      content = '';
204      shown_results = 0;
205      ref = this.results_data;
206      for (i = 0, len = ref.length; i < len; i++) {
207        data = ref[i];
208        data_content = '';
209        if (data.group) {
210          data_content = this.result_add_group(data);
211        } else {
212          data_content = this.result_add_option(data);
213        }
214        if (data_content !== '') {
215          shown_results++;
216          content += data_content;
217        }
218        if (options != null ? options.first : void 0) {
219          if (data.selected && this.is_multiple) {
220            this.choice_build(data);
221          } else if (data.selected && !this.is_multiple) {
222            this.single_set_selected_text(this.choice_label(data));
223          }
224        }
225        if (shown_results >= this.max_shown_results) {
226          break;
227        }
228      }
229      return content;
230    };
231
232    AbstractChosen.prototype.result_add_option = function(option) {
233      var classes, option_el;
234      if (!option.search_match) {
235        return '';
236      }
237      if (!this.include_option_in_results(option)) {
238        return '';
239      }
240      classes = [];
241      if (!option.disabled && !(option.selected && this.is_multiple)) {
242        classes.push("active-result");
243      }
244      if (option.disabled && !(option.selected && this.is_multiple)) {
245        classes.push("disabled-result");
246      }
247      if (option.selected) {
248        classes.push("result-selected");
249      }
250      if (option.group_array_index != null) {
251        classes.push("group-option");
252      }
253      if (option.classes !== "") {
254        classes.push(option.classes);
255      }
256      option_el = document.createElement("li");
257      option_el.className = classes.join(" ");
258      if (option.style) {
259        option_el.style.cssText = option.style;
260      }
261      option_el.setAttribute("data-option-array-index", option.array_index);
262      option_el.innerHTML = option.highlighted_html || option.html;
263      if (option.title) {
264        option_el.title = option.title;
265      }
266      return this.outerHTML(option_el);
267    };
268
269    AbstractChosen.prototype.result_add_group = function(group) {
270      var classes, group_el;
271      if (!(group.search_match || group.group_match)) {
272        return '';
273      }
274      if (!(group.active_options > 0)) {
275        return '';
276      }
277      classes = [];
278      classes.push("group-result");
279      if (group.classes) {
280        classes.push(group.classes);
281      }
282      group_el = document.createElement("li");
283      group_el.className = classes.join(" ");
284      group_el.innerHTML = group.highlighted_html || this.escape_html(group.label);
285      if (group.title) {
286        group_el.title = group.title;
287      }
288      return this.outerHTML(group_el);
289    };
290
291    AbstractChosen.prototype.results_update_field = function() {
292      this.set_default_text();
293      if (!this.is_multiple) {
294        this.results_reset_cleanup();
295      }
296      this.result_clear_highlight();
297      this.results_build();
298      if (this.results_showing) {
299        return this.winnow_results();
300      }
301    };
302
303    AbstractChosen.prototype.reset_single_select_options = function() {
304      var i, len, ref, result, results1;
305      ref = this.results_data;
306      results1 = [];
307      for (i = 0, len = ref.length; i < len; i++) {
308        result = ref[i];
309        if (result.selected) {
310          results1.push(result.selected = false);
311        } else {
312          results1.push(void 0);
313        }
314      }
315      return results1;
316    };
317
318    AbstractChosen.prototype.results_toggle = function() {
319      if (this.results_showing) {
320        return this.results_hide();
321      } else {
322        return this.results_show();
323      }
324    };
325
326    AbstractChosen.prototype.results_search = function(evt) {
327      if (this.results_showing) {
328        return this.winnow_results();
329      } else {
330        return this.results_show();
331      }
332    };
333
334    AbstractChosen.prototype.winnow_results = function(options) {
335      var escapedQuery, fix, i, len, option, prefix, query, ref, regex, results, results_group, search_match, startpos, suffix, text;
336      this.no_results_clear();
337      results = 0;
338      query = this.get_search_text();
339      escapedQuery = query.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
340      regex = this.get_search_regex(escapedQuery);
341      ref = this.results_data;
342      for (i = 0, len = ref.length; i < len; i++) {
343        option = ref[i];
344        option.search_match = false;
345        results_group = null;
346        search_match = null;
347        option.highlighted_html = '';
348        if (this.include_option_in_results(option)) {
349          if (option.group) {
350            option.group_match = false;
351            option.active_options = 0;
352          }
353          if ((option.group_array_index != null) && this.results_data[option.group_array_index]) {
354            results_group = this.results_data[option.group_array_index];
355            if (results_group.active_options === 0 && results_group.search_match) {
356              results += 1;
357            }
358            results_group.active_options += 1;
359          }
360          text = option.group ? option.label : option.text;
361          if (!(option.group && !this.group_search)) {
362            search_match = this.search_string_match(text, regex);
363            option.search_match = search_match != null;
364            if (option.search_match && !option.group) {
365              results += 1;
366            }
367            if (option.search_match) {
368              if (query.length) {
369                startpos = search_match.index;
370                prefix = text.slice(0, startpos);
371                fix = text.slice(startpos, startpos + query.length);
372                suffix = text.slice(startpos + query.length);
373                option.highlighted_html = (this.escape_html(prefix)) + "<em>" + (this.escape_html(fix)) + "</em>" + (this.escape_html(suffix));
374              }
375              if (results_group != null) {
376                results_group.group_match = true;
377              }
378            } else if ((option.group_array_index != null) && this.results_data[option.group_array_index].search_match) {
379              option.search_match = true;
380            }
381          }
382        }
383      }
384      this.result_clear_highlight();
385      if (results < 1 && query.length) {
386        this.update_results_content("");
387        return this.no_results(query);
388      } else {
389        this.update_results_content(this.results_option_build());
390        if (!(options != null ? options.skip_highlight : void 0)) {
391          return this.winnow_results_set_highlight();
392        }
393      }
394    };
395
396    AbstractChosen.prototype.get_search_regex = function(escaped_search_string) {
397      var regex_flag, regex_string;
398      regex_string = this.search_contains ? escaped_search_string : "(^|\\s|\\b)" + escaped_search_string + "[^\\s]*";
399      if (!(this.enable_split_word_search || this.search_contains)) {
400        regex_string = "^" + regex_string;
401      }
402      regex_flag = this.case_sensitive_search ? "" : "i";
403      return new RegExp(regex_string, regex_flag);
404    };
405
406    AbstractChosen.prototype.search_string_match = function(search_string, regex) {
407      var match;
408      match = regex.exec(search_string);
409      if (!this.search_contains && (match != null ? match[1] : void 0)) {
410        match.index += 1;
411      }
412      return match;
413    };
414
415    AbstractChosen.prototype.choices_count = function() {
416      var i, len, option, ref;
417      if (this.selected_option_count != null) {
418        return this.selected_option_count;
419      }
420      this.selected_option_count = 0;
421      ref = this.form_field.options;
422      for (i = 0, len = ref.length; i < len; i++) {
423        option = ref[i];
424        if (option.selected) {
425          this.selected_option_count += 1;
426        }
427      }
428      return this.selected_option_count;
429    };
430
431    AbstractChosen.prototype.choices_click = function(evt) {
432      evt.preventDefault();
433      this.activate_field();
434      if (!(this.results_showing || this.is_disabled)) {
435        return this.results_show();
436      }
437    };
438
439    AbstractChosen.prototype.keydown_checker = function(evt) {
440      var ref, stroke;
441      stroke = (ref = evt.which) != null ? ref : evt.keyCode;
442      this.search_field_scale();
443      if (stroke !== 8 && this.pending_backstroke) {
444        this.clear_backstroke();
445      }
446      switch (stroke) {
447        case 8:
448          this.backstroke_length = this.get_search_field_value().length;
449          break;
450        case 9:
451          if (this.results_showing && !this.is_multiple) {
452            this.result_select(evt);
453          }
454          this.mouse_on_container = false;
455          break;
456        case 13:
457          if (this.results_showing) {
458            evt.preventDefault();
459          }
460          break;
461        case 27:
462          if (this.results_showing) {
463            evt.preventDefault();
464          }
465          break;
466        case 32:
467          if (this.disable_search) {
468            evt.preventDefault();
469          }
470          break;
471        case 38:
472          evt.preventDefault();
473          this.keyup_arrow();
474          break;
475        case 40:
476          evt.preventDefault();
477          this.keydown_arrow();
478          break;
479      }
480    };
481
482    AbstractChosen.prototype.keyup_checker = function(evt) {
483      var ref, stroke;
484      stroke = (ref = evt.which) != null ? ref : evt.keyCode;
485      this.search_field_scale();
486      switch (stroke) {
487        case 8:
488          if (this.is_multiple && this.backstroke_length < 1 && this.choices_count() > 0) {
489            this.keydown_backstroke();
490          } else if (!this.pending_backstroke) {
491            this.result_clear_highlight();
492            this.results_search();
493          }
494          break;
495        case 13:
496          evt.preventDefault();
497          if (this.results_showing) {
498            this.result_select(evt);
499          }
500          break;
501        case 27:
502          if (this.results_showing) {
503            this.results_hide();
504          }
505          break;
506        case 9:
507        case 16:
508        case 17:
509        case 18:
510        case 38:
511        case 40:
512        case 91:
513          break;
514        default:
515          this.results_search();
516          break;
517      }
518    };
519
520    AbstractChosen.prototype.clipboard_event_checker = function(evt) {
521      if (this.is_disabled) {
522        return;
523      }
524      return setTimeout(((function(_this) {
525        return function() {
526          return _this.results_search();
527        };
528      })(this)), 50);
529    };
530
531    AbstractChosen.prototype.container_width = function() {
532      if (this.options.width != null) {
533        return this.options.width;
534      } else {
535        return this.form_field.offsetWidth + "px";
536      }
537    };
538
539    AbstractChosen.prototype.include_option_in_results = function(option) {
540      if (this.is_multiple && (!this.display_selected_options && option.selected)) {
541        return false;
542      }
543      if (!this.display_disabled_options && option.disabled) {
544        return false;
545      }
546      if (option.empty) {
547        return false;
548      }
549      return true;
550    };
551
552    AbstractChosen.prototype.search_results_touchstart = function(evt) {
553      this.touch_started = true;
554      return this.search_results_mouseover(evt);
555    };
556
557    AbstractChosen.prototype.search_results_touchmove = function(evt) {
558      this.touch_started = false;
559      return this.search_results_mouseout(evt);
560    };
561
562    AbstractChosen.prototype.search_results_touchend = function(evt) {
563      if (this.touch_started) {
564        return this.search_results_mouseup(evt);
565      }
566    };
567
568    AbstractChosen.prototype.outerHTML = function(element) {
569      var tmp;
570      if (element.outerHTML) {
571        return element.outerHTML;
572      }
573      tmp = document.createElement("div");
574      tmp.appendChild(element);
575      return tmp.innerHTML;
576    };
577
578    AbstractChosen.prototype.get_single_html = function() {
579      return "<a class=\"chosen-single chosen-default\">\n  <span>" + this.default_text + "</span>\n  <div><b></b></div>\n</a>\n<div class=\"chosen-drop\">\n  <div class=\"chosen-search\">\n    <input class=\"chosen-search-input\" type=\"text\" autocomplete=\"off\" />\n  </div>\n  <ul class=\"chosen-results\"></ul>\n</div>";
580    };
581
582    AbstractChosen.prototype.get_multi_html = function() {
583      return "<ul class=\"chosen-choices\">\n  <li class=\"search-field\">\n    <input class=\"chosen-search-input\" type=\"text\" autocomplete=\"off\" value=\"" + this.default_text + "\" />\n  </li>\n</ul>\n<div class=\"chosen-drop\">\n  <ul class=\"chosen-results\"></ul>\n</div>";
584    };
585
586    AbstractChosen.prototype.get_no_results_html = function(terms) {
587      return "<li class=\"no-results\">\n  " + this.results_none_found + " <span>" + (this.escape_html(terms)) + "</span>\n</li>";
588    };
589
590    AbstractChosen.browser_is_supported = function() {
591      if ("Microsoft Internet Explorer" === window.navigator.appName) {
592        return document.documentMode >= 8;
593      }
594      if (/iP(od|hone)/i.test(window.navigator.userAgent) || /IEMobile/i.test(window.navigator.userAgent) || /Windows Phone/i.test(window.navigator.userAgent) || /BlackBerry/i.test(window.navigator.userAgent) || /BB10/i.test(window.navigator.userAgent) || /Android.*Mobile/i.test(window.navigator.userAgent)) {
595        return false;
596      }
597      return true;
598    };
599
600    AbstractChosen.default_multiple_text = "Select Some Options";
601
602    AbstractChosen.default_single_text = "Select an Option";
603
604    AbstractChosen.default_no_result_text = "No results match";
605
606    return AbstractChosen;
607
608  })();
609
610  $ = jQuery;
611
612  $.fn.extend({
613    chosen: function(options) {
614      if (!AbstractChosen.browser_is_supported()) {
615        return this;
616      }
617      return this.each(function(input_field) {
618        var $this, chosen;
619        $this = $(this);
620        chosen = $this.data('chosen');
621        if (options === 'destroy') {
622          if (chosen instanceof Chosen) {
623            chosen.destroy();
624          }
625          return;
626        }
627        if (!(chosen instanceof Chosen)) {
628          $this.data('chosen', new Chosen(this, options));
629        }
630      });
631    }
632  });
633
634  Chosen = (function(superClass) {
635    extend(Chosen, superClass);
636
637    function Chosen() {
638      return Chosen.__super__.constructor.apply(this, arguments);
639    }
640
641    Chosen.prototype.setup = function() {
642      this.form_field_jq = $(this.form_field);
643      return this.current_selectedIndex = this.form_field.selectedIndex;
644    };
645
646    Chosen.prototype.set_up_html = function() {
647      var container_classes, container_props;
648      container_classes = ["chosen-container"];
649      container_classes.push("chosen-container-" + (this.is_multiple ? "multi" : "single"));
650      if (this.inherit_select_classes && this.form_field.className) {
651        container_classes.push(this.form_field.className);
652      }
653      if (this.is_rtl) {
654        container_classes.push("chosen-rtl");
655      }
656      container_props = {
657        'class': container_classes.join(' '),
658        'title': this.form_field.title
659      };
660      if (this.form_field.id.length) {
661        container_props.id = this.form_field.id.replace(/[^\w]/g, '_') + "_chosen";
662      }
663      this.container = $("<div />", container_props);
664      this.container.width(this.container_width());
665      if (this.is_multiple) {
666        this.container.html(this.get_multi_html());
667      } else {
668        this.container.html(this.get_single_html());
669      }
670      this.form_field_jq.hide().after(this.container);
671      this.dropdown = this.container.find('div.chosen-drop').first();
672      this.search_field = this.container.find('input').first();
673      this.search_results = this.container.find('ul.chosen-results').first();
674      this.search_field_scale();
675      this.search_no_results = this.container.find('li.no-results').first();
676      if (this.is_multiple) {
677        this.search_choices = this.container.find('ul.chosen-choices').first();
678        this.search_container = this.container.find('li.search-field').first();
679      } else {
680        this.search_container = this.container.find('div.chosen-search').first();
681        this.selected_item = this.container.find('.chosen-single').first();
682      }
683      this.results_build();
684      this.set_tab_index();
685      return this.set_label_behavior();
686    };
687
688    Chosen.prototype.on_ready = function() {
689      return this.form_field_jq.trigger("chosen:ready", {
690        chosen: this
691      });
692    };
693
694    Chosen.prototype.register_observers = function() {
695      this.container.on('touchstart.chosen', (function(_this) {
696        return function(evt) {
697          _this.container_mousedown(evt);
698        };
699      })(this));
700      this.container.on('touchend.chosen', (function(_this) {
701        return function(evt) {
702          _this.container_mouseup(evt);
703        };
704      })(this));
705      this.container.on('mousedown.chosen', (function(_this) {
706        return function(evt) {
707          _this.container_mousedown(evt);
708        };
709      })(this));
710      this.container.on('mouseup.chosen', (function(_this) {
711        return function(evt) {
712          _this.container_mouseup(evt);
713        };
714      })(this));
715      this.container.on('mouseenter.chosen', (function(_this) {
716        return function(evt) {
717          _this.mouse_enter(evt);
718        };
719      })(this));
720      this.container.on('mouseleave.chosen', (function(_this) {
721        return function(evt) {
722          _this.mouse_leave(evt);
723        };
724      })(this));
725      this.search_results.on('mouseup.chosen', (function(_this) {
726        return function(evt) {
727          _this.search_results_mouseup(evt);
728        };
729      })(this));
730      this.search_results.on('mouseover.chosen', (function(_this) {
731        return function(evt) {
732          _this.search_results_mouseover(evt);
733        };
734      })(this));
735      this.search_results.on('mouseout.chosen', (function(_this) {
736        return function(evt) {
737          _this.search_results_mouseout(evt);
738        };
739      })(this));
740      this.search_results.on('mousewheel.chosen DOMMouseScroll.chosen', (function(_this) {
741        return function(evt) {
742          _this.search_results_mousewheel(evt);
743        };
744      })(this));
745      this.search_results.on('touchstart.chosen', (function(_this) {
746        return function(evt) {
747          _this.search_results_touchstart(evt);
748        };
749      })(this));
750      this.search_results.on('touchmove.chosen', (function(_this) {
751        return function(evt) {
752          _this.search_results_touchmove(evt);
753        };
754      })(this));
755      this.search_results.on('touchend.chosen', (function(_this) {
756        return function(evt) {
757          _this.search_results_touchend(evt);
758        };
759      })(this));
760      this.form_field_jq.on("chosen:updated.chosen", (function(_this) {
761        return function(evt) {
762          _this.results_update_field(evt);
763        };
764      })(this));
765      this.form_field_jq.on("chosen:activate.chosen", (function(_this) {
766        return function(evt) {
767          _this.activate_field(evt);
768        };
769      })(this));
770      this.form_field_jq.on("chosen:open.chosen", (function(_this) {
771        return function(evt) {
772          _this.container_mousedown(evt);
773        };
774      })(this));
775      this.form_field_jq.on("chosen:close.chosen", (function(_this) {
776        return function(evt) {
777          _this.close_field(evt);
778        };
779      })(this));
780      this.search_field.on('blur.chosen', (function(_this) {
781        return function(evt) {
782          _this.input_blur(evt);
783        };
784      })(this));
785      this.search_field.on('keyup.chosen', (function(_this) {
786        return function(evt) {
787          _this.keyup_checker(evt);
788        };
789      })(this));
790      this.search_field.on('keydown.chosen', (function(_this) {
791        return function(evt) {
792          _this.keydown_checker(evt);
793        };
794      })(this));
795      this.search_field.on('focus.chosen', (function(_this) {
796        return function(evt) {
797          _this.input_focus(evt);
798        };
799      })(this));
800      this.search_field.on('cut.chosen', (function(_this) {
801        return function(evt) {
802          _this.clipboard_event_checker(evt);
803        };
804      })(this));
805      this.search_field.on('paste.chosen', (function(_this) {
806        return function(evt) {
807          _this.clipboard_event_checker(evt);
808        };
809      })(this));
810      if (this.is_multiple) {
811        return this.search_choices.on('click.chosen', (function(_this) {
812          return function(evt) {
813            _this.choices_click(evt);
814          };
815        })(this));
816      } else {
817        return this.container.on('click.chosen', function(evt) {
818          evt.preventDefault();
819        });
820      }
821    };
822
823    Chosen.prototype.destroy = function() {
824      $(this.container[0].ownerDocument).off('click.chosen', this.click_test_action);
825      if (this.form_field_label.length > 0) {
826        this.form_field_label.off('click.chosen');
827      }
828      if (this.search_field[0].tabIndex) {
829        this.form_field_jq[0].tabIndex = this.search_field[0].tabIndex;
830      }
831      this.container.remove();
832      this.form_field_jq.removeData('chosen');
833      return this.form_field_jq.show();
834    };
835
836    Chosen.prototype.search_field_disabled = function() {
837      this.is_disabled = this.form_field.disabled || this.form_field_jq.parents('fieldset').is(':disabled');
838      this.container.toggleClass('chosen-disabled', this.is_disabled);
839      this.search_field[0].disabled = this.is_disabled;
840      if (!this.is_multiple) {
841        this.selected_item.off('focus.chosen', this.activate_field);
842      }
843      if (this.is_disabled) {
844        return this.close_field();
845      } else if (!this.is_multiple) {
846        return this.selected_item.on('focus.chosen', this.activate_field);
847      }
848    };
849
850    Chosen.prototype.container_mousedown = function(evt) {
851      var ref;
852      if (this.is_disabled) {
853        return;
854      }
855      if (evt && ((ref = evt.type) === 'mousedown' || ref === 'touchstart') && !this.results_showing) {
856        evt.preventDefault();
857      }
858      if (!((evt != null) && ($(evt.target)).hasClass("search-choice-close"))) {
859        if (!this.active_field) {
860          if (this.is_multiple) {
861            this.search_field.val("");
862          }
863          $(this.container[0].ownerDocument).on('click.chosen', this.click_test_action);
864          this.results_show();
865        } else if (!this.is_multiple && evt && (($(evt.target)[0] === this.selected_item[0]) || $(evt.target).parents("a.chosen-single").length)) {
866          evt.preventDefault();
867          this.results_toggle();
868        }
869        return this.activate_field();
870      }
871    };
872
873    Chosen.prototype.container_mouseup = function(evt) {
874      if (evt.target.nodeName === "ABBR" && !this.is_disabled) {
875        return this.results_reset(evt);
876      }
877    };
878
879    Chosen.prototype.search_results_mousewheel = function(evt) {
880      var delta;
881      if (evt.originalEvent) {
882        delta = evt.originalEvent.deltaY || -evt.originalEvent.wheelDelta || evt.originalEvent.detail;
883      }
884      if (delta != null) {
885        evt.preventDefault();
886        if (evt.type === 'DOMMouseScroll') {
887          delta = delta * 40;
888        }
889        return this.search_results.scrollTop(delta + this.search_results.scrollTop());
890      }
891    };
892
893    Chosen.prototype.blur_test = function(evt) {
894      if (!this.active_field && this.container.hasClass("chosen-container-active")) {
895        return this.close_field();
896      }
897    };
898
899    Chosen.prototype.close_field = function() {
900      $(this.container[0].ownerDocument).off("click.chosen", this.click_test_action);
901      this.active_field = false;
902      this.results_hide();
903      this.container.removeClass("chosen-container-active");
904      this.clear_backstroke();
905      this.show_search_field_default();
906      this.search_field_scale();
907      return this.search_field.blur();
908    };
909
910    Chosen.prototype.activate_field = function() {
911      if (this.is_disabled) {
912        return;
913      }
914      this.container.addClass("chosen-container-active");
915      this.active_field = true;
916      this.search_field.val(this.search_field.val());
917      return this.search_field.focus();
918    };
919
920    Chosen.prototype.test_active_click = function(evt) {
921      var active_container;
922      active_container = $(evt.target).closest('.chosen-container');
923      if (active_container.length && this.container[0] === active_container[0]) {
924        return this.active_field = true;
925      } else {
926        return this.close_field();
927      }
928    };
929
930    Chosen.prototype.results_build = function() {
931      this.parsing = true;
932      this.selected_option_count = null;
933      this.results_data = SelectParser.select_to_array(this.form_field);
934      if (this.is_multiple) {
935        this.search_choices.find("li.search-choice").remove();
936      } else {
937        this.single_set_selected_text();
938        if (this.disable_search || this.form_field.options.length <= this.disable_search_threshold) {
939          this.search_field[0].readOnly = true;
940          this.container.addClass("chosen-container-single-nosearch");
941        } else {
942          this.search_field[0].readOnly = false;
943          this.container.removeClass("chosen-container-single-nosearch");
944        }
945      }
946      this.update_results_content(this.results_option_build({
947        first: true
948      }));
949      this.search_field_disabled();
950      this.show_search_field_default();
951      this.search_field_scale();
952      return this.parsing = false;
953    };
954
955    Chosen.prototype.result_do_highlight = function(el) {
956      var high_bottom, high_top, maxHeight, visible_bottom, visible_top;
957      if (el.length) {
958        this.result_clear_highlight();
959        this.result_highlight = el;
960        this.result_highlight.addClass("highlighted");
961        maxHeight = parseInt(this.search_results.css("maxHeight"), 10);
962        visible_top = this.search_results.scrollTop();
963        visible_bottom = maxHeight + visible_top;
964        high_top = this.result_highlight.position().top + this.search_results.scrollTop();
965        high_bottom = high_top + this.result_highlight.outerHeight();
966        if (high_bottom >= visible_bottom) {
967          return this.search_results.scrollTop((high_bottom - maxHeight) > 0 ? high_bottom - maxHeight : 0);
968        } else if (high_top < visible_top) {
969          return this.search_results.scrollTop(high_top);
970        }
971      }
972    };
973
974    Chosen.prototype.result_clear_highlight = function() {
975      if (this.result_highlight) {
976        this.result_highlight.removeClass("highlighted");
977      }
978      return this.result_highlight = null;
979    };
980
981    Chosen.prototype.results_show = function() {
982      if (this.is_multiple && this.max_selected_options <= this.choices_count()) {
983        this.form_field_jq.trigger("chosen:maxselected", {
984          chosen: this
985        });
986        return false;
987      }
988      this.container.addClass("chosen-with-drop");
989      this.results_showing = true;
990      this.search_field.focus();
991      this.search_field.val(this.get_search_field_value());
992      this.winnow_results();
993      return this.form_field_jq.trigger("chosen:showing_dropdown", {
994        chosen: this
995      });
996    };
997
998    Chosen.prototype.update_results_content = function(content) {
999      return this.search_results.html(content);
1000    };
1001
1002    Chosen.prototype.results_hide = function() {
1003      if (this.results_showing) {
1004        this.result_clear_highlight();
1005        this.container.removeClass("chosen-with-drop");
1006        this.form_field_jq.trigger("chosen:hiding_dropdown", {
1007          chosen: this
1008        });
1009      }
1010      return this.results_showing = false;
1011    };
1012
1013    Chosen.prototype.set_tab_index = function(el) {
1014      var ti;
1015      
1015ti = this.form_field.tabIndex;
1016
1017      if (ti === -1) {
1018        ti = -1;
1019      } else {
1020        ti = 0;   
1021      }
1022    
1023      this.form_field.tabIndex = -1;
1024      this.search_field[0].tabIndex = ti;
1025      return this.search_field[0].tabIndex;
vendor: 11,227 bytes, lines 1025-1352
1025
1026    };
1027
1028    Chosen.prototype.set_label_behavior = function() {
1029      this.form_field_label = this.form_field_jq.parents("label");
1030      if (!this.form_field_label.length && this.form_field.id.length) {
1031        this.form_field_label = $("label[for='" + this.form_field.id + "']");
1032      }
1033      if (this.form_field_label.length > 0) {
1034        return this.form_field_label.on('click.chosen', this.label_click_handler);
1035      }
1036    };
1037
1038    Chosen.prototype.show_search_field_default = function() {
1039      if (this.is_multiple && this.choices_count() < 1 && !this.active_field) {
1040        this.search_field.val(this.default_text);
1041        return this.search_field.addClass("default");
1042      } else {
1043        this.search_field.val("");
1044        return this.search_field.removeClass("default");
1045      }
1046    };
1047
1048    Chosen.prototype.search_results_mouseup = function(evt) {
1049      var target;
1050      target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
1051      if (target.length) {
1052        this.result_highlight = target;
1053        this.result_select(evt);
1054        return this.search_field.focus();
1055      }
1056    };
1057
1058    Chosen.prototype.search_results_mouseover = function(evt) {
1059      var target;
1060      target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
1061      if (target) {
1062        return this.result_do_highlight(target);
1063      }
1064    };
1065
1066    Chosen.prototype.search_results_mouseout = function(evt) {
1067      if ($(evt.target).hasClass("active-result") || $(evt.target).parents('.active-result').first()) {
1068        return this.result_clear_highlight();
1069      }
1070    };
1071
1072    Chosen.prototype.choice_build = function(item) {
1073      var choice, close_link;
1074      choice = $('<li />', {
1075        "class": "search-choice"
1076      }).html("<span>" + (this.choice_label(item)) + "</span>");
1077      if (item.disabled) {
1078        choice.addClass('search-choice-disabled');
1079      } else {
1080        close_link = $('<a />', {
1081          "class": 'search-choice-close',
1082          'data-option-array-index': item.array_index
1083        });
1084        close_link.on('click.chosen', (function(_this) {
1085          return function(evt) {
1086            return _this.choice_destroy_link_click(evt);
1087          };
1088        })(this));
1089        choice.append(close_link);
1090      }
1091      return this.search_container.before(choice);
1092    };
1093
1094    Chosen.prototype.choice_destroy_link_click = function(evt) {
1095      evt.preventDefault();
1096      evt.stopPropagation();
1097      if (!this.is_disabled) {
1098        return this.choice_destroy($(evt.target));
1099      }
1100    };
1101
1102    Chosen.prototype.choice_destroy = function(link) {
1103      if (this.result_deselect(link[0].getAttribute("data-option-array-index"))) {
1104        if (this.active_field) {
1105          this.search_field.focus();
1106        } else {
1107          this.show_search_field_default();
1108        }
1109        if (this.is_multiple && this.choices_count() > 0 && this.get_search_field_value().length < 1) {
1110          this.results_hide();
1111        }
1112        link.parents('li').first().remove();
1113        return this.search_field_scale();
1114      }
1115    };
1116
1117    Chosen.prototype.results_reset = function() {
1118      this.reset_single_select_options();
1119      this.form_field.options[0].selected = true;
1120      this.single_set_selected_text();
1121      this.show_search_field_default();
1122      this.results_reset_cleanup();
1123      this.trigger_form_field_change();
1124      if (this.active_field) {
1125        return this.results_hide();
1126      }
1127    };
1128
1129    Chosen.prototype.results_reset_cleanup = function() {
1130      this.current_selectedIndex = this.form_field.selectedIndex;
1131      return this.selected_item.find("abbr").remove();
1132    };
1133
1134    Chosen.prototype.result_select = function(evt) {
1135      var high, item;
1136      if (this.result_highlight) {
1137        high = this.result_highlight;
1138        this.result_clear_highlight();
1139        if (this.is_multiple && this.max_selected_options <= this.choices_count()) {
1140          this.form_field_jq.trigger("chosen:maxselected", {
1141            chosen: this
1142          });
1143          return false;
1144        }
1145        if (this.is_multiple) {
1146          high.removeClass("active-result");
1147        } else {
1148          this.reset_single_select_options();
1149        }
1150        high.addClass("result-selected");
1151        item = this.results_data[high[0].getAttribute("data-option-array-index")];
1152        item.selected = true;
1153        this.form_field.options[item.options_index].selected = true;
1154        this.selected_option_count = null;
1155        if (this.is_multiple) {
1156          this.choice_build(item);
1157        } else {
1158          this.single_set_selected_text(this.choice_label(item));
1159        }
1160        if (this.is_multiple && (!this.hide_results_on_select || (evt.metaKey || evt.ctrlKey))) {
1161          if (evt.metaKey || evt.ctrlKey) {
1162            this.winnow_results({
1163              skip_highlight: true
1164            });
1165          } else {
1166            this.search_field.val("");
1167            this.winnow_results();
1168          }
1169        } else {
1170          this.results_hide();
1171          this.show_search_field_default();
1172        }
1173        if (this.is_multiple || this.form_field.selectedIndex !== this.current_selectedIndex) {
1174          this.trigger_form_field_change({
1175            selected: this.form_field.options[item.options_index].value
1176          });
1177        }
1178        this.current_selectedIndex = this.form_field.selectedIndex;
1179        evt.preventDefault();
1180        return this.search_field_scale();
1181      }
1182    };
1183
1184    Chosen.prototype.single_set_selected_text = function(text) {
1185      if (text == null) {
1186        text = this.default_text;
1187      }
1188      if (text === this.default_text) {
1189        this.selected_item.addClass("chosen-default");
1190      } else {
1191        this.single_deselect_control_build();
1192        this.selected_item.removeClass("chosen-default");
1193      }
1194      return this.selected_item.find("span").html(text);
1195    };
1196
1197    Chosen.prototype.result_deselect = function(pos) {
1198      var result_data;
1199      result_data = this.results_data[pos];
1200      if (!this.form_field.options[result_data.options_index].disabled) {
1201        result_data.selected = false;
1202        this.form_field.options[result_data.options_index].selected = false;
1203        this.selected_option_count = null;
1204        this.result_clear_highlight();
1205        if (this.results_showing) {
1206          this.winnow_results();
1207        }
1208        this.trigger_form_field_change({
1209          deselected: this.form_field.options[result_data.options_index].value
1210        });
1211        this.search_field_scale();
1212        return true;
1213      } else {
1214        return false;
1215      }
1216    };
1217
1218    Chosen.prototype.single_deselect_control_build = function() {
1219      if (!this.allow_single_deselect) {
1220        return;
1221      }
1222      if (!this.selected_item.find("abbr").length) {
1223        this.selected_item.find("span").first().after("<abbr class=\"search-choice-close\"></abbr>");
1224      }
1225      return this.selected_item.addClass("chosen-single-with-deselect");
1226    };
1227
1228    Chosen.prototype.get_search_field_value = function() {
1229      return this.search_field.val();
1230    };
1231
1232    Chosen.prototype.get_search_text = function() {
1233      return $.trim(this.get_search_field_value());
1234    };
1235
1236    Chosen.prototype.escape_html = function(text) {
1237      return $('<div/>').text(text).html();
1238    };
1239
1240    Chosen.prototype.winnow_results_set_highlight = function() {
1241      var do_high, selected_results;
1242      selected_results = !this.is_multiple ? this.search_results.find(".result-selected.active-result") : [];
1243      do_high = selected_results.length ? selected_results.first() : this.search_results.find(".active-result").first();
1244      if (do_high != null) {
1245        return this.result_do_highlight(do_high);
1246      }
1247    };
1248
1249    Chosen.prototype.no_results = function(terms) {
1250      var no_results_html;
1251      no_results_html = this.get_no_results_html(terms);
1252      this.search_results.append(no_results_html);
1253      return this.form_field_jq.trigger("chosen:no_results", {
1254        chosen: this
1255      });
1256    };
1257
1258    Chosen.prototype.no_results_clear = function() {
1259      return this.search_results.find(".no-results").remove();
1260    };
1261
1262    Chosen.prototype.keydown_arrow = function() {
1263      var next_sib;
1264      if (this.results_showing && this.result_highlight) {
1265        next_sib = this.result_highlight.nextAll("li.active-result").first();
1266        if (next_sib) {
1267          return this.result_do_highlight(next_sib);
1268        }
1269      } else {
1270        return this.results_show();
1271      }
1272    };
1273
1274    Chosen.prototype.keyup_arrow = function() {
1275      var prev_sibs;
1276      if (!this.results_showing && !this.is_multiple) {
1277        return this.results_show();
1278      } else if (this.result_highlight) {
1279        prev_sibs = this.result_highlight.prevAll("li.active-result");
1280        if (prev_sibs.length) {
1281          return this.result_do_highlight(prev_sibs.first());
1282        } else {
1283          if (this.choices_count() > 0) {
1284            this.results_hide();
1285          }
1286          return this.result_clear_highlight();
1287        }
1288      }
1289    };
1290
1291    Chosen.prototype.keydown_backstroke = function() {
1292      var next_available_destroy;
1293      if (this.pending_backstroke) {
1294        this.choice_destroy(this.pending_backstroke.find("a").first());
1295        return this.clear_backstroke();
1296      } else {
1297        next_available_destroy = this.search_container.siblings("li.search-choice").last();
1298        if (next_available_destroy.length && !next_available_destroy.hasClass("search-choice-disabled")) {
1299          this.pending_backstroke = next_available_destroy;
1300          if (this.single_backstroke_delete) {
1301            return this.keydown_backstroke();
1302          } else {
1303            return this.pending_backstroke.addClass("search-choice-focus");
1304          }
1305        }
1306      }
1307    };
1308
1309    Chosen.prototype.clear_backstroke = function() {
1310      if (this.pending_backstroke) {
1311        this.pending_backstroke.removeClass("search-choice-focus");
1312      }
1313      return this.pending_backstroke = null;
1314    };
1315
1316    Chosen.prototype.search_field_scale = function() {
1317      var div, i, len, style, style_block, styles, width;
1318      if (!this.is_multiple) {
1319        return;
1320      }
1321      style_block = {
1322        position: 'absolute',
1323        left: '-1000px',
1324        top: '-1000px',
1325        display: 'none',
1326        whiteSpace: 'pre'
1327      };
1328      styles = ['fontSize', 'fontStyle', 'fontWeight', 'fontFamily', 'lineHeight', 'textTransform', 'letterSpacing'];
1329      for (i = 0, len = styles.length; i < len; i++) {
1330        style = styles[i];
1331        style_block[style] = this.search_field.css(style);
1332      }
1333      div = $('<div />').css(style_block);
1334      div.text(this.get_search_field_value());
1335      $('body').append(div);
1336      width = div.width() + 25;
1337      div.remove();
1338      if (this.container.is(':visible')) {
1339        width = Math.min(this.container.outerWidth() - 10, width);
1340      }
1341      return this.search_field.width(width);
1342    };
1343
1344    Chosen.prototype.trigger_form_field_change = function(extra) {
1345      this.form_field_jq.trigger("input", extra);
1346      return this.form_field_jq.trigger("change", extra);
1347    };
1348
1349    return Chosen;
1350
1351  })(AbstractChosen);
1352
1353  document.AbstractChosen = AbstractChosen;
1354  document.Chosen = Chosen;
1355}).call(this);

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.