PageSourceSearch

https://crna.si/media/jui/js/chosen.jquery.js?4261267a09ca4dc29f7355ef498bb555

js crna.si collected 2026-10-02 20:27:51 UTC 47,934 bytes, 1,351 lines download raw bytes

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