PageSourceSearch

https://dateurope.com/wp-content/plugins/imaginem-blocks-ii/assets/js/chosen/chosen.jquery.js

js dateurope.com collected 2026-10-07 16:32:56 UTC 46,744 bytes, 1,321 lines download raw bytes

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