PageSourceSearch

https://ays-pro.com/components/com_b2jcontact/js/chosen.jquery.js

js ays-pro.com collected 2026-10-02 05:13:49 UTC 39,901 bytes, 1,113 lines download raw bytes

1// Chosen, a Select Box Enhancer for jQuery and Protoype
2// by Patrick Filler for Harvest, http://getharvest.com
3//
4// Version 0.9.8
5// Full source at https://github.com/harvesthq/chosen
6// Copyright (c) 2011 Harvest http://getharvest.com
7//
8// Changelog:
9// [2012-08-02] - Add option to specify a custom value on the fly [Anderson Grüdtner Martins]
10
11// MIT License, https://github.com/harvesthq/chosen/blob/master/LICENSE.md
12// This file is generated by `cake build`, do not edit it by hand.
13
14//
15// Changes made by Joomla for RTL for 3.0
16//
17(function() {
18  var SelectParser;
19
20  SelectParser = (function() {
21
22    function SelectParser() {
23      this.options_index = 0;
24      this.parsed = [];
25    }
26
27    SelectParser.prototype.add_node = function(child) {
28      if (child.nodeName === "OPTGROUP") {
29        return this.add_group(child);
30      } else {
31        return this.add_option(child);
32      }
33    };
34
35    SelectParser.prototype.add_group = function(group) {
36      var group_position, option, _i, _len, _ref, _results;
37      group_position = this.parsed.length;
38      this.parsed.push({
39        array_index: group_position,
40        group: true,
41        label: group.label,
42        children: 0,
43        disabled: group.disabled
44      });
45      _ref = group.childNodes;
46      _results = [];
47      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
48        option = _ref[_i];
49        _results.push(this.add_option(option, group_position, group.disabled));
50      }
51      return _results;
52    };
53
54    SelectParser.prototype.add_option = function(option, group_position, group_disabled) {
55      if (option.nodeName === "OPTION") {
56        if (option.text !== "") {
57          if (group_position != null) {
58            this.parsed[group_position].children += 1;
59          }
60          this.parsed.push({
61            array_index: this.parsed.length,
62            options_index: this.options_index,
63            value: option.value,
64            text: option.text,
65            html: option.innerHTML,
66            selected: option.selected,
67            disabled: group_disabled === true ? group_disabled : option.disabled,
68            group_array_index: group_position,
69            classes: option.className,
70            style: option.style.cssText
71          });
72        } else {
73          this.parsed.push({
74            array_index: this.parsed.length,
75            options_index: this.options_index,
76            empty: true
77          });
78        }
79        return this.options_index += 1;
80      }
81    };
82
83    return SelectParser;
84
85  })();
86
87  SelectParser.select_to_array = function(select) {
88    var child, parser, _i, _len, _ref;
89    parser = new SelectParser();
90    _ref = select.childNodes;
91    for (_i = 0, _len = _ref.length; _i < _len; _i++) {
92      child = _ref[_i];
93      parser.add_node(child);
94    }
95    return parser.parsed;
96  };
97
98  this.SelectParser = SelectParser;
99
100}).call(this);
101
102/*
103Chosen source: generate output using 'cake build'
104Copyright (c) 2011 by Harvest
105*/
106
107(function() {
108  var AbstractChosen, root;
109
110  root = this;
111
112  AbstractChosen = (function() {
113
114    function AbstractChosen(form_field, options) {
115      this.form_field = form_field;
116      this.options = options != null ? options : {};
117      this.set_default_values();
118      this.is_multiple = this.form_field.multiple;
119      this.set_default_text();
120      this.setup();
121      this.set_up_html();
122      this.register_observers();
123      this.finish_setup();
124    }
125
126    AbstractChosen.prototype.set_default_values = function() {
127      var _this = this;
128      this.click_test_action = function(evt) {
129        return _this.test_active_click(evt);
130      };
131      this.activate_action = function(evt) {
132        return _this.activate_field(evt);
133      };
134      this.active_field = false;
135      this.mouse_on_container = false;
136      this.results_showing = false;
137      this.result_highlighted = null;
138      this.result_single_selected = null;
139      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;
140      this.disable_search_threshold = this.options.disable_search_threshold || 0;
141      this.search_contains = this.options.search_contains || false;
142      this.choices = 0;
143      this.single_backstroke_delete = this.options.single_backstroke_delete || false;
144      this.max_selected_options = this.options.max_selected_options || Infinity;
145      this.allow_custom_value = false;
146      return true;
147    };
148
149    /* USING JOOMLA.JTEXT TO TRANSLATE LANGUAGE STRINGS
150    * ================================================= */
151
152    AbstractChosen.prototype.set_default_text = function() {
153      var results_none_found_default;
154      if (this.form_field.getAttribute("data-placeholder")) {
155        this.default_text = this.form_field.getAttribute("data-placeholder");
156      } else if (this.is_multiple) {
157        this.default_text = this.options.placeholder_text_multiple || this.options.placeholder_text || Joomla.JText._('JGLOBAL_SELECT_SOME_OPTIONS');
158	  } else if (this.allow_custom_value) {
159        this.default_text = this.options.placeholder_text_single || this.options.placeholder_text || Joomla.JText._('JGLOBAL_TYPE_OR_SELECT_SOME_OPTIONS');
160      } else {
161        this.default_text = this.options.placeholder_text_single || this.options.placeholder_text || Joomla.JText._('JGLOBAL_SELECT_AN_OPTION');
162      }
163      if (this.allow_custom_value) {
164        this.custom_group_text = this.form_field.getAttribute("data-custom_group_text") || this.options.custom_group_text || "Custom Value";
165        results_none_found_default = "Add custom value";
166      } else {
167        results_none_found_default = "No results match";
168      }
169      return this.results_none_found = this.form_field.getAttribute("data-no_results_text") || this.options.no_results_text || Joomla.JText._('JGLOBAL_SELECT_NO_RESULTS_MATCH');
170    };
171
172    AbstractChosen.prototype.mouse_enter = function() {
173      return this.mouse_on_container = true;
174    };
175
176    AbstractChosen.prototype.mouse_leave = function() {
177      return this.mouse_on_container = false;
178    };
179
180    AbstractChosen.prototype.input_focus = function(evt) {
181      var _this = this;
182      if (!this.active_field) {
183        return setTimeout((function() {
184          return _this.container_mousedown();
185        }), 50);
186      }
187    };
188
189    AbstractChosen.prototype.input_blur = function(evt) {
190      var _this = this;
191      if (!this.mouse_on_container) {
192        this.active_field = false;
193        return setTimeout((function() {
194          return _this.blur_test();
195        }), 100);
196      }
197    };
198
199    AbstractChosen.prototype.result_add_option = function(option) {
200      var classes, style;
201      if (!option.disabled) {
202        option.dom_id = this.container_id + "_o_" + option.array_index;
203        classes = option.selected && this.is_multiple ? [] : ["active-result"];
204        if (option.selected) {
205          classes.push("result-selected");
206        }
207        if (option.group_array_index != null) {
208          classes.push("group-option");
209        }
210        if (option.classes !== "") {
211          classes.push(option.classes);
212        }
213        style = option.style.cssText !== "" ? " style=\"" + option.style + "\"" : "";
214        return '<li id="' + option.dom_id + '" class="' + classes.join(' ') + '"' + style + '>' + option.html + '</li>';
215      } else {
216        return "";
217      }
218    };
219
220    AbstractChosen.prototype.results_update_field = function() {
221      if (!this.is_multiple) {
222        this.results_reset_cleanup();
223      }
224      this.result_clear_highlight();
225      this.result_single_selected = null;
226      return this.results_build();
227    };
228
229    AbstractChosen.prototype.results_toggle = function() {
230      if (this.results_showing) {
231        return this.results_hide();
232      } else {
233        return this.results_show();
234      }
235    };
236
237    AbstractChosen.prototype.results_search = function(evt) {
238      if (this.results_showing) {
239        return this.winnow_results();
240      } else {
241        return this.results_show();
242      }
243    };
244
245    AbstractChosen.prototype.keyup_checker = function(evt) {
246      var stroke, _ref;
247      stroke = (_ref = evt.which) != null ? _ref : evt.keyCode;
248      this.search_field_scale();
249      switch (stroke) {
250        case 8:
251          if (this.is_multiple && this.backstroke_length < 1 && this.choices > 0) {
252            return this.keydown_backstroke();
253          } else if (!this.pending_backstroke) {
254            this.result_clear_highlight();
255            return this.results_search();
256          }
257          break;
258        case 13:
259          evt.preventDefault();
260          if (this.results_showing) {
261            return this.result_select(evt);
262          }
263          break;
264        case 27:
265          if (this.results_showing) {
266            this.results_hide();
267          }
268          return true;
269        case 9:
270        case 38:
271        case 40:
272        case 16:
273        case 91:
274        case 17:
275          break;
276        default:
277          return this.results_search();
278      }
279    };
280
281    AbstractChosen.prototype.generate_field_id = function() {
282      var new_id;
283      new_id = this.generate_random_id();
284      this.form_field.id = new_id;
285      return new_id;
286    };
287
288    AbstractChosen.prototype.generate_random_char = function() {
289      var chars, newchar, rand;
290      chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
291      rand = Math.floor(Math.random() * chars.length);
292      return newchar = chars.substring(rand, rand + 1);
293    };
294
295    return AbstractChosen;
296
297  })();
298
299  root.AbstractChosen = AbstractChosen;
300
301}).call(this);
302
303/*
304Chosen source: generate output using 'cake build'
305Copyright (c) 2011 by Harvest
306*/
307
308(function() {
309  var $, Chosen, get_side_border_padding, root,
310    __hasProp = {}.hasOwnProperty,
311    __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; };
312
313  root = this;
314
315  $ = jQuery;
316
317  $.fn.extend({
318    chosen: function(options) {
319      if ($.browser.msie && ($.browser.version === "6.0" || $.browser.version === "7.0")) {
320        return this;
321      }
322      return this.each(function(input_field) {
323        var $this;
324        $this = $(this);
325        if (!$this.hasClass("chzn-done")) {
326          return $this.data('chosen', new Chosen(this, options));
327        }
328      });
329    }
330  });
331
332  Chosen = (function(_super) {
333
334    __extends(Chosen, _super);
335
336    function Chosen() {
337      return Chosen.__super__.constructor.apply(this, arguments);
338    }
339
340    Chosen.prototype.setup = function() {
341      this.form_field_jq = $(this.form_field);
342      this.current_value = this.form_field_jq.val();
343      this.is_rtl = this.form_field_jq.hasClass("chzn-rtl");
344      return this.allow_custom_value = this.form_field_jq.hasClass("chzn-custom-value" || this.options.allow_custom_value);
345    };
346
347    Chosen.prototype.finish_setup = function() {
348      return this.form_field_jq.addClass("chzn-done");
349    };
350
351    Chosen.prototype.set_up_html = function() {
352      var container_div, dd_top, dd_width, sf_width;
353      this.container_id = this.form_field.id.length ? this.form_field.id.replace(/[^\w]/g, '_') : this.generate_field_id();
354      this.container_id += "_chzn";
355      this.f_width = this.form_field_jq.outerWidth();
356      container_div = $("<div />", {
357        id: this.container_id,
358        "class": "chzn-container" + (this.is_rtl ? ' chzn-rtl' : ''),
359        style: 'width: ' + this.f_width + 'px;'
360      });
361      if (this.is_multiple) {
362        // Changed left:-9000 to display:none for rtl
363    	// container_div.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" style="left:-9000px;"><ul class="chzn-results"></ul></div>');
364    	container_div.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" style="display:none;"><ul class="chzn-results"></ul></div>');
365      } else {
366    	// Changed left:-9000 to display:none for rtl
367    	//container_div.html('<a href="javascript:void(0)" class="chzn-single chzn-default"><span>' + this.default_text + '</span><div><b></b></div></a><div class="chzn-drop" style="left:-9000px;"><div class="chzn-search"><input type="text" autocomplete="off" /></div><ul class="chzn-results"></ul></div>');
368    	container_div.html('<a href="javascript:void(0)" class="chzn-single chzn-default"><span>' + this.default_text + '</span><div><b></b></div></a><div class="chzn-drop" style="display:none;"><div class="chzn-search"><input type="text" autocomplete="off" /></div><ul class="chzn-results"></ul></div>');
369      }
370      this.form_field_jq.hide().after(container_div);
371      this.container = $('#' + this.container_id);
372      this.container.addClass("chzn-container-" + (this.is_multiple ? "multi" : "single"));
373      this.dropdown = this.container.find('div.chzn-drop').first();
374      dd_top = this.container.height();
375      dd_width = this.f_width - get_side_border_padding(this.dropdown);
376      this.dropdown.css({
377        "width": dd_width + "px",
378        "top": dd_top + "px"
379      });
380      this.search_field = this.container.find('input').first();
381      this.search_results = this.container.find('ul.chzn-results').first();
382      this.search_field_scale();
383      this.search_no_results = this.container.find('li.no-results').first();
384      if (this.is_multiple) {
385        this.search_choices = this.container.find('ul.chzn-choices').first();
386        this.search_container = this.container.find('li.search-field').first();
387      } else {
388        this.search_container = this.container.find('div.chzn-search').first();
389        this.selected_item = this.container.find('.chzn-single').first();
390        sf_width = dd_width - get_side_border_padding(this.search_container) - get_side_border_padding(this.search_field);
391        this.search_field.css({
392          "width": sf_width + "px"
393        });
394      }
395      this.results_build();
396      this.set_tab_index();
397      return this.form_field_jq.trigger("liszt:ready", {
398        chosen: this
399      });
400    };
401
402    Chosen.prototype.register_observers = function() {
403      var _this = this;
404      this.container.mousedown(function(evt) {
405        return _this.container_mousedown(evt);
406      });
407      this.container.mouseup(function(evt) {
408        return _this.container_mouseup(evt);
409      });
410      this.container.mouseenter(function(evt) {
411        return _this.mouse_enter(evt);
412      });
413      this.container.mouseleave(function(evt) {
414        return _this.mouse_leave(evt);
415      });
416      this.search_results.mouseup(function(evt) {
417        return _this.search_results_mouseup(evt);
418      });
419      this.search_results.mouseover(function(evt) {
420        return _this.search_results_mouseover(evt);
421      });
422      this.search_results.mouseout(function(evt) {
423        return _this.search_results_mouseout(evt);
424      });
425      this.form_field_jq.bind("liszt:updated", function(evt) {
426        return _this.results_update_field(evt);
427      });
428      this.search_field.blur(function(evt) {
429        return _this.input_blur(evt);
430      });
431      this.search_field.keyup(function(evt) {
432        return _this.keyup_checker(evt);
433      });
434      this.search_field.keydown(function(evt) {
435        return _this.keydown_checker(evt);
436      });
437      if (this.is_multiple) {
438        this.search_choices.click(function(evt) {
439          return _this.choices_click(evt);
440        });
441        return this.search_field.focus(function(evt) {
442          return _this.input_focus(evt);
443        });
444      } else {
445        return this.container.click(function(evt) {
446          return evt.preventDefault();
447        });
448      }
449    };
450
451    Chosen.prototype.search_field_disabled = function() {
452      this.is_disabled = this.form_field_jq[0].disabled;
453      if (this.is_disabled) {
454        this.container.addClass('chzn-disabled');
455        this.search_field[0].disabled = true;
456        if (!this.is_multiple) {
457          this.selected_item.unbind("focus", this.activate_action);
458        }
459        return this.close_field();
460      } else {
461        this.container.removeClass('chzn-disabled');
462        this.search_field[0].disabled = false;
463        if (!this.is_multiple) {
464          return this.selected_item.bind("focus", this.activate_action);
465        }
466      }
467    };
468
469    Chosen.prototype.container_mousedown = function(evt) {
470      var target_closelink;
471      if (!this.is_disabled) {
472        target_closelink = evt != null ? ($(evt.target)).hasClass("search-choice-close") : false;
473        if (evt && evt.type === "mousedown" && !this.results_showing) {
474          evt.stopPropagation();
475        }
476        if (!this.pending_destroy_click && !target_closelink) {
477          if (!this.active_field) {
478            if (this.is_multiple) {
479              this.search_field.val("");
480            }
481            $(document).click(this.click_test_action);
482            this.results_show();
483          } else if (!this.is_multiple && evt && (($(evt.target)[0] === this.selected_item[0]) || $(evt.target).parents("a.chzn-single").length)) {
484            evt.preventDefault();
485            this.results_toggle();
486          }
487          return this.activate_field();
488        } else {
489          return this.pending_destroy_click = false;
490        }
491      }
492    };
493
494    Chosen.prototype.container_mouseup = function(evt) {
495      if (evt.target.nodeName === "ABBR" && !this.is_disabled) {
496        return this.results_reset(evt);
497      }
498    };
499
500    Chosen.prototype.blur_test = function(evt) {
501      if (!this.active_field && this.container.hasClass("chzn-container-active")) {
502        return this.close_field();
503      }
504    };
505
506    Chosen.prototype.close_field = function() {
507      $(document).unbind("click", this.click_test_action);
508      if (!this.is_multiple) {
509        this.selected_item.attr("tabindex", this.search_field.attr("tabindex"));
510        this.search_field.attr("tabindex", -1);
511      }
512      this.active_field = false;
513      this.results_hide();
514      this.container.removeClass("chzn-container-active");
515      this.winnow_results_clear();
516      this.clear_backstroke();
517      this.show_search_field_default();
518      return this.search_field_scale();
519    };
520
521    Chosen.prototype.activate_field = function() {
522      if (!this.is_multiple && !this.active_field) {
523        this.search_field.attr("tabindex", this.selected_item.attr("tabindex"));
524        this.selected_item.attr("tabindex", -1);
525      }
526      this.container.addClass("chzn-container-active");
527      this.active_field = true;
528      this.search_field.val(this.search_field.val());
529      return this.search_field.focus();
530    };
531
532    Chosen.prototype.test_active_click = function(evt) {
533      if ($(evt.target).parents('#' + this.container_id).length) {
534        return this.active_field = true;
535      } else {
536        return this.close_field();
537      }
538    };
539
540    Chosen.prototype.results_build = function() {
541      var content, data, _i, _len, _ref;
542      this.parsing = true;
543      this.results_data = root.SelectParser.select_to_array(this.form_field);
544      if (this.is_multiple && this.choices > 0) {
545        this.search_choices.find("li.search-choice").remove();
546        this.choices = 0;
547      } else if (!this.is_multiple) {
548        this.selected_item.addClass("chzn-default").find("span").text(this.default_text);
549        if (this.form_field.options.length <= this.disable_search_threshold) {
550          this.container.addClass("chzn-container-single-nosearch");
551        } else {
552          this.container.removeClass("chzn-container-single-nosearch");
553        }
554      }
555      content = '';
556      _ref = this.results_data;
557      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
558        data = _ref[_i];
559        if (data.group) {
560          content += this.result_add_group(data);
561        } else if (!data.empty) {
562          content += this.result_add_option(data);
563          if (data.selected && this.is_multiple) {
564            this.choice_build(data);
565          } else if (data.selected && !this.is_multiple) {
566            this.selected_item.removeClass("chzn-default").find("span").text(data.text);
567            if (this.allow_single_deselect) {
568              this.single_deselect_control_build();
569            }
570          }
571        }
572      }
573      this.search_field_disabled();
574      this.show_search_field_default();
575      this.search_field_scale();
576      this.search_results.html(content);
577      return this.parsing = false;
578    };
579
580    Chosen.prototype.result_add_group = function(group) {
581      if (!group.disabled) {
582        group.dom_id = this.container_id + "_g_" + group.array_index;
583        return '<li id="' + group.dom_id + '" class="group-result">' + $("<div />").text(group.label).html() + '</li>';
584      } else {
585        return "";
586      }
587    };
588
589    Chosen.prototype.result_do_highlight = function(el) {
590      var high_bottom, high_top, maxHeight, visible_bottom, visible_top;
591      if (el.length) {
592        this.result_clear_highlight();
593        this.result_highlight = el;
594        this.result_highlight.addClass("highlighted");
595        maxHeight = parseInt(this.search_results.css("maxHeight"), 10);
596        visible_top = this.search_results.scrollTop();
597        visible_bottom = maxHeight + visible_top;
598        high_top = this.result_highlight.position().top + this.search_results.scrollTop();
599        high_bottom = high_top + this.result_highlight.outerHeight();
600        if (high_bottom >= visible_bottom) {
601          return this.search_results.scrollTop((high_bottom - maxHeight) > 0 ? high_bottom - maxHeight : 0);
602        } else if (high_top < visible_top) {
603          return this.search_results.scrollTop(high_top);
604        }
605      }
606    };
607
608    Chosen.prototype.result_clear_highlight = function() {
609      if (this.result_highlight) {
610        this.result_highlight.removeClass("highlighted");
611      }
612      return this.result_highlight = null;
613    };
614
615    Chosen.prototype.results_show = function() {
616      var dd_top;
617      if (!this.is_multiple) {
618        this.selected_item.addClass("chzn-single-with-drop");
619        if (this.result_single_selected) {
620          this.result_do_highlight(this.result_single_selected);
621        }
622      } else if (this.max_selected_options <= this.choices) {
623        this.form_field_jq.trigger("liszt:maxselected", {
624          chosen: this
625        });
626        return false;
627      }
628      dd_top = this.is_multiple ? this.container.height() : this.container.height() - 1;
629      this.form_field_jq.trigger("liszt:showing_dropdown", {
630        chosen: this
631      });
632      this.dropdown.css({
633        "top": dd_top + "px",
634        // Changed for RTL
635        //"left": 0
636        "display": "block"
637      });
638      this.results_showing = true;
639      this.search_field.focus();
640      this.search_field.val(this.search_field.val());
641      return this.winnow_results();
642    };
643
644    Chosen.prototype.results_hide = function() {
645      if (!this.is_multiple) {
646        this.selected_item.removeClass("chzn-single-with-drop");
647      }
648      this.result_clear_highlight();
649      this.form_field_jq.trigger("liszt:hiding_dropdown", {
650        chosen: this
651      });
652      this.dropdown.css({
653        // Changed for RTL
654        //"left": "-9000px"
655        "display": "none"
656      });
657      return this.results_showing = false;
658    };
659
660    Chosen.prototype.set_tab_index = function(el) {
661      var ti;
662      if (this.form_field_jq.attr("tabindex")) {
663        ti = this.form_field_jq.attr("tabindex");
664        this.form_field_jq.attr("tabindex", -1);
665        if (this.is_multiple) {
666          return this.search_field.attr("tabindex", ti);
667        } else {
668          this.selected_item.attr("tabindex", ti);
669          return this.search_field.attr("tabindex", -1);
670        }
671      }
672    };
673
674    Chosen.prototype.show_search_field_default = function() {
675	if (this.is_multiple) {
676		if (this.choices < 1 && !this.active_field) {
677			this.search_field.val(this.default_text);
678			return this.search_field.addClass("default");
679		} 
680      } else {
681        this.search_field.val("");
682        return this.search_field.removeClass("default");
683      }
684    };
685
686    Chosen.prototype.search_results_mouseup = function(evt) {
687      var target;
688      target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
689      if (target.length) {
690        this.result_highlight = target;
691        return this.result_select(evt);
692      }
693    };
694
695    Chosen.prototype.search_results_mouseover = function(evt) {
696      var target;
697      target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
698      if (target) {
699        return this.result_do_highlight(target);
700      }
701    };
702
703    Chosen.prototype.search_results_mouseout = function(evt) {
704      if ($(evt.target).hasClass("active-result" || $(evt.target).parents('.active-result').first())) {
705        return this.result_clear_highlight();
706      }
707    };
708
709    Chosen.prototype.choices_click = function(evt) {
710      evt.preventDefault();
711      if (this.active_field && !($(evt.target).hasClass("search-choice" || $(evt.target).parents('.search-choice').first)) && !this.results_showing) {
712        return this.results_show();
713      }
714    };
715
716    Chosen.prototype.choice_build = function(item) {
717      var choice_id, link,
718        _this = this;
719      if (this.is_multiple && this.max_selected_options <= this.choices) {
720        this.form_field_jq.trigger("liszt:maxselected", {
721          chosen: this
722        });
723        return false;
724      }
725      choice_id = this.container_id + "_c_" + item.array_index;
726      this.choices += 1;
727      this.search_container.before('<li class="search-choice" id="' + choice_id + '"><span>' + item.html + '</span><a href="javascript:void(0)" class="search-choice-close" rel="' + item.array_index + '"></a></li>');
728      link = $('#' + choice_id).find("a").first();
729      return link.click(function(evt) {
730        return _this.choice_destroy_link_click(evt);
731      });
732    };
733
734    Chosen.prototype.choice_destroy_link_click = function(evt) {
735      evt.preventDefault();
736      if (!this.is_disabled) {
737        this.pending_destroy_click = true;
738        return this.choice_destroy($(evt.target));
739      } else {
740        return evt.stopPropagation;
741      }
742    };
743
744    Chosen.prototype.choice_destroy = function(link) {
745      this.choices -= 1;
746      this.show_search_field_default();
747      if (this.is_multiple && this.choices > 0 && this.search_field.val().length < 1) {
748        this.results_hide();
749      }
750      this.result_deselect(link.attr("rel"));
751      return link.parents('li').first().remove();
752    };
753
754    Chosen.prototype.results_reset = function() {
755      this.form_field.options[0].selected = true;
756      this.selected_item.find("span").text(this.default_text);
757      if (!this.is_multiple) {
758        this.selected_item.addClass("chzn-default");
759      }
760      this.show_search_field_default();
761      this.results_reset_cleanup();
762      this.form_field_jq.trigger("change");
763      if (this.active_field) {
764        return this.results_hide();
765      }
766    };
767
768    Chosen.prototype.results_reset_cleanup = function() {
769      return this.selected_item.find("abbr").remove();
770    };
771
772    Chosen.prototype.result_select = function(evt) {
773      var high, high_id, item, position;
774      if (this.result_highlight) {
775        high = this.result_highlight;
776        high_id = high.attr("id");
777        this.result_clear_highlight();
778        if (this.is_multiple) {
779          this.result_deactivate(high);
780        } else {
781          this.search_results.find(".result-selected").removeClass("result-selected");
782          this.result_single_selected = high;
783          this.selected_item.removeClass("chzn-default");
784        }
785        high.addClass("result-selected");
786        position = high_id.substr(high_id.lastIndexOf("_") + 1);
787        item = this.results_data[position];
788        item.selected = true;
789        this.form_field.options[item.options_index].selected = true;
790        if (this.is_multiple) {
791          this.choice_build(item);
792        } else {
793          this.selected_item.find("span").first().text(item.text);
794          if (this.allow_single_deselect) {
795            this.single_deselect_control_build();
796          }
797        }
798        if (!(evt.metaKey && this.is_multiple)) {
799          this.results_hide();
800        }
801        this.search_field.val("");
802        if (this.is_multiple || this.form_field_jq.val() !== this.current_value) {
803          this.form_field_jq.trigger("change", {
804            'selected': this.form_field.options[item.options_index].value
805          });
806        }
807        this.current_value = this.form_field_jq.val();
808        return this.search_field_scale();
809      } else if ((!this.is_multiple) && this.allow_custom_value) {
810        value = this.search_field.val();
811        group = this.add_unique_custom_group();
812        option = $('<option value="' + value + '">' + value + '</option>');
813        group.append(option);
814        this.form_field_jq.append(group);
815        this.form_field.options[this.form_field.options.length - 1].selected = true;
816        if (!evt.metaKey) {
817          this.results_hide();
818        }
819        return this.results_build();
820      }
821    };
822
823    Chosen.prototype.find_custom_group = function() {
824      var found, group, _i, _len, _ref;
825      _ref = $('optgroup', this.form_field);
826      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
827        group = _ref[_i];
828        if (group.getAttribute('label') === this.custom_group_text) {
829          found = group;
830        }
831      }
832      return found;
833    };
834
835    Chosen.prototype.add_unique_custom_group = function() {
836      var group;
837      group = this.find_custom_group();
838      if (!group) {
839        group = $('<optgroup label="' + this.custom_group_text + '"></optgroup>');
840      }
841      return $(group);
842    };
843
844    Chosen.prototype.result_activate = function(el) {
845      return el.addClass("active-result");
846    };
847
848    Chosen.prototype.result_deactivate = function(el) {
849      return el.removeClass("active-result");
850    };
851
852    Chosen.prototype.result_deselect = function(pos) {
853      var result, result_data;
854      result_data = this.results_data[pos];
855      result_data.selected = false;
856      this.form_field.options[result_data.options_index].selected = false;
857      result = $("#" + this.container_id + "_o_" + pos);
858      result.removeClass("result-selected").addClass("active-result").show();
859      this.result_clear_highlight();
860      this.winnow_results();
861      this.form_field_jq.trigger("change", {
862        deselected: this.form_field.options[result_data.options_index].value
863      });
864      return this.search_field_scale();
865    };
866
867    Chosen.prototype.single_deselect_control_build = function() {
868      if (this.allow_single_deselect && this.selected_item.find("abbr").length < 1) {
869        return this.selected_item.find("span").first().after("<abbr class=\"search-choice-close\"></abbr>");
870      }
871    };
872
873    Chosen.prototype.winnow_results = function() {
874      var found, option, part, parts, regex, regexAnchor, result, result_id, results, searchText, startpos, text, zregex, _i, _j, _len, _len2, _ref;
875      this.no_results_clear();
876      results = 0;
877      searchText = this.search_field.val() === this.default_text ? "" : $('<div/>').text($.trim(this.search_field.val())).html();
878      regexAnchor = this.search_contains ? "" : "^";
879      regex = new RegExp(regexAnchor + searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
880      zregex = new RegExp(searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
881      _ref = this.results_data;
882      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
883        option = _ref[_i];
884        if (!option.disabled && !option.empty) {
885          if (option.group) {
886            $('#' + option.dom_id).css('display', 'none');
887          } else if (!(this.is_multiple && option.selected)) {
888            found = false;
889            result_id = option.dom_id;
890            result = $("#" + result_id);
891            if (regex.test(option.html)) {
892              found = true;
893              results += 1;
894            } else if (option.html.indexOf(" ") >= 0 || option.html.indexOf("[") === 0) {
895              parts = option.html.replace(/\[|\]/g, "").split(" ");
896              if (parts.length) {
897                for (_j = 0, _len2 = parts.length; _j < _len2; _j++) {
898                  part = parts[_j];
899                  if (regex.test(part)) {
900                    found = true;
901                    results += 1;
902                  }
903                }
904              }
905            }
906            if (found) {
907              if (searchText.length) {
908                startpos = option.html.search(zregex);
909                text = option.html.substr(0, startpos + searchText.length) + '</em>' + option.html.substr(startpos + searchText.length);
910                text = text.substr(0, startpos) + '<em>' + text.substr(startpos);
911              } else {
912                text = option.html;
913              }
914              result.html(text);
915              this.result_activate(result);
916              if (option.group_array_index != null) {
917                $("#" + this.results_data[option.group_array_index].dom_id).css('display', 'list-item');
918              }
919            } else {
920              if (this.result_highlight && result_id === this.result_highlight.attr('id')) {
921                this.result_clear_highlight();
922              }
923              this.result_deactivate(result);
924            }
925          }
926        }
927      }
928      if (results < 1 && searchText.length) {
929        return this.no_results(searchText);
930      } else {
931        return this.winnow_results_set_highlight();
932      }
933    };
934
935    Chosen.prototype.winnow_results_clear = function() {
936      var li, lis, _i, _len, _results;
937      this.search_field.val("");
938      lis = this.search_results.find("li");
939      _results = [];
940      for (_i = 0, _len = lis.length; _i < _len; _i++) {
941        li = lis[_i];
942        li = $(li);
943        if (li.hasClass("group-result")) {
944          _results.push(li.css('display', 'auto'));
945        } else if (!this.is_multiple || !li.hasClass("result-selected")) {
946          _results.push(this.result_activate(li));
947        } else {
948          _results.push(void 0);
949        }
950      }
951      return _results;
952    };
953
954    Chosen.prototype.winnow_results_set_highlight = function() {
955      var do_high, selected_results;
956      if (!this.result_highlight) {
957        selected_results = !this.is_multiple ? this.search_results.find(".result-selected.active-result") : [];
958        do_high = selected_results.length ? selected_results.first() : this.search_results.find(".active-result").first();
959        if (do_high != null) {
960          return this.result_do_highlight(do_high);
961        }
962      }
963    };
964
965    Chosen.prototype.no_results = function(terms) {
966      var no_results_html;
967      no_results_html = $('<li class="no-results">' + this.results_none_found + ' "<span></span>"</li>');
968      no_results_html.find("span").first().html(terms);
969      return this.search_results.append(no_results_html);
970    };
971
972    Chosen.prototype.no_results_clear = function() {
973      return this.search_results.find(".no-results").remove();
974    };
975
976    Chosen.prototype.keydown_arrow = function() {
977      var first_active, next_sib;
978      if (!this.result_highlight) {
979        first_active = this.search_results.find("li.active-result").first();
980        if (first_active) {
981          this.result_do_highlight($(first_active));
982        }
983      } else if (this.results_showing) {
984        next_sib = this.result_highlight.nextAll("li.active-result").first();
985        if (next_sib) {
986          this.result_do_highlight(next_sib);
987        }
988      }
989      if (!this.results_showing) {
990        return this.results_show();
991      }
992    };
993
994    Chosen.prototype.keyup_arrow = function() {
995      var prev_sibs;
996      if (!this.results_showing && !this.is_multiple) {
997        return this.results_show();
998      } else if (this.result_highlight) {
999        prev_sibs = this.result_highlight.prevAll("li.active-result");
1000        if (prev_sibs.length) {
1001          return this.result_do_highlight(prev_sibs.first());
1002        } else {
1003          if (this.choices > 0) {
1004            this.results_hide();
1005          }
1006          return this.result_clear_highlight();
1007        }
1008      }
1009    };
1010
1011    Chosen.prototype.keydown_backstroke = function() {
1012      if (this.pending_backstroke) {
1013        this.choice_destroy(this.pending_backstroke.find("a").first());
1014        return this.clear_backstroke();
1015      } else {
1016        this.pending_backstroke = this.search_container.siblings("li.search-choice").last();
1017        if (this.single_backstroke_delete) {
1018          return this.keydown_backstroke();
1019        } else {
1020          return this.pending_backstroke.addClass("search-choice-focus");
1021        }
1022      }
1023    };
1024
1025    Chosen.prototype.clear_backstroke = function() {
1026      if (this.pending_backstroke) {
1027        this.pending_backstroke.removeClass("search-choice-focus");
1028      }
1029      return this.pending_backstroke = null;
1030    };
1031
1032    Chosen.prototype.keydown_checker = function(evt) {
1033      var stroke, _ref;
1034      stroke = (_ref = evt.which) != null ? _ref : evt.keyCode;
1035      this.search_field_scale();
1036      if (stroke !== 8 && this.pending_backstroke) {
1037        this.clear_backstroke();
1038      }
1039      switch (stroke) {
1040        case 8:
1041          this.backstroke_length = this.search_field.val().length;
1042          break;
1043        case 9:
1044          if (this.results_showing && !this.is_multiple) {
1045            this.result_select(evt);
1046          }
1047          this.mouse_on_container = false;
1048          break;
1049        case 13:
1050          evt.preventDefault();
1051          break;
1052        case 38:
1053          evt.preventDefault();
1054          this.keyup_arrow();
1055          break;
1056        case 40:
1057          this.keydown_arrow();
1058          break;
1059      }
1060    };
1061
1062    Chosen.prototype.search_field_scale = function() {
1063      var dd_top, div, h, style, style_block, styles, w, _i, _len;
1064      if (this.is_multiple) {
1065        h = 0;
1066        w = 0;
1067        style_block = "position:absolute; left: -1000px; top: -1000px; display:none;";
1068        styles = ['font-size', 'font-style', 'font-weight', 'font-family', 'line-height', 'text-transform', 'letter-spacing'];
1069        for (_i = 0, _len = styles.length; _i < _len; _i++) {
1070          style = styles[_i];
1071          style_block += style + ":" + this.search_field.css(style) + ";";
1072        }
1073        div = $('<div />', {
1074          'style': style_block
1075        });
1076        div.text(this.search_field.val());
1077        $('body').append(div);
1078        w = div.width() + 25;
1079        div.remove();
1080        if (w > this.f_width - 10) {
1081          w = this.f_width - 10;
1082        }
1083        this.search_field.css({
1084          'width': w + 'px'
1085        });
1086        dd_top = this.container.height();
1087        return this.dropdown.css({
1088          "top": dd_top + "px"
1089        });
1090      }
1091    };
1092
1093    Chosen.prototype.generate_random_id = function() {
1094      var string;
1095      string = "sel" + this.generate_random_char() + this.generate_random_char() + this.generate_random_char();
1096      while ($("#" + string).length > 0) {
1097        string += this.generate_random_char();
1098      }
1099      return string;
1100    };
1101
1102    return Chosen;
1103
1104  })(AbstractChosen);
1105
1106  get_side_border_padding = function(elmt) {
1107    var side_border_padding;
1108    return side_border_padding = elmt.outerWidth() - elmt.width();
1109  };
1110
1111  root.get_side_border_padding = get_side_border_padding;
1112
1113}).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.