Changeset 98557 in spip-zone for _plugins_/chosen/trunk


Ignore:
Timestamp:
Jun 25, 2016, 4:07:17 PM (2 years ago)
Author:
p@…
Message:

Mise à jour de la lib Chosen

On passe de 1.1.0 à 1.6.1

Location:
_plugins_/chosen/trunk/lib/chosen
Files:
12 added
5 edited
1 copied

Legend:

Unmodified
Added
Removed
  • _plugins_/chosen/trunk/lib/chosen/chosen-sprite@2x.png

    • Property svn:executable deleted
  • _plugins_/chosen/trunk/lib/chosen/chosen.css

    r89038 r98557  
    33by Patrick Filler for Harvest, http://getharvest.com
    44
    5 Version 1.1.0
     5Version 1.6.1
    66Full source at https://github.com/harvesthq/chosen
    7 Copyright (c) 2011 Harvest http://getharvest.com
     7Copyright (c) 2011-2016 Harvest http://getharvest.com
    88
    99MIT License, https://github.com/harvesthq/chosen/blob/master/LICENSE.md
     
    1111*/
    1212
    13 /*!
    14 Chosen, a Select Box Enhancer for jQuery and Prototype
    15 by Patrick Filler for Harvest, http://getharvest.com
    16 
    17 Version 1.1.0
    18 Full source at https://github.com/harvesthq/chosen
    19 Copyright (c) 2011 Harvest http://getharvest.com
    20 
    21 MIT License, https://github.com/harvesthq/chosen/blob/master/LICENSE.md
    22 This file is generated by `grunt build`, do not edit it by hand.
    23 */
    24 
    2513/* @group Base */
    2614.chosen-container {
     
    2917  vertical-align: middle;
    3018  font-size: 13px;
    31   zoom: 1;
    32   *display: inline;
    33   -moz-user-select: -moz-none;
    34   -ms-user-select: none;
    3519  -webkit-user-select: none;
     20  -moz-user-select: none;
    3621  user-select: none;
     22}
     23.chosen-container * {
     24  -webkit-box-sizing: border-box;
     25  -moz-box-sizing: border-box;
     26  box-sizing: border-box;
    3727}
    3828.chosen-container .chosen-drop {
     
    4131  left: -9999px;
    4232  z-index: 1010;
    43   -moz-box-sizing: border-box;
    44   -webkit-box-sizing: border-box;
    45   box-sizing: border-box;
    4633  width: 100%;
    4734  border: 1px solid #aaa;
     
    5643  cursor: pointer;
    5744}
     45.chosen-container .search-choice .group-name, .chosen-container .chosen-single .group-name {
     46  margin-right: 4px;
     47  overflow: hidden;
     48  white-space: nowrap;
     49  text-overflow: ellipsis;
     50  font-weight: normal;
     51  color: #999999;
     52}
     53.chosen-container .search-choice .group-name:after, .chosen-container .chosen-single .group-name:after {
     54  content: ":";
     55  padding-left: 2px;
     56  vertical-align: top;
     57}
    5858
    5959/* @end */
     
    6464  overflow: hidden;
    6565  padding: 0 0 0 8px;
    66   height: 23px;
     66  height: 25px;
    6767  border: 1px solid #aaa;
    6868  border-radius: 5px;
    6969  background-color: #fff;
    70   background: -moz-linear-gradient(top, #ffffff 20%, #f6f6f6 50%, #eeeeee 52%, #f4f4f4 100%);
    71   background: -o-linear-gradient(top, #ffffff 20%, #f6f6f6 50%, #eeeeee 52%, #f4f4f4 100%);
    72   background: -webkit-linear-gradient(top, #ffffff 20%, #f6f6f6 50%, #eeeeee 52%, #f4f4f4 100%);
    73   background: linear-gradient(to bottom, #ffffff 20%, #f6f6f6 50%, #eeeeee 52%, #f4f4f4 100%);
     70  background: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(20%, #ffffff), color-stop(50%, #f6f6f6), color-stop(52%, #eeeeee), color-stop(100%, #f4f4f4));
     71  background: -webkit-linear-gradient(#ffffff 20%, #f6f6f6 50%, #eeeeee 52%, #f4f4f4 100%);
     72  background: -moz-linear-gradient(#ffffff 20%, #f6f6f6 50%, #eeeeee 52%, #f4f4f4 100%);
     73  background: -o-linear-gradient(#ffffff 20%, #f6f6f6 50%, #eeeeee 52%, #f4f4f4 100%);
     74  background: linear-gradient(#ffffff 20%, #f6f6f6 50%, #eeeeee 52%, #f4f4f4 100%);
    7475  background-clip: padding-box;
    7576  box-shadow: 0 0 3px white inset, 0 1px 1px rgba(0, 0, 0, 0.1);
     
    130131}
    131132.chosen-container-single .chosen-search input[type="text"] {
    132   -moz-box-sizing: border-box;
    133   -webkit-box-sizing: border-box;
    134   box-sizing: border-box;
    135133  margin: 1px 0;
    136134  padding: 4px 20px 4px 5px;
     
    159157/* @group Results */
    160158.chosen-container .chosen-results {
     159  color: #444;
    161160  position: relative;
    162161  overflow-x: hidden;
     
    173172  list-style: none;
    174173  line-height: 15px;
     174  word-wrap: break-word;
    175175  -webkit-touch-callout: none;
    176176}
     
    186186.chosen-container .chosen-results li.highlighted {
    187187  background-color: #3875d7;
     188  background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(20%, #3875d7), color-stop(90%, #2a62bc));
     189  background-image: -webkit-linear-gradient(#3875d7 20%, #2a62bc 90%);
    188190  background-image: -moz-linear-gradient(#3875d7 20%, #2a62bc 90%);
    189191  background-image: -o-linear-gradient(#3875d7 20%, #2a62bc 90%);
    190   background-image: -webkit-linear-gradient(#3875d7 20%, #2a62bc 90%);
    191192  background-image: linear-gradient(#3875d7 20%, #2a62bc 90%);
    192193  color: #fff;
    193194}
    194195.chosen-container .chosen-results li.no-results {
     196  color: #777;
    195197  display: list-item;
    196198  background: #f4f4f4;
     
    214216  position: relative;
    215217  overflow: hidden;
    216   -moz-box-sizing: border-box;
    217   -webkit-box-sizing: border-box;
    218   box-sizing: border-box;
    219218  margin: 0;
    220   padding: 0;
     219  padding: 0 5px;
    221220  width: 100%;
    222   height: auto !important;
    223   height: 1%;
     221  height: auto;
    224222  border: 1px solid #aaa;
    225223  background-color: #fff;
     224  background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(1%, #eeeeee), color-stop(15%, #ffffff));
     225  background-image: -webkit-linear-gradient(#eeeeee 1%, #ffffff 15%);
    226226  background-image: -moz-linear-gradient(#eeeeee 1%, #ffffff 15%);
    227227  background-image: -o-linear-gradient(#eeeeee 1%, #ffffff 15%);
    228   background-image: -webkit-linear-gradient(#eeeeee 1%, #ffffff 15%);
    229228  background-image: linear-gradient(#eeeeee 1%, #ffffff 15%);
    230229  cursor: text;
     
    241240.chosen-container-multi .chosen-choices li.search-field input[type="text"] {
    242241  margin: 1px 0;
    243   padding: 5px;
    244   height: 15px;
     242  padding: 0;
     243  height: 25px;
    245244  outline: 0;
    246245  border: 0 !important;
    247246  background: transparent !important;
    248247  box-shadow: none;
    249   color: #666;
     248  color: #999;
    250249  font-size: 100%;
    251250  font-family: sans-serif;
     
    253252  border-radius: 0;
    254253}
    255 .chosen-container-multi .chosen-choices li.search-field .default {
    256   color: #999;
    257 }
    258254.chosen-container-multi .chosen-choices li.search-choice {
    259255  position: relative;
    260   margin: 3px 0 3px 5px;
     256  margin: 3px 5px 3px 0;
    261257  padding: 3px 20px 3px 5px;
    262258  border: 1px solid #aaa;
     259  max-width: 100%;
    263260  border-radius: 3px;
    264   background-color: #e4e4e4;
     261  background-color: #eeeeee;
     262  background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(20%, #f4f4f4), color-stop(50%, #f0f0f0), color-stop(52%, #e8e8e8), color-stop(100%, #eeeeee));
     263  background-image: -webkit-linear-gradient(#f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%);
    265264  background-image: -moz-linear-gradient(#f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%);
    266265  background-image: -o-linear-gradient(#f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%);
    267   background-image: -webkit-linear-gradient(#f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%);
    268266  background-image: linear-gradient(#f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%);
     267  background-size: 100% 19px;
     268  background-repeat: repeat-x;
    269269  background-clip: padding-box;
    270270  box-shadow: 0 0 2px white inset, 0 1px 0 rgba(0, 0, 0, 0.05);
     
    273273  cursor: default;
    274274}
     275.chosen-container-multi .chosen-choices li.search-choice span {
     276  word-wrap: break-word;
     277}
    275278.chosen-container-multi .chosen-choices li.search-choice .search-choice-close {
    276279  position: absolute;
     
    290293  border: 1px solid #ccc;
    291294  background-color: #e4e4e4;
    292   background-image: -moz-linear-gradient(top, #f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%);
    293   background-image: -o-linear-gradient(top, #f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%);
    294   background-image: -webkit-linear-gradient(top, #f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%);
    295   background-image: linear-gradient(to bottom, #f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%);
     295  background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(20%, #f4f4f4), color-stop(50%, #f0f0f0), color-stop(52%, #e8e8e8), color-stop(100%, #eeeeee));
     296  background-image: -webkit-linear-gradient(#f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%);
     297  background-image: -moz-linear-gradient(#f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%);
     298  background-image: -o-linear-gradient(#f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%);
     299  background-image: linear-gradient(#f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%);
    296300  color: #666;
    297301}
     
    324328  -moz-border-radius-bottomleft: 0;
    325329  border-bottom-left-radius: 0;
     330  background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(20%, #eeeeee), color-stop(80%, #ffffff));
     331  background-image: -webkit-linear-gradient(#eeeeee 20%, #ffffff 80%);
    326332  background-image: -moz-linear-gradient(#eeeeee 20%, #ffffff 80%);
    327333  background-image: -o-linear-gradient(#eeeeee 20%, #ffffff 80%);
    328   background-image: -webkit-linear-gradient(#eeeeee 20%, #ffffff 80%);
    329334  background-image: linear-gradient(#eeeeee 20%, #ffffff 80%);
    330335  box-shadow: 0 1px 0 #fff inset;
     
    342347}
    343348.chosen-container-active .chosen-choices li.search-field input[type="text"] {
    344   color: #111 !important;
     349  color: #222 !important;
    345350}
    346351
     
    427432/* @end */
    428433/* @group Retina compatibility */
    429 @media only screen and (-webkit-min-device-pixel-ratio: 2), only screen and (min-resolution: 144dpi) {
     434@media only screen and (-webkit-min-device-pixel-ratio: 1.5), only screen and (min-resolution: 144dpi), only screen and (min-resolution: 1.5dppx) {
    430435  .chosen-rtl .chosen-search input[type="text"],
    431436  .chosen-container-single .chosen-single abbr,
  • _plugins_/chosen/trunk/lib/chosen/chosen.jquery.js

    r95346 r98557  
    33by Patrick Filler for Harvest, http://getharvest.com
    44
    5 Version 1.1.0
     5Version 1.6.1
    66Full source at https://github.com/harvesthq/chosen
    7 Copyright (c) 2011 Harvest http://getharvest.com
     7Copyright (c) 2011-2016 Harvest http://getharvest.com
    88
    99MIT License, https://github.com/harvesthq/chosen/blob/master/LICENSE.md
    1010This file is generated by `grunt build`, do not edit it by hand.
    11 
    12 Attention : this is a forked version to add the create option (https://github.com/harvesthq/chosen/pull/166)
    13 This release is issued from https://github.com/koenpunt/chosen/releases
    1411*/
    1512
    1613(function() {
    17   var $, AbstractChosen, Chosen, ChosenOptionAdding, SelectParser, _ref, _ref1,
     14  var $, AbstractChosen, Chosen, SelectParser, _ref,
    1815    __hasProp = {}.hasOwnProperty,
    1916    __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; };
     
    4037        group: true,
    4138        label: this.escapeExpression(group.label),
     39        title: group.title ? group.title : void 0,
    4240        children: 0,
    43         disabled: group.disabled
     41        disabled: group.disabled,
     42        classes: group.className
    4443      });
    4544      _ref = group.childNodes;
     
    6463            text: option.text,
    6564            html: option.innerHTML,
     65            title: option.title ? option.title : void 0,
    6666            selected: option.selected,
    6767            disabled: group_disabled === true ? group_disabled : option.disabled,
    6868            group_array_index: group_position,
     69            group_label: group_position != null ? this.parsed[group_position].label : null,
    6970            classes: option.className,
    7071            style: option.style.cssText
     
    130131      this.set_up_html();
    131132      this.register_observers();
     133      this.on_ready();
    132134    }
    133135
     
    154156      this.inherit_select_classes = this.options.inherit_select_classes || false;
    155157      this.display_selected_options = this.options.display_selected_options != null ? this.options.display_selected_options : true;
    156       return this.display_disabled_options = this.options.display_disabled_options != null ? this.options.display_disabled_options : true;
     158      this.display_disabled_options = this.options.display_disabled_options != null ? this.options.display_disabled_options : true;
     159      this.include_group_label_in_selected = this.options.include_group_label_in_selected || false;
     160      this.max_shown_results = this.options.max_shown_results || Number.POSITIVE_INFINITY;
     161      return this.case_sensitive_search = this.options.case_sensitive_search || false;
    157162    };
    158163
     
    166171      }
    167172      return this.results_none_found = this.form_field.getAttribute("data-no_results_text") || this.options.no_results_text || AbstractChosen.default_no_result_text;
     173    };
     174
     175    AbstractChosen.prototype.choice_label = function(item) {
     176      if (this.include_group_label_in_selected && (item.group_label != null)) {
     177        return "<b class='group-name'>" + item.group_label + "</b>" + item.html;
     178      } else {
     179        return item.html;
     180      }
    168181    };
    169182
     
    202215
    203216    AbstractChosen.prototype.results_option_build = function(options) {
    204       var content, data, _i, _len, _ref;
     217      var content, data, data_content, shown_results, _i, _len, _ref;
    205218      content = '';
     219      shown_results = 0;
    206220      _ref = this.results_data;
    207221      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
    208222        data = _ref[_i];
     223        data_content = '';
    209224        if (data.group) {
    210           content += this.result_add_group(data);
     225          data_content = this.result_add_group(data);
    211226        } else {
    212           content += this.result_add_option(data);
     227          data_content = this.result_add_option(data);
     228        }
     229        if (data_content !== '') {
     230          shown_results++;
     231          content += data_content;
    213232        }
    214233        if (options != null ? options.first : void 0) {
     
    216235            this.choice_build(data);
    217236          } else if (data.selected && !this.is_multiple) {
    218             this.single_set_selected_text(data.text);
    219           }
     237            this.single_set_selected_text(this.choice_label(data));
     238          }
     239        }
     240        if (shown_results >= this.max_shown_results) {
     241          break;
    220242        }
    221243      }
     
    252274      option_el.setAttribute("data-option-array-index", option.array_index);
    253275      option_el.innerHTML = option.search_text;
     276      if (option.title) {
     277        option_el.title = option.title;
     278      }
    254279      return this.outerHTML(option_el);
    255280    };
    256281
    257282    AbstractChosen.prototype.result_add_group = function(group) {
    258       var group_el;
     283      var classes, group_el;
    259284      if (!(group.search_match || group.group_match)) {
    260285        return '';
     
    263288        return '';
    264289      }
     290      classes = [];
     291      classes.push("group-result");
     292      if (group.classes) {
     293        classes.push(group.classes);
     294      }
    265295      group_el = document.createElement("li");
    266       group_el.className = "group-result";
     296      group_el.className = classes.join(" ");
    267297      group_el.innerHTML = group.search_text;
     298      if (group.title) {
     299        group_el.title = group.title;
     300      }
    268301      return this.outerHTML(group_el);
    269302    };
     
    313346
    314347    AbstractChosen.prototype.winnow_results = function() {
    315       var escapedSearchText, option, regex, regexAnchor, results, results_group, searchText, startpos, text, zregex, _i, _len, _ref;
     348      var escapedSearchText, option, regex, results, results_group, searchText, startpos, text, zregex, _i, _len, _ref;
    316349      this.no_results_clear();
    317350      results = 0;
    318351      searchText = this.get_search_text();
    319352      escapedSearchText = searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
    320       regexAnchor = this.search_contains ? "" : "^";
    321       regex = new RegExp(regexAnchor + escapedSearchText, 'i');
    322353      zregex = new RegExp(escapedSearchText, 'i');
     354      regex = this.get_search_regex(escapedSearchText);
    323355      _ref = this.results_data;
    324356      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
     
    338370            results_group.active_options += 1;
    339371          }
     372          option.search_text = option.group ? option.label : option.html;
    340373          if (!(option.group && !this.group_search)) {
    341             option.search_text = option.group ? option.label : option.html;
    342374            option.search_match = this.search_string_match(option.search_text, regex);
    343375            if (option.search_match && !option.group) {
     
    369401    };
    370402
     403    AbstractChosen.prototype.get_search_regex = function(escaped_search_string) {
     404      var regex_anchor, regex_flag;
     405      regex_anchor = this.search_contains ? "" : "^";
     406      regex_flag = this.case_sensitive_search ? "" : "i";
     407      return new RegExp(regex_anchor + escaped_search_string, regex_flag);
     408    };
     409
    371410    AbstractChosen.prototype.search_string_match = function(search_string, regex) {
    372411      var part, parts, _i, _len;
     
    439478        case 91:
    440479        case 17:
     480        case 18:
    441481          break;
    442482        default:
    443483          return this.results_search();
    444484      }
     485    };
     486
     487    AbstractChosen.prototype.clipboard_event_checker = function(evt) {
     488      var _this = this;
     489      return setTimeout((function() {
     490        return _this.results_search();
     491      }), 50);
    445492    };
    446493
     
    493540
    494541    AbstractChosen.browser_is_supported = function() {
    495       if (window.navigator.appName === "Microsoft Internet Explorer") {
     542      if ("Microsoft Internet Explorer" === window.navigator.appName) {
    496543        return document.documentMode >= 8;
    497544      }
    498       if (/iP(od|hone)/i.test(window.navigator.userAgent)) {
     545      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)) {
    499546        return false;
    500       }
    501       if (/Android/i.test(window.navigator.userAgent)) {
    502         if (/Mobile/i.test(window.navigator.userAgent)) {
    503           return false;
    504         }
    505547      }
    506548      return true;
     
    528570        $this = $(this);
    529571        chosen = $this.data('chosen');
    530         if (options === 'destroy' && chosen) {
    531           chosen.destroy();
    532         } else if (!chosen) {
     572        if (options === 'destroy') {
     573          if (chosen instanceof Chosen) {
     574            chosen.destroy();
     575          }
     576          return;
     577        }
     578        if (!(chosen instanceof Chosen)) {
    533579          $this.data('chosen', new Chosen(this, options));
    534580        }
     
    573619        this.container.html('<ul class="chosen-choices"><li class="search-field"><input type="text" value="' + this.default_text + '" class="default" autocomplete="off" style="width:25px;" /></li></ul><div class="chosen-drop"><ul class="chosen-results"></ul></div>');
    574620      } else {
    575         this.container.html('<a class="chosen-single chosen-default" tabindex="-1"><span>' + this.default_text + '</span><div><b></b></div></a><div class="chosen-drop"><div class="chosen-search"><input type="text" autocomplete="off" /></div><ul class="chosen-results"></ul></div>');
     621        this.container.html('<a class="chosen-single chosen-default"><span>' + this.default_text + '</span><div><b></b></div></a><div class="chosen-drop"><div class="chosen-search"><input type="text" autocomplete="off" /></div><ul class="chosen-results"></ul></div>');
    576622      }
    577623      this.form_field_jq.hide().after(this.container);
     
    590636      this.results_build();
    591637      this.set_tab_index();
    592       this.set_label_behavior();
     638      return this.set_label_behavior();
     639    };
     640
     641    Chosen.prototype.on_ready = function() {
    593642      return this.form_field_jq.trigger("chosen:ready", {
    594643        chosen: this
     
    598647    Chosen.prototype.register_observers = function() {
    599648      var _this = this;
     649      this.container.bind('touchstart.chosen', function(evt) {
     650        _this.container_mousedown(evt);
     651        return evt.preventDefault();
     652      });
     653      this.container.bind('touchend.chosen', function(evt) {
     654        _this.container_mouseup(evt);
     655        return evt.preventDefault();
     656      });
    600657      this.container.bind('mousedown.chosen', function(evt) {
    601658        _this.container_mousedown(evt);
     
    640697        _this.container_mousedown(evt);
    641698      });
     699      this.form_field_jq.bind("chosen:close.chosen", function(evt) {
     700        _this.input_blur(evt);
     701      });
    642702      this.search_field.bind('blur.chosen', function(evt) {
    643703        _this.input_blur(evt);
     
    651711      this.search_field.bind('focus.chosen', function(evt) {
    652712        _this.input_focus(evt);
     713      });
     714      this.search_field.bind('cut.chosen', function(evt) {
     715        _this.clipboard_event_checker(evt);
     716      });
     717      this.search_field.bind('paste.chosen', function(evt) {
     718        _this.clipboard_event_checker(evt);
    653719      });
    654720      if (this.is_multiple) {
     
    664730
    665731    Chosen.prototype.destroy = function() {
    666       $(document).unbind("click.chosen", this.click_test_action);
     732      $(this.container[0].ownerDocument).unbind("click.chosen", this.click_test_action);
    667733      if (this.search_field[0].tabIndex) {
    668734        this.form_field_jq[0].tabIndex = this.search_field[0].tabIndex;
     
    701767              this.search_field.val("");
    702768            }
    703             $(document).bind('click.chosen', this.click_test_action);
     769            $(this.container[0].ownerDocument).bind('click.chosen', this.click_test_action);
    704770            this.results_show();
    705771          } else if (!this.is_multiple && evt && (($(evt.target)[0] === this.selected_item[0]) || $(evt.target).parents("a.chosen-single").length)) {
     
    721787      var delta;
    722788      if (evt.originalEvent) {
    723         delta = -evt.originalEvent.wheelDelta || evt.originalEvent.detail;
     789        delta = evt.originalEvent.deltaY || -evt.originalEvent.wheelDelta || evt.originalEvent.detail;
    724790      }
    725791      if (delta != null) {
     
    739805
    740806    Chosen.prototype.close_field = function() {
    741       $(document).unbind("click.chosen", this.click_test_action);
     807      $(this.container[0].ownerDocument).unbind("click.chosen", this.click_test_action);
    742808      this.active_field = false;
    743809      this.results_hide();
     
    756822
    757823    Chosen.prototype.test_active_click = function(evt) {
    758       if (this.container.is($(evt.target).closest('.chosen-container'))) {
     824      var active_container;
     825      active_container = $(evt.target).closest('.chosen-container');
     826      if (active_container.length && this.container[0] === active_container[0]) {
    759827        return this.active_field = true;
    760828      } else {
     
    769837      if (this.is_multiple) {
    770838        this.search_choices.find("li.search-choice").remove();
    771       } else {
     839      } else if (!this.is_multiple) {
    772840        this.single_set_selected_text();
    773         this.single_set_nosearch();
     841        if (this.disable_search || this.form_field.options.length <= this.disable_search_threshold) {
     842          this.search_field[0].readOnly = true;
     843          this.container.addClass("chosen-container-single-nosearch");
     844        } else {
     845          this.search_field[0].readOnly = false;
     846          this.container.removeClass("chosen-container-single-nosearch");
     847        }
    774848      }
    775849      this.update_results_content(this.results_option_build({
     
    780854      this.search_field_scale();
    781855      return this.parsing = false;
    782     };
    783 
    784     Chosen.prototype.single_set_nosearch = function() {
    785       if (this.disable_search || this.form_field.options.length <= this.disable_search_threshold) {
    786         this.search_field[0].readOnly = true;
    787         return this.container.addClass("chosen-container-single-nosearch");
    788       } else {
    789         this.search_field[0].readOnly = false;
    790         return this.container.removeClass("chosen-container-single-nosearch");
    791       }
    792856    };
    793857
     
    826890      }
    827891      this.container.addClass("chosen-with-drop");
    828       this.form_field_jq.trigger("chosen:showing_dropdown", {
    829         chosen: this
    830       });
    831892      this.results_showing = true;
    832893      this.search_field.focus();
    833894      this.search_field.val(this.search_field.val());
    834       return this.winnow_results();
     895      this.winnow_results();
     896      return this.form_field_jq.trigger("chosen:showing_dropdown", {
     897        chosen: this
     898      });
    835899    };
    836900
     
    915979      choice = $('<li />', {
    916980        "class": "search-choice"
    917       }).html("<span>" + item.html + "</span>");
     981      }).html("<span>" + (this.choice_label(item)) + "</span>");
    918982      if (item.disabled) {
    919983        choice.addClass('search-choice-disabled');
     
    9831047          this.reset_single_select_options();
    9841048        }
     1049        high.addClass("result-selected");
    9851050        item = this.results_data[high[0].getAttribute("data-option-array-index")];
    9861051        item.selected = true;
     
    9901055          this.choice_build(item);
    9911056        } else {
    992           this.single_set_selected_text(item.text);
     1057          this.single_set_selected_text(this.choice_label(item));
    9931058        }
    9941059        if (!((evt.metaKey || evt.ctrlKey) && this.is_multiple)) {
    9951060          this.results_hide();
    9961061        }
    997         this.search_field.val("");
     1062        this.show_search_field_default();
    9981063        if (this.is_multiple || this.form_field.selectedIndex !== this.current_selectedIndex) {
    9991064          this.form_field_jq.trigger("change", {
     
    10021067        }
    10031068        this.current_selectedIndex = this.form_field.selectedIndex;
     1069        evt.preventDefault();
    10041070        return this.search_field_scale();
    10051071      }
     
    10161082        this.selected_item.removeClass("chosen-default");
    10171083      }
    1018       return this.selected_item.find("span").text(text);
     1084      return this.selected_item.find("span").html(text);
    10191085    };
    10201086
     
    10511117
    10521118    Chosen.prototype.get_search_text = function() {
    1053       if (this.search_field.val() === this.default_text) {
    1054         return "";
    1055       } else {
    1056         return $('<div/>').text($.trim(this.search_field.val())).html();
    1057       }
     1119      return $('<div/>').text($.trim(this.search_field.val())).html();
    10581120    };
    10591121
     
    10711133      no_results_html = $('<li class="no-results">' + this.results_none_found + ' "<span></span>"</li>');
    10721134      no_results_html.find("span").first().html(terms);
    1073       return this.search_results.append(no_results_html);
     1135      this.search_results.append(no_results_html);
     1136      return this.form_field_jq.trigger("chosen:no_results", {
     1137        chosen: this
     1138      });
    10741139    };
    10751140
     
    11501215          break;
    11511216        case 13:
    1152           evt.preventDefault();
     1217          if (this.results_showing) {
     1218            evt.preventDefault();
     1219          }
     1220          break;
     1221        case 32:
     1222          if (this.disable_search) {
     1223            evt.preventDefault();
     1224          }
    11531225          break;
    11541226        case 38:
     
    11951267  })(AbstractChosen);
    11961268
    1197   $ = jQuery;
    1198 
    1199   $.fn.extend({
    1200     chosen: function(options) {
    1201       if (!AbstractChosen.browser_is_supported()) {
    1202         return this;
    1203       }
    1204       return this.each(function(input_field) {
    1205         var $this, chosen;
    1206         $this = $(this);
    1207         chosen = $this.data('chosen');
    1208         if (options === 'destroy' && chosen) {
    1209           chosen.destroy();
    1210         } else if (!chosen) {
    1211           $this.data('chosen', new ChosenOptionAdding(this, options));
    1212         }
    1213       });
    1214     }
    1215   });
    1216 
    1217   ChosenOptionAdding = (function(_super) {
    1218     __extends(ChosenOptionAdding, _super);
    1219 
    1220     function ChosenOptionAdding() {
    1221       _ref1 = ChosenOptionAdding.__super__.constructor.apply(this, arguments);
    1222       return _ref1;
    1223     }
    1224 
    1225     ChosenOptionAdding.prototype.set_default_values = function() {
    1226       ChosenOptionAdding.__super__.set_default_values.apply(this, arguments);
    1227       this.create_option = this.options.create_option || false;
    1228       this.persistent_create_option = this.options.persistent_create_option || false;
    1229       return this.skip_no_results = this.options.skip_no_results || false;
    1230     };
    1231 
    1232     ChosenOptionAdding.prototype.set_default_text = function() {
    1233       ChosenOptionAdding.__super__.set_default_text.apply(this, arguments);
    1234       return this.create_option_text = this.form_field.getAttribute("data-create_option_text") || this.options.create_option_text || 'Add option ';
    1235     };
    1236 
    1237     ChosenOptionAdding.prototype.single_set_nosearch = function() {
    1238       if (this.disable_search || this.form_field.options.length <= this.disable_search_threshold && !this.create_option) {
    1239         this.search_field[0].readOnly = true;
    1240         return this.container.addClass("chosen-container-single-nosearch");
    1241       } else {
    1242         this.search_field[0].readOnly = false;
    1243         return this.container.removeClass("chosen-container-single-nosearch");
    1244       }
    1245     };
    1246 
    1247     ChosenOptionAdding.prototype.result_select = function(evt) {
    1248       if (this.result_highlight) {
    1249         if (this.result_highlight.hasClass("create-option")) {
    1250           this.select_create_option(this.search_field.val());
    1251           return this.results_hide();
    1252         }
    1253         return ChosenOptionAdding.__super__.result_select.apply(this, arguments);
    1254       }
    1255     };
    1256 
    1257     ChosenOptionAdding.prototype.show_create_option = function(terms) {
    1258       var create_option_html;
    1259       create_option_html = $('<li class="create-option active-result"><a>' + this.create_option_text + '</a>: "' + terms + '"</li>');
    1260       return this.search_results.append(create_option_html);
    1261     };
    1262 
    1263     ChosenOptionAdding.prototype.create_option_clear = function() {
    1264       return this.search_results.find(".create-option").remove();
    1265     };
    1266 
    1267     ChosenOptionAdding.prototype.select_create_option = function(terms) {
    1268       if ($.isFunction(this.create_option)) {
    1269         return this.create_option.call(this, terms);
    1270       } else {
    1271         return this.select_append_option({
    1272           value: terms,
    1273           text: terms
    1274         });
    1275       }
    1276     };
    1277 
    1278     ChosenOptionAdding.prototype.select_append_option = function(options) {
    1279       var option;
    1280       option = $('<option />', options).attr('selected', 'selected');
    1281       this.form_field_jq.append(option);
    1282       this.form_field_jq.trigger("chosen:updated");
    1283       this.form_field_jq.trigger("change");
    1284       return this.search_field.trigger("focus");
    1285     };
    1286 
    1287     ChosenOptionAdding.prototype.append_option = function(option) {
    1288       return this.select_append_option(option);
    1289     };
    1290 
    1291     ChosenOptionAdding.prototype.no_results = function(terms) {
    1292       if (!(this.create_option && this.skip_no_results)) {
    1293         return ChosenOptionAdding.__super__.no_results.call(this, terms);
    1294       }
    1295     };
    1296 
    1297     ChosenOptionAdding.prototype.keydown_arrow = function() {
    1298       var next_sib;
    1299       if (this.results_showing && this.result_highlight) {
    1300         next_sib = this.result_highlight.nextAll("li.active-result").first();
    1301         if (next_sib) {
    1302           return this.result_do_highlight(next_sib);
    1303         }
    1304       } else if (this.results_showing && this.create_option) {
    1305         return this.result_do_highlight(this.search_results.find('.create-option'));
    1306       } else {
    1307         return this.results_show();
    1308       }
    1309     };
    1310 
    1311     ChosenOptionAdding.prototype.winnow_results = function() {
    1312       var eregex, escapedSearchText, exact_result, option, regex, regexAnchor, results, results_group, searchText, startpos, text, zregex, _i, _len, _ref2;
    1313       this.no_results_clear();
    1314       results = 0;
    1315       exact_result = false;
    1316       searchText = this.get_search_text();
    1317       escapedSearchText = searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
    1318       regexAnchor = this.search_contains ? "" : "^";
    1319       regex = new RegExp(regexAnchor + escapedSearchText, 'i');
    1320       zregex = new RegExp(escapedSearchText, 'i');
    1321       eregex = new RegExp('^' + escapedSearchText + '$', 'i');
    1322       _ref2 = this.results_data;
    1323       for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
    1324         option = _ref2[_i];
    1325         option.search_match = false;
    1326         results_group = null;
    1327         if (this.include_option_in_results(option)) {
    1328           if (option.group) {
    1329             option.group_match = false;
    1330             option.active_options = 0;
    1331           }
    1332           if ((option.group_array_index != null) && this.results_data[option.group_array_index]) {
    1333             results_group = this.results_data[option.group_array_index];
    1334             if (results_group.active_options === 0 && results_group.search_match) {
    1335               results += 1;
    1336             }
    1337             results_group.active_options += 1;
    1338           }
    1339           if (!(option.group && !this.group_search)) {
    1340             option.search_text = option.group ? option.label : option.html;
    1341             option.search_match = this.search_string_match(option.search_text, regex);
    1342             if (option.search_match && !option.group) {
    1343               results += 1;
    1344             }
    1345             exact_result = eregex.test(option.html);
    1346             if (option.search_match) {
    1347               if (searchText.length) {
    1348                 startpos = option.search_text.search(zregex);
    1349                 text = option.search_text.substr(0, startpos + searchText.length) + '</em>' + option.search_text.substr(startpos + searchText.length);
    1350                 option.search_text = text.substr(0, startpos) + '<em>' + text.substr(startpos);
    1351               }
    1352               if (results_group != null) {
    1353                 results_group.group_match = true;
    1354               }
    1355             } else if ((option.group_array_index != null) && this.results_data[option.group_array_index].search_match) {
    1356               option.search_match = true;
    1357             }
    1358           }
    1359         }
    1360       }
    1361       this.result_clear_highlight();
    1362       if (results < 1 && searchText.length) {
    1363         this.update_results_content("");
    1364         if (!(this.create_option && this.skip_no_results)) {
    1365           this.no_results(searchText);
    1366         }
    1367       } else {
    1368         this.update_results_content(this.results_option_build());
    1369         this.winnow_results_set_highlight();
    1370       }
    1371       if (this.create_option && (results < 1 || (!exact_result && this.persistent_create_option)) && searchText.length) {
    1372         return this.show_create_option(searchText);
    1373       }
    1374     };
    1375 
    1376     return ChosenOptionAdding;
    1377 
    1378   })(Chosen);
    1379 
    13801269}).call(this);
  • _plugins_/chosen/trunk/lib/chosen/chosen.jquery.min.js

    r89038 r98557  
    1 /* Chosen v1.1.0 | (c) 2011-2013 by Harvest | MIT License, https://github.com/harvesthq/chosen/blob/master/LICENSE.md */
    2 !function(){var a,AbstractChosen,Chosen,SelectParser,b,c={}.hasOwnProperty,d=function(a,b){function d(){this.constructor=a}for(var e in b)c.call(b,e)&&(a[e]=b[e]);return d.prototype=b.prototype,a.prototype=new d,a.__super__=b.prototype,a};SelectParser=function(){function SelectParser(){this.options_index=0,this.parsed=[]}return SelectParser.prototype.add_node=function(a){return"OPTGROUP"===a.nodeName.toUpperCase()?this.add_group(a):this.add_option(a)},SelectParser.prototype.add_group=function(a){var b,c,d,e,f,g;for(b=this.parsed.length,this.parsed.push({array_index:b,group:!0,label:this.escapeExpression(a.label),children:0,disabled:a.disabled}),f=a.childNodes,g=[],d=0,e=f.length;e>d;d++)c=f[d],g.push(this.add_option(c,b,a.disabled));return g},SelectParser.prototype.add_option=function(a,b,c){return"OPTION"===a.nodeName.toUpperCase()?(""!==a.text?(null!=b&&(this.parsed[b].children+=1),this.parsed.push({array_index:this.parsed.length,options_index:this.options_index,value:a.value,text:a.text,html:a.innerHTML,selected:a.selected,disabled:c===!0?c:a.disabled,group_array_index:b,classes:a.className,style:a.style.cssText})):this.parsed.push({array_index:this.parsed.length,options_index:this.options_index,empty:!0}),this.options_index+=1):void 0},SelectParser.prototype.escapeExpression=function(a){var b,c;return null==a||a===!1?"":/[\&\<\>\"\'\`]/.test(a)?(b={"<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;","`":"&#x60;"},c=/&(?!\w+;)|[\<\>\"\'\`]/g,a.replace(c,function(a){return b[a]||"&amp;"})):a},SelectParser}(),SelectParser.select_to_array=function(a){var b,c,d,e,f;for(c=new SelectParser,f=a.childNodes,d=0,e=f.length;e>d;d++)b=f[d],c.add_node(b);return c.parsed},AbstractChosen=function(){function AbstractChosen(a,b){this.form_field=a,this.options=null!=b?b:{},AbstractChosen.browser_is_supported()&&(this.is_multiple=this.form_field.multiple,this.set_default_text(),this.set_default_values(),this.setup(),this.set_up_html(),this.register_observers())}return AbstractChosen.prototype.set_default_values=function(){var a=this;return this.click_test_action=function(b){return a.test_active_click(b)},this.activate_action=function(b){return a.activate_field(b)},this.active_field=!1,this.mouse_on_container=!1,this.results_showing=!1,this.result_highlighted=null,this.allow_single_deselect=null!=this.options.allow_single_deselect&&null!=this.form_field.options[0]&&""===this.form_field.options[0].text?this.options.allow_single_deselect:!1,this.disable_search_threshold=this.options.disable_search_threshold||0,this.disable_search=this.options.disable_search||!1,this.enable_split_word_search=null!=this.options.enable_split_word_search?this.options.enable_split_word_search:!0,this.group_search=null!=this.options.group_search?this.options.group_search:!0,this.search_contains=this.options.search_contains||!1,this.single_backstroke_delete=null!=this.options.single_backstroke_delete?this.options.single_backstroke_delete:!0,this.max_selected_options=this.options.max_selected_options||1/0,this.inherit_select_classes=this.options.inherit_select_classes||!1,this.display_selected_options=null!=this.options.display_selected_options?this.options.display_selected_options:!0,this.display_disabled_options=null!=this.options.display_disabled_options?this.options.display_disabled_options:!0,this.create_option=this.options.create_option||!1,this.persistent_create_option=this.options.persistent_create_option||!1,this.skip_no_results=this.options.skip_no_results||!1},AbstractChosen.prototype.set_default_text=function(){return this.default_text=this.form_field.getAttribute("data-placeholder")?this.form_field.getAttribute("data-placeholder"):this.is_multiple?this.options.placeholder_text_multiple||this.options.placeholder_text||AbstractChosen.default_multiple_text:this.options.placeholder_text_single||this.options.placeholder_text||AbstractChosen.default_single_text,this.results_none_found=this.form_field.getAttribute("data-no_results_text")||this.options.no_results_text||AbstractChosen.default_no_result_text,this.create_option_text=this.form_field.getAttribute("data-create_option_text")||this.options.create_option_text||AbstractChosen.default_create_option_text},AbstractChosen.prototype.mouse_enter=function(){return this.mouse_on_container=!0},AbstractChosen.prototype.mouse_leave=function(){return this.mouse_on_container=!1},AbstractChosen.prototype.input_focus=function(){var a=this;if(this.is_multiple){if(!this.active_field)return setTimeout(function(){return a.container_mousedown()},50)}else if(!this.active_field)return this.activate_field()},AbstractChosen.prototype.input_blur=function(){var a=this;return this.mouse_on_container?void 0:(this.active_field=!1,setTimeout(function(){return a.blur_test()},100))},AbstractChosen.prototype.results_option_build=function(a){var b,c,d,e,f;for(b="",f=this.results_data,d=0,e=f.length;e>d;d++)c=f[d],b+=c.group?this.result_add_group(c):this.result_add_option(c),(null!=a?a.first:void 0)&&(c.selected&&this.is_multiple?this.choice_build(c):c.selected&&!this.is_multiple&&this.single_set_selected_text(c.text));return b},AbstractChosen.prototype.result_add_option=function(a){var b,c;return a.search_match?this.include_option_in_results(a)?(b=[],a.disabled||a.selected&&this.is_multiple||b.push("active-result"),!a.disabled||a.selected&&this.is_multiple||b.push("disabled-result"),a.selected&&b.push("result-selected"),null!=a.group_array_index&&b.push("group-option"),""!==a.classes&&b.push(a.classes),c=document.createElement("li"),c.className=b.join(" "),c.style.cssText=a.style,c.setAttribute("data-option-array-index",a.array_index),c.innerHTML=a.search_text,this.outerHTML(c)):"":""},AbstractChosen.prototype.result_add_group=function(a){var b;return a.search_match||a.group_match?a.active_options>0?(b=document.createElement("li"),b.className="group-result",b.innerHTML=a.search_text,this.outerHTML(b)):"":""},AbstractChosen.prototype.append_option=function(a){return this.select_append_option(a)},AbstractChosen.prototype.results_update_field=function(){return this.set_default_text(),this.is_multiple||this.results_reset_cleanup(),this.result_clear_highlight(),this.results_build(),this.results_showing?this.winnow_results():void 0},AbstractChosen.prototype.reset_single_select_options=function(){var a,b,c,d,e;for(d=this.results_data,e=[],b=0,c=d.length;c>b;b++)a=d[b],a.selected?e.push(a.selected=!1):e.push(void 0);return e},AbstractChosen.prototype.results_toggle=function(){return this.results_showing?this.results_hide():this.results_show()},AbstractChosen.prototype.results_search=function(){return this.results_showing?this.winnow_results():this.results_show()},AbstractChosen.prototype.winnow_results=function(){var a,b,c,d,e,f,g,h,i,j,k,l,m,n,o;for(this.no_results_clear(),g=0,c=!1,i=this.get_search_text(),b=i.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),f=this.search_contains?"":"^",e=new RegExp(f+b,"i"),l=new RegExp(b,"i"),a=new RegExp("^"+b+"$","i"),o=this.results_data,m=0,n=o.length;n>m;m++)d=o[m],d.search_match=!1,h=null,this.include_option_in_results(d)&&(d.group&&(d.group_match=!1,d.active_options=0),null!=d.group_array_index&&this.results_data[d.group_array_index]&&(h=this.results_data[d.group_array_index],0===h.active_options&&h.search_match&&(g+=1),h.active_options+=1),(!d.group||this.group_search)&&(d.search_text=d.group?d.label:d.html,d.search_match=this.search_string_match(d.search_text,e),d.search_match&&!d.group&&(g+=1),c=a.test(d.html),d.search_match?(i.length&&(j=d.search_text.search(l),k=d.search_text.substr(0,j+i.length)+"</em>"+d.search_text.substr(j+i.length),d.search_text=k.substr(0,j)+"<em>"+k.substr(j)),null!=h&&(h.group_match=!0)):null!=d.group_array_index&&this.results_data[d.group_array_index].search_match&&(d.search_match=!0)));return this.result_clear_highlight(),1>g&&i.length?(this.update_results_content(""),this.create_option&&this.skip_no_results||this.no_results(i)):(this.update_results_content(this.results_option_build()),this.winnow_results_set_highlight()),this.create_option&&(1>g||!c&&this.persistent_create_option)&&i.length?this.show_create_option(i):void 0},AbstractChosen.prototype.search_string_match=function(a,b){var c,d,e,f;if(b.test(a))return!0;if(this.enable_split_word_search&&(a.indexOf(" ")>=0||0===a.indexOf("["))&&(d=a.replace(/\[|\]/g,"").split(" "),d.length))for(e=0,f=d.length;f>e;e++)if(c=d[e],b.test(c))return!0},AbstractChosen.prototype.choices_count=function(){var a,b,c,d;if(null!=this.selected_option_count)return this.selected_option_count;for(this.selected_option_count=0,d=this.form_field.options,b=0,c=d.length;c>b;b++)a=d[b],a.selected&&(this.selected_option_count+=1);return this.selected_option_count},AbstractChosen.prototype.choices_click=function(a){return a.preventDefault(),this.results_showing||this.is_disabled?void 0:this.results_show()},AbstractChosen.prototype.keyup_checker=function(a){var b,c;switch(b=null!=(c=a.which)?c:a.keyCode,this.search_field_scale(),b){case 8:if(this.is_multiple&&this.backstroke_length<1&&this.choices_count()>0)return this.keydown_backstroke();if(!this.pending_backstroke)return this.result_clear_highlight(),this.results_search();break;case 13:if(a.preventDefault(),this.results_showing)return this.result_select(a);break;case 27:return this.results_showing&&this.results_hide(),!0;case 9:case 38:case 40:case 16:case 91:case 17:break;default:return this.results_search()}},AbstractChosen.prototype.clipboard_event_checker=function(){var a=this;return setTimeout(function(){return a.results_search()},50)},AbstractChosen.prototype.container_width=function(){return null!=this.options.width?this.options.width:""+this.form_field.offsetWidth+"px"},AbstractChosen.prototype.include_option_in_results=function(a){return this.is_multiple&&!this.display_selected_options&&a.selected?!1:!this.display_disabled_options&&a.disabled?!1:a.empty?!1:!0},AbstractChosen.prototype.search_results_touchstart=function(a){return this.touch_started=!0,this.search_results_mouseover(a)},AbstractChosen.prototype.search_results_touchmove=function(a){return this.touch_started=!1,this.search_results_mouseout(a)},AbstractChosen.prototype.search_results_touchend=function(a){return this.touch_started?this.search_results_mouseup(a):void 0},AbstractChosen.prototype.outerHTML=function(a){var b;return a.outerHTML?a.outerHTML:(b=document.createElement("div"),b.appendChild(a),b.innerHTML)},AbstractChosen.browser_is_supported=function(){return"Microsoft Internet Explorer"===window.navigator.appName?document.documentMode>=8:/iP(od|hone)/i.test(window.navigator.userAgent)?!1:/Android/i.test(window.navigator.userAgent)&&/Mobile/i.test(window.navigator.userAgent)?!1:!0},AbstractChosen.default_multiple_text="Select Some Options",AbstractChosen.default_single_text="Select an Option",AbstractChosen.default_no_result_text="No results match",AbstractChosen.default_create_option_text="Add Option",AbstractChosen}(),a=jQuery,a.fn.extend({chosen:function(b){return AbstractChosen.browser_is_supported()?this.each(function(){var c,d;c=a(this),d=c.data("chosen"),"destroy"===b&&d?d.destroy():d||c.data("chosen",new Chosen(this,b))}):this}}),Chosen=function(c){function Chosen(){return b=Chosen.__super__.constructor.apply(this,arguments)}return d(Chosen,c),Chosen.prototype.setup=function(){return this.form_field_jq=a(this.form_field),this.current_selectedIndex=this.form_field.selectedIndex,this.is_rtl=this.form_field_jq.hasClass("chosen-rtl")},Chosen.prototype.set_up_html=function(){var b,c;return b=["chosen-container"],b.push("chosen-container-"+(this.is_multiple?"multi":"single")),this.inherit_select_classes&&this.form_field.className&&b.push(this.form_field.className),this.is_rtl&&b.push("chosen-rtl"),c={"class":b.join(" "),style:"width: "+this.container_width()+";",title:this.form_field.title},this.form_field.id.length&&(c.id=this.form_field.id.replace(/[^\w]/g,"_")+"_chosen"),this.container=a("<div />",c),this.is_multiple?this.container.html('<ul class="chosen-choices"><li class="search-field"><input type="text" value="'+this.default_text+'" class="default" autocomplete="off" style="width:25px;" /></li></ul><div class="chosen-drop"><ul class="chosen-results"></ul></div>'):this.container.html('<a class="chosen-single chosen-default" tabindex="-1"><span>'+this.default_text+'</span><div><b></b></div></a><div class="chosen-drop"><div class="chosen-search"><input type="text" autocomplete="off" /></div><ul class="chosen-results"></ul></div>'),this.form_field_jq.hide().after(this.container),this.dropdown=this.container.find("div.chosen-drop").first(),this.search_field=this.container.find("input").first(),this.search_results=this.container.find("ul.chosen-results").first(),this.search_field_scale(),this.search_no_results=this.container.find("li.no-results").first(),this.is_multiple?(this.search_choices=this.container.find("ul.chosen-choices").first(),this.search_container=this.container.find("li.search-field").first()):(this.search_container=this.container.find("div.chosen-search").first(),this.selected_item=this.container.find(".chosen-single").first()),this.results_build(),this.set_tab_index(),this.set_label_behavior(),this.form_field_jq.trigger("chosen:ready",{chosen:this})},Chosen.prototype.register_observers=function(){var a=this;return this.container.bind("mousedown.chosen",function(b){a.container_mousedown(b)}),this.container.bind("mouseup.chosen",function(b){a.container_mouseup(b)}),this.container.bind("mouseenter.chosen",function(b){a.mouse_enter(b)}),this.container.bind("mouseleave.chosen",function(b){a.mouse_leave(b)}),this.search_results.bind("mouseup.chosen",function(b){a.search_results_mouseup(b)}),this.search_results.bind("mouseover.chosen",function(b){a.search_results_mouseover(b)}),this.search_results.bind("mouseout.chosen",function(b){a.search_results_mouseout(b)}),this.search_results.bind("mousewheel.chosen DOMMouseScroll.chosen",function(b){a.search_results_mousewheel(b)}),this.search_results.bind("touchstart.chosen",function(b){a.search_results_touchstart(b)}),this.search_results.bind("touchmove.chosen",function(b){a.search_results_touchmove(b)}),this.search_results.bind("touchend.chosen",function(b){a.search_results_touchend(b)}),this.form_field_jq.bind("chosen:updated.chosen",function(b){a.results_update_field(b)}),this.form_field_jq.bind("chosen:activate.chosen",function(b){a.activate_field(b)}),this.form_field_jq.bind("chosen:open.chosen",function(b){a.container_mousedown(b)}),this.form_field_jq.bind("chosen:close.chosen",function(b){a.input_blur(b)}),this.search_field.bind("blur.chosen",function(b){a.input_blur(b)}),this.search_field.bind("keyup.chosen",function(b){a.keyup_checker(b)}),this.search_field.bind("keydown.chosen",function(b){a.keydown_checker(b)}),this.search_field.bind("focus.chosen",function(b){a.input_focus(b)}),this.search_field.bind("cut.chosen",function(b){a.clipboard_event_checker(b)}),this.search_field.bind("paste.chosen",function(b){a.clipboard_event_checker(b)}),this.is_multiple?this.search_choices.bind("click.chosen",function(b){a.choices_click(b)}):this.container.bind("click.chosen",function(a){a.preventDefault()})},Chosen.prototype.destroy=function(){return a(this.container[0].ownerDocument).unbind("click.chosen",this.click_test_action),this.search_field[0].tabIndex&&(this.form_field_jq[0].tabIndex=this.search_field[0].tabIndex),this.container.remove(),this.form_field_jq.removeData("chosen"),this.form_field_jq.show()},Chosen.prototype.search_field_disabled=function(){return this.is_disabled=this.form_field_jq[0].disabled,this.is_disabled?(this.container.addClass("chosen-disabled"),this.search_field[0].disabled=!0,this.is_multiple||this.selected_item.unbind("focus.chosen",this.activate_action),this.close_field()):(this.container.removeClass("chosen-disabled"),this.search_field[0].disabled=!1,this.is_multiple?void 0:this.selected_item.bind("focus.chosen",this.activate_action))},Chosen.prototype.container_mousedown=function(b){return this.is_disabled||(b&&"mousedown"===b.type&&!this.results_showing&&b.preventDefault(),null!=b&&a(b.target).hasClass("search-choice-close"))?void 0:(this.active_field?this.is_multiple||!b||a(b.target)[0]!==this.selected_item[0]&&!a(b.target).parents("a.chosen-single").length||(b.preventDefault(),this.results_toggle()):(this.is_multiple&&this.search_field.val(""),a(this.container[0].ownerDocument).bind("click.chosen",this.click_test_action),this.results_show()),this.activate_field())},Chosen.prototype.container_mouseup=function(a){return"ABBR"!==a.target.nodeName||this.is_disabled?void 0:this.results_reset(a)},Chosen.prototype.search_results_mousewheel=function(a){var b;return a.originalEvent&&(b=-a.originalEvent.wheelDelta||a.originalEvent.detail),null!=b?(a.preventDefault(),"DOMMouseScroll"===a.type&&(b=40*b),this.search_results.scrollTop(b+this.search_results.scrollTop())):void 0},Chosen.prototype.blur_test=function(){return!this.active_field&&this.container.hasClass("chosen-container-active")?this.close_field():void 0},Chosen.prototype.close_field=function(){return a(this.container[0].ownerDocument).unbind("click.chosen",this.click_test_action),this.active_field=!1,this.results_hide(),this.container.removeClass("chosen-container-active"),this.clear_backstroke(),this.show_search_field_default(),this.search_field_scale()},Chosen.prototype.activate_field=function(){return this.container.addClass("chosen-container-active"),this.active_field=!0,this.search_field.val(this.search_field.val()),this.search_field.focus()},Chosen.prototype.test_active_click=function(b){var c;return c=a(b.target).closest(".chosen-container"),c.length&&this.container[0]===c[0]?this.active_field=!0:this.close_field()},Chosen.prototype.results_build=function(){return this.parsing=!0,this.selected_option_count=null,this.results_data=SelectParser.select_to_array(this.form_field),this.is_multiple?this.search_choices.find("li.search-choice").remove():this.is_multiple||(this.single_set_selected_text(),this.disable_search||this.form_field.options.length<=this.disable_search_threshold&&!this.create_option?(this.search_field[0].readOnly=!0,this.container.addClass("chosen-container-single-nosearch")):(this.search_field[0].readOnly=!1,this.container.removeClass("chosen-container-single-nosearch"))),this.update_results_content(this.results_option_build({first:!0})),this.search_field_disabled(),this.show_search_field_default(),this.search_field_scale(),this.parsing=!1},Chosen.prototype.result_do_highlight=function(a){var b,c,d,e,f;if(a.length){if(this.result_clear_highlight(),this.result_highlight=a,this.result_highlight.addClass("highlighted"),d=parseInt(this.search_results.css("maxHeight"),10),f=this.search_results.scrollTop(),e=d+f,c=this.result_highlight.position().top+this.search_results.scrollTop(),b=c+this.result_highlight.outerHeight(),b>=e)return this.search_results.scrollTop(b-d>0?b-d:0);if(f>c)return this.search_results.scrollTop(c)}},Chosen.prototype.result_clear_highlight=function(){return this.result_highlight&&this.result_highlight.removeClass("highlighted"),this.result_highlight=null},Chosen.prototype.results_show=function(){return this.is_multiple&&this.max_selected_options<=this.choices_count()?(this.form_field_jq.trigger("chosen:maxselected",{chosen:this}),!1):(this.container.addClass("chosen-with-drop"),this.results_showing=!0,this.search_field.focus(),this.search_field.val(this.search_field.val()),this.winnow_results(),this.form_field_jq.trigger("chosen:showing_dropdown",{chosen:this}))},Chosen.prototype.update_results_content=function(a){return this.search_results.html(a)},Chosen.prototype.results_hide=function(){return this.results_showing&&(this.result_clear_highlight(),this.container.removeClass("chosen-with-drop"),this.form_field_jq.trigger("chosen:hiding_dropdown",{chosen:this})),this.results_showing=!1},Chosen.prototype.set_tab_index=function(){var a;return this.form_field.tabIndex?(a=this.form_field.tabIndex,this.form_field.tabIndex=-1,this.search_field[0].tabIndex=a):void 0},Chosen.prototype.set_label_behavior=function(){var b=this;return this.form_field_label=this.form_field_jq.parents("label"),!this.form_field_label.length&&this.form_field.id.length&&(this.form_field_label=a("label[for='"+this.form_field.id+"']")),this.form_field_label.length>0?this.form_field_label.bind("click.chosen",function(a){return b.is_multiple?b.container_mousedown(a):b.activate_field()}):void 0},Chosen.prototype.show_search_field_default=function(){return this.is_multiple&&this.choices_count()<1&&!this.active_field?(this.search_field.val(this.default_text),this.search_field.addClass("default")):(this.search_field.val(""),this.search_field.removeClass("default"))},Chosen.prototype.search_results_mouseup=function(b){var c;return c=a(b.target).hasClass("active-result")?a(b.target):a(b.target).parents(".active-result").first(),c.length?(this.result_highlight=c,this.result_select(b),this.search_field.focus()):void 0},Chosen.prototype.search_results_mouseover=function(b){var c;return c=a(b.target).hasClass("active-result")?a(b.target):a(b.target).parents(".active-result").first(),c?this.result_do_highlight(c):void 0},Chosen.prototype.search_results_mouseout=function(b){return a(b.target).hasClass("active-result")?this.result_clear_highlight():void 0},Chosen.prototype.choice_build=function(b){var c,d,e=this;return c=a("<li />",{"class":"search-choice"}).html("<span>"+b.html+"</span>"),b.disabled?c.addClass("search-choice-disabled"):(d=a("<a />",{"class":"search-choice-close","data-option-array-index":b.array_index}),d.bind("click.chosen",function(a){return e.choice_destroy_link_click(a)}),c.append(d)),this.search_container.before(c)},Chosen.prototype.choice_destroy_link_click=function(b){return b.preventDefault(),b.stopPropagation(),this.is_disabled?void 0:this.choice_destroy(a(b.target))},Chosen.prototype.choice_destroy=function(a){return this.result_deselect(a[0].getAttribute("data-option-array-index"))?(this.show_search_field_default(),this.is_multiple&&this.choices_count()>0&&this.search_field.val().length<1&&this.results_hide(),a.parents("li").first().remove(),this.search_field_scale()):void 0},Chosen.prototype.results_reset=function(){return this.reset_single_select_options(),this.form_field.options[0].selected=!0,this.single_set_selected_text(),this.show_search_field_default(),this.results_reset_cleanup(),this.form_field_jq.trigger("change"),this.active_field?this.results_hide():void 0},Chosen.prototype.results_reset_cleanup=function(){return this.current_selectedIndex=this.form_field.selectedIndex,this.selected_item.find("abbr").remove()},Chosen.prototype.result_select=function(a){var b,c;return this.result_highlight?(b=this.result_highlight,b.hasClass("create-option")?(this.select_create_option(this.search_field.val()),this.results_hide()):(this.result_clear_highlight(),this.is_multiple&&this.max_selected_options<=this.choices_count()?(this.form_field_jq.trigger("chosen:maxselected",{chosen:this}),!1):(this.is_multiple?b.removeClass("active-result"):this.reset_single_select_options(),c=this.results_data[b[0].getAttribute("data-option-array-index")],c.selected=!0,this.form_field.options[c.options_index].selected=!0,this.selected_option_count=null,this.is_multiple?this.choice_build(c):this.single_set_selected_text(c.text),(a.metaKey||a.ctrlKey)&&this.is_multiple||this.results_hide(),this.search_field.val(""),(this.is_multiple||this.form_field.selectedIndex!==this.current_selectedIndex)&&this.form_field_jq.trigger("change",{selected:this.form_field.options[c.options_index].value}),this.current_selectedIndex=this.form_field.selectedIndex,this.search_field_scale()))):void 0},Chosen.prototype.single_set_selected_text=function(a){return null==a&&(a=this.default_text),a===this.default_text?this.selected_item.addClass("chosen-default"):(this.single_deselect_control_build(),this.selected_item.removeClass("chosen-default")),this.selected_item.find("span").text(a)},Chosen.prototype.result_deselect=function(a){var b;return b=this.results_data[a],this.form_field.options[b.options_index].disabled?!1:(b.selected=!1,this.form_field.options[b.options_index].selected=!1,this.selected_option_count=null,this.result_clear_highlight(),this.results_showing&&this.winnow_results(),this.form_field_jq.trigger("change",{deselected:this.form_field.options[b.options_index].value}),this.search_field_scale(),!0)},Chosen.prototype.single_deselect_control_build=function(){return this.allow_single_deselect?(this.selected_item.find("abbr").length||this.selected_item.find("span").first().after('<abbr class="search-choice-close"></abbr>'),this.selected_item.addClass("chosen-single-with-deselect")):void 0},Chosen.prototype.get_search_text=function(){return this.search_field.val()===this.default_text?"":a("<div/>").text(a.trim(this.search_field.val())).html()},Chosen.prototype.winnow_results_set_highlight=function(){var a,b;return b=this.is_multiple?[]:this.search_results.find(".result-selected.active-result"),a=b.length?b.first():this.search_results.find(".active-result").first(),null!=a?this.result_do_highlight(a):void 0},Chosen.prototype.no_results=function(b){var c;return c=a('<li class="no-results">'+this.results_none_found+' "<span></span>"</li>'),c.find("span").first().html(b),this.search_results.append(c),this.form_field_jq.trigger("chosen:no_results",{chosen:this})},Chosen.prototype.show_create_option=function(b){var c;return c=a('<li class="create-option active-result"><a>'+this.create_option_text+'</a>: "'+b+'"</li>'),this.search_results.append(c)},Chosen.prototype.create_option_clear=function(){return this.search_results.find(".create-option").remove()},Chosen.prototype.select_create_option=function(b){return a.isFunction(this.create_option)?this.create_option.call(this,b):this.select_append_option({value:b,text:b})},Chosen.prototype.select_append_option=function(b){var c;return c=a("<option />",b).attr("selected","selected"),this.form_field_jq.append(c),this.form_field_jq.trigger("chosen:updated"),this.form_field_jq.trigger("change"),this.search_field.trigger("focus")},Chosen.prototype.no_results_clear=function(){return this.search_results.find(".no-results").remove()},Chosen.prototype.keydown_arrow=function(){var a;return this.results_showing&&this.result_highlight?(a=this.result_highlight.nextAll("li.active-result").first())?this.result_do_highlight(a):void 0:this.results_showing&&this.create_option?this.result_do_highlight(this.search_results.find(".create-option")):this.results_show()},Chosen.prototype.keyup_arrow=function(){var a;return this.results_showing||this.is_multiple?this.result_highlight?(a=this.result_highlight.prevAll("li.active-result"),a.length?this.result_do_highlight(a.first()):(this.choices_count()>0&&this.results_hide(),this.result_clear_highlight())):void 0:this.results_show()},Chosen.prototype.keydown_backstroke=function(){var a;return this.pending_backstroke?(this.choice_destroy(this.pending_backstroke.find("a").first()),this.clear_backstroke()):(a=this.search_container.siblings("li.search-choice").last(),a.length&&!a.hasClass("search-choice-disabled")?(this.pending_backstroke=a,this.single_backstroke_delete?this.keydown_backstroke():this.pending_backstroke.addClass("search-choice-focus")):void 0)},Chosen.prototype.clear_backstroke=function(){return this.pending_backstroke&&this.pending_backstroke.removeClass("search-choice-focus"),this.pending_backstroke=null},Chosen.prototype.keydown_checker=function(a){var b,c;switch(b=null!=(c=a.which)?c:a.keyCode,this.search_field_scale(),8!==b&&this.pending_backstroke&&this.clear_backstroke(),b){case 8:this.backstroke_length=this.search_field.val().length;break;case 9:this.results_showing&&!this.is_multiple&&this.result_select(a),this.mouse_on_container=!1;break;case 13:a.preventDefault();break;case 38:a.preventDefault(),this.keyup_arrow();break;case 40:a.preventDefault(),this.keydown_arrow()}},Chosen.prototype.search_field_scale=function(){var b,c,d,e,f,g,h,i,j;if(this.is_multiple){for(d=0,h=0,f="position:absolute; left: -1000px; top: -1000px; display:none;",g=["font-size","font-style","font-weight","font-family","line-height","text-transform","letter-spacing"],i=0,j=g.length;j>i;i++)e=g[i],f+=e+":"+this.search_field.css(e)+";";return b=a("<div />",{style:f}),b.text(this.search_field.val()),a("body").append(b),h=b.width()+25,b.remove(),c=this.container.outerWidth(),h>c-10&&(h=c-10),this.search_field.css({width:h+"px"})}},Chosen}(AbstractChosen)}.call(this);
     1/* Chosen v1.6.1 | (c) 2011-2016 by Harvest | MIT License, https://github.com/harvesthq/chosen/blob/master/LICENSE.md */
     2(function(){var a,AbstractChosen,Chosen,SelectParser,b,c={}.hasOwnProperty,d=function(a,b){function d(){this.constructor=a}for(var e in b)c.call(b,e)&&(a[e]=b[e]);return d.prototype=b.prototype,a.prototype=new d,a.__super__=b.prototype,a};SelectParser=function(){function SelectParser(){this.options_index=0,this.parsed=[]}return SelectParser.prototype.add_node=function(a){return"OPTGROUP"===a.nodeName.toUpperCase()?this.add_group(a):this.add_option(a)},SelectParser.prototype.add_group=function(a){var b,c,d,e,f,g;for(b=this.parsed.length,this.parsed.push({array_index:b,group:!0,label:this.escapeExpression(a.label),title:a.title?a.title:void 0,children:0,disabled:a.disabled,classes:a.className}),f=a.childNodes,g=[],d=0,e=f.length;e>d;d++)c=f[d],g.push(this.add_option(c,b,a.disabled));return g},SelectParser.prototype.add_option=function(a,b,c){return"OPTION"===a.nodeName.toUpperCase()?(""!==a.text?(null!=b&&(this.parsed[b].children+=1),this.parsed.push({array_index:this.parsed.length,options_index:this.options_index,value:a.value,text:a.text,html:a.innerHTML,title:a.title?a.title:void 0,selected:a.selected,disabled:c===!0?c:a.disabled,group_array_index:b,group_label:null!=b?this.parsed[b].label:null,classes:a.className,style:a.style.cssText})):this.parsed.push({array_index:this.parsed.length,options_index:this.options_index,empty:!0}),this.options_index+=1):void 0},SelectParser.prototype.escapeExpression=function(a){var b,c;return null==a||a===!1?"":/[\&\<\>\"\'\`]/.test(a)?(b={"<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;","`":"&#x60;"},c=/&(?!\w+;)|[\<\>\"\'\`]/g,a.replace(c,function(a){return b[a]||"&amp;"})):a},SelectParser}(),SelectParser.select_to_array=function(a){var b,c,d,e,f;for(c=new SelectParser,f=a.childNodes,d=0,e=f.length;e>d;d++)b=f[d],c.add_node(b);return c.parsed},AbstractChosen=function(){function AbstractChosen(a,b){this.form_field=a,this.options=null!=b?b:{},AbstractChosen.browser_is_supported()&&(this.is_multiple=this.form_field.multiple,this.set_default_text(),this.set_default_values(),this.setup(),this.set_up_html(),this.register_observers(),this.on_ready())}return AbstractChosen.prototype.set_default_values=function(){var a=this;return this.click_test_action=function(b){return a.test_active_click(b)},this.activate_action=function(b){return a.activate_field(b)},this.active_field=!1,this.mouse_on_container=!1,this.results_showing=!1,this.result_highlighted=null,this.allow_single_deselect=null!=this.options.allow_single_deselect&&null!=this.form_field.options[0]&&""===this.form_field.options[0].text?this.options.allow_single_deselect:!1,this.disable_search_threshold=this.options.disable_search_threshold||0,this.disable_search=this.options.disable_search||!1,this.enable_split_word_search=null!=this.options.enable_split_word_search?this.options.enable_split_word_search:!0,this.group_search=null!=this.options.group_search?this.options.group_search:!0,this.search_contains=this.options.search_contains||!1,this.single_backstroke_delete=null!=this.options.single_backstroke_delete?this.options.single_backstroke_delete:!0,this.max_selected_options=this.options.max_selected_options||1/0,this.inherit_select_classes=this.options.inherit_select_classes||!1,this.display_selected_options=null!=this.options.display_selected_options?this.options.display_selected_options:!0,this.display_disabled_options=null!=this.options.display_disabled_options?this.options.display_disabled_options:!0,this.include_group_label_in_selected=this.options.include_group_label_in_selected||!1,this.max_shown_results=this.options.max_shown_results||Number.POSITIVE_INFINITY,this.case_sensitive_search=this.options.case_sensitive_search||!1},AbstractChosen.prototype.set_default_text=function(){return this.form_field.getAttribute("data-placeholder")?this.default_text=this.form_field.getAttribute("data-placeholder"):this.is_multiple?this.default_text=this.options.placeholder_text_multiple||this.options.placeholder_text||AbstractChosen.default_multiple_text:this.default_text=this.options.placeholder_text_single||this.options.placeholder_text||AbstractChosen.default_single_text,this.results_none_found=this.form_field.getAttribute("data-no_results_text")||this.options.no_results_text||AbstractChosen.default_no_result_text},AbstractChosen.prototype.choice_label=function(a){return this.include_group_label_in_selected&&null!=a.group_label?"<b class='group-name'>"+a.group_label+"</b>"+a.html:a.html},AbstractChosen.prototype.mouse_enter=function(){return this.mouse_on_container=!0},AbstractChosen.prototype.mouse_leave=function(){return this.mouse_on_container=!1},AbstractChosen.prototype.input_focus=function(a){var b=this;if(this.is_multiple){if(!this.active_field)return setTimeout(function(){return b.container_mousedown()},50)}else if(!this.active_field)return this.activate_field()},AbstractChosen.prototype.input_blur=function(a){var b=this;return this.mouse_on_container?void 0:(this.active_field=!1,setTimeout(function(){return b.blur_test()},100))},AbstractChosen.prototype.results_option_build=function(a){var b,c,d,e,f,g,h;for(b="",e=0,h=this.results_data,f=0,g=h.length;g>f&&(c=h[f],d="",d=c.group?this.result_add_group(c):this.result_add_option(c),""!==d&&(e++,b+=d),(null!=a?a.first:void 0)&&(c.selected&&this.is_multiple?this.choice_build(c):c.selected&&!this.is_multiple&&this.single_set_selected_text(this.choice_label(c))),!(e>=this.max_shown_results));f++);return b},AbstractChosen.prototype.result_add_option=function(a){var b,c;return a.search_match&&this.include_option_in_results(a)?(b=[],a.disabled||a.selected&&this.is_multiple||b.push("active-result"),!a.disabled||a.selected&&this.is_multiple||b.push("disabled-result"),a.selected&&b.push("result-selected"),null!=a.group_array_index&&b.push("group-option"),""!==a.classes&&b.push(a.classes),c=document.createElement("li"),c.className=b.join(" "),c.style.cssText=a.style,c.setAttribute("data-option-array-index",a.array_index),c.innerHTML=a.search_text,a.title&&(c.title=a.title),this.outerHTML(c)):""},AbstractChosen.prototype.result_add_group=function(a){var b,c;return(a.search_match||a.group_match)&&a.active_options>0?(b=[],b.push("group-result"),a.classes&&b.push(a.classes),c=document.createElement("li"),c.className=b.join(" "),c.innerHTML=a.search_text,a.title&&(c.title=a.title),this.outerHTML(c)):""},AbstractChosen.prototype.results_update_field=function(){return this.set_default_text(),this.is_multiple||this.results_reset_cleanup(),this.result_clear_highlight(),this.results_build(),this.results_showing?this.winnow_results():void 0},AbstractChosen.prototype.reset_single_select_options=function(){var a,b,c,d,e;for(d=this.results_data,e=[],b=0,c=d.length;c>b;b++)a=d[b],a.selected?e.push(a.selected=!1):e.push(void 0);return e},AbstractChosen.prototype.results_toggle=function(){return this.results_showing?this.results_hide():this.results_show()},AbstractChosen.prototype.results_search=function(a){return this.results_showing?this.winnow_results():this.results_show()},AbstractChosen.prototype.winnow_results=function(){var a,b,c,d,e,f,g,h,i,j,k,l;for(this.no_results_clear(),d=0,f=this.get_search_text(),a=f.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),i=new RegExp(a,"i"),c=this.get_search_regex(a),l=this.results_data,j=0,k=l.length;k>j;j++)b=l[j],b.search_match=!1,e=null,this.include_option_in_results(b)&&(b.group&&(b.group_match=!1,b.active_options=0),null!=b.group_array_index&&this.results_data[b.group_array_index]&&(e=this.results_data[b.group_array_index],0===e.active_options&&e.search_match&&(d+=1),e.active_options+=1),b.search_text=b.group?b.label:b.html,(!b.group||this.group_search)&&(b.search_match=this.search_string_match(b.search_text,c),b.search_match&&!b.group&&(d+=1),b.search_match?(f.length&&(g=b.search_text.search(i),h=b.search_text.substr(0,g+f.length)+"</em>"+b.search_text.substr(g+f.length),b.search_text=h.substr(0,g)+"<em>"+h.substr(g)),null!=e&&(e.group_match=!0)):null!=b.group_array_index&&this.results_data[b.group_array_index].search_match&&(b.search_match=!0)));return this.result_clear_highlight(),1>d&&f.length?(this.update_results_content(""),this.no_results(f)):(this.update_results_content(this.results_option_build()),this.winnow_results_set_highlight())},AbstractChosen.prototype.get_search_regex=function(a){var b,c;return b=this.search_contains?"":"^",c=this.case_sensitive_search?"":"i",new RegExp(b+a,c)},AbstractChosen.prototype.search_string_match=function(a,b){var c,d,e,f;if(b.test(a))return!0;if(this.enable_split_word_search&&(a.indexOf(" ")>=0||0===a.indexOf("["))&&(d=a.replace(/\[|\]/g,"").split(" "),d.length))for(e=0,f=d.length;f>e;e++)if(c=d[e],b.test(c))return!0},AbstractChosen.prototype.choices_count=function(){var a,b,c,d;if(null!=this.selected_option_count)return this.selected_option_count;for(this.selected_option_count=0,d=this.form_field.options,b=0,c=d.length;c>b;b++)a=d[b],a.selected&&(this.selected_option_count+=1);return this.selected_option_count},AbstractChosen.prototype.choices_click=function(a){return a.preventDefault(),this.results_showing||this.is_disabled?void 0:this.results_show()},AbstractChosen.prototype.keyup_checker=function(a){var b,c;switch(b=null!=(c=a.which)?c:a.keyCode,this.search_field_scale(),b){case 8:if(this.is_multiple&&this.backstroke_length<1&&this.choices_count()>0)return this.keydown_backstroke();if(!this.pending_backstroke)return this.result_clear_highlight(),this.results_search();break;case 13:if(a.preventDefault(),this.results_showing)return this.result_select(a);break;case 27:return this.results_showing&&this.results_hide(),!0;case 9:case 38:case 40:case 16:case 91:case 17:case 18:break;default:return this.results_search()}},AbstractChosen.prototype.clipboard_event_checker=function(a){var b=this;return setTimeout(function(){return b.results_search()},50)},AbstractChosen.prototype.container_width=function(){return null!=this.options.width?this.options.width:""+this.form_field.offsetWidth+"px"},AbstractChosen.prototype.include_option_in_results=function(a){return this.is_multiple&&!this.display_selected_options&&a.selected?!1:!this.display_disabled_options&&a.disabled?!1:a.empty?!1:!0},AbstractChosen.prototype.search_results_touchstart=function(a){return this.touch_started=!0,this.search_results_mouseover(a)},AbstractChosen.prototype.search_results_touchmove=function(a){return this.touch_started=!1,this.search_results_mouseout(a)},AbstractChosen.prototype.search_results_touchend=function(a){return this.touch_started?this.search_results_mouseup(a):void 0},AbstractChosen.prototype.outerHTML=function(a){var b;return a.outerHTML?a.outerHTML:(b=document.createElement("div"),b.appendChild(a),b.innerHTML)},AbstractChosen.browser_is_supported=function(){return"Microsoft Internet Explorer"===window.navigator.appName?document.documentMode>=8:/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)?!1:!0},AbstractChosen.default_multiple_text="Select Some Options",AbstractChosen.default_single_text="Select an Option",AbstractChosen.default_no_result_text="No results match",AbstractChosen}(),a=jQuery,a.fn.extend({chosen:function(b){return AbstractChosen.browser_is_supported()?this.each(function(c){var d,e;return d=a(this),e=d.data("chosen"),"destroy"===b?void(e instanceof Chosen&&e.destroy()):void(e instanceof Chosen||d.data("chosen",new Chosen(this,b)))}):this}}),Chosen=function(c){function Chosen(){return b=Chosen.__super__.constructor.apply(this,arguments)}return d(Chosen,c),Chosen.prototype.setup=function(){return this.form_field_jq=a(this.form_field),this.current_selectedIndex=this.form_field.selectedIndex,this.is_rtl=this.form_field_jq.hasClass("chosen-rtl")},Chosen.prototype.set_up_html=function(){var b,c;return b=["chosen-container"],b.push("chosen-container-"+(this.is_multiple?"multi":"single")),this.inherit_select_classes&&this.form_field.className&&b.push(this.form_field.className),this.is_rtl&&b.push("chosen-rtl"),c={"class":b.join(" "),style:"width: "+this.container_width()+";",title:this.form_field.title},this.form_field.id.length&&(c.id=this.form_field.id.replace(/[^\w]/g,"_")+"_chosen"),this.container=a("<div />",c),this.is_multiple?this.container.html('<ul class="chosen-choices"><li class="search-field"><input type="text" value="'+this.default_text+'" class="default" autocomplete="off" style="width:25px;" /></li></ul><div class="chosen-drop"><ul class="chosen-results"></ul></div>'):this.container.html('<a class="chosen-single chosen-default"><span>'+this.default_text+'</span><div><b></b></div></a><div class="chosen-drop"><div class="chosen-search"><input type="text" autocomplete="off" /></div><ul class="chosen-results"></ul></div>'),this.form_field_jq.hide().after(this.container),this.dropdown=this.container.find("div.chosen-drop").first(),this.search_field=this.container.find("input").first(),this.search_results=this.container.find("ul.chosen-results").first(),this.search_field_scale(),this.search_no_results=this.container.find("li.no-results").first(),this.is_multiple?(this.search_choices=this.container.find("ul.chosen-choices").first(),this.search_container=this.container.find("li.search-field").first()):(this.search_container=this.container.find("div.chosen-search").first(),this.selected_item=this.container.find(".chosen-single").first()),this.results_build(),this.set_tab_index(),this.set_label_behavior()},Chosen.prototype.on_ready=function(){return this.form_field_jq.trigger("chosen:ready",{chosen:this})},Chosen.prototype.register_observers=function(){var a=this;return this.container.bind("touchstart.chosen",function(b){return a.container_mousedown(b),b.preventDefault()}),this.container.bind("touchend.chosen",function(b){return a.container_mouseup(b),b.preventDefault()}),this.container.bind("mousedown.chosen",function(b){a.container_mousedown(b)}),this.container.bind("mouseup.chosen",function(b){a.container_mouseup(b)}),this.container.bind("mouseenter.chosen",function(b){a.mouse_enter(b)}),this.container.bind("mouseleave.chosen",function(b){a.mouse_leave(b)}),this.search_results.bind("mouseup.chosen",function(b){a.search_results_mouseup(b)}),this.search_results.bind("mouseover.chosen",function(b){a.search_results_mouseover(b)}),this.search_results.bind("mouseout.chosen",function(b){a.search_results_mouseout(b)}),this.search_results.bind("mousewheel.chosen DOMMouseScroll.chosen",function(b){a.search_results_mousewheel(b)}),this.search_results.bind("touchstart.chosen",function(b){a.search_results_touchstart(b)}),this.search_results.bind("touchmove.chosen",function(b){a.search_results_touchmove(b)}),this.search_results.bind("touchend.chosen",function(b){a.search_results_touchend(b)}),this.form_field_jq.bind("chosen:updated.chosen",function(b){a.results_update_field(b)}),this.form_field_jq.bind("chosen:activate.chosen",function(b){a.activate_field(b)}),this.form_field_jq.bind("chosen:open.chosen",function(b){a.container_mousedown(b)}),this.form_field_jq.bind("chosen:close.chosen",function(b){a.input_blur(b)}),this.search_field.bind("blur.chosen",function(b){a.input_blur(b)}),this.search_field.bind("keyup.chosen",function(b){a.keyup_checker(b)}),this.search_field.bind("keydown.chosen",function(b){a.keydown_checker(b)}),this.search_field.bind("focus.chosen",function(b){a.input_focus(b)}),this.search_field.bind("cut.chosen",function(b){a.clipboard_event_checker(b)}),this.search_field.bind("paste.chosen",function(b){a.clipboard_event_checker(b)}),this.is_multiple?this.search_choices.bind("click.chosen",function(b){a.choices_click(b)}):this.container.bind("click.chosen",function(a){a.preventDefault()})},Chosen.prototype.destroy=function(){return a(this.container[0].ownerDocument).unbind("click.chosen",this.click_test_action),this.search_field[0].tabIndex&&(this.form_field_jq[0].tabIndex=this.search_field[0].tabIndex),this.container.remove(),this.form_field_jq.removeData("chosen"),this.form_field_jq.show()},Chosen.prototype.search_field_disabled=function(){return this.is_disabled=this.form_field_jq[0].disabled,this.is_disabled?(this.container.addClass("chosen-disabled"),this.search_field[0].disabled=!0,this.is_multiple||this.selected_item.unbind("focus.chosen",this.activate_action),this.close_field()):(this.container.removeClass("chosen-disabled"),this.search_field[0].disabled=!1,this.is_multiple?void 0:this.selected_item.bind("focus.chosen",this.activate_action))},Chosen.prototype.container_mousedown=function(b){return this.is_disabled||(b&&"mousedown"===b.type&&!this.results_showing&&b.preventDefault(),null!=b&&a(b.target).hasClass("search-choice-close"))?void 0:(this.active_field?this.is_multiple||!b||a(b.target)[0]!==this.selected_item[0]&&!a(b.target).parents("a.chosen-single").length||(b.preventDefault(),this.results_toggle()):(this.is_multiple&&this.search_field.val(""),a(this.container[0].ownerDocument).bind("click.chosen",this.click_test_action),this.results_show()),this.activate_field())},Chosen.prototype.container_mouseup=function(a){return"ABBR"!==a.target.nodeName||this.is_disabled?void 0:this.results_reset(a)},Chosen.prototype.search_results_mousewheel=function(a){var b;return a.originalEvent&&(b=a.originalEvent.deltaY||-a.originalEvent.wheelDelta||a.originalEvent.detail),null!=b?(a.preventDefault(),"DOMMouseScroll"===a.type&&(b=40*b),this.search_results.scrollTop(b+this.search_results.scrollTop())):void 0},Chosen.prototype.blur_test=function(a){return!this.active_field&&this.container.hasClass("chosen-container-active")?this.close_field():void 0},Chosen.prototype.close_field=function(){return a(this.container[0].ownerDocument).unbind("click.chosen",this.click_test_action),this.active_field=!1,this.results_hide(),this.container.removeClass("chosen-container-active"),this.clear_backstroke(),this.show_search_field_default(),this.search_field_scale()},Chosen.prototype.activate_field=function(){return this.container.addClass("chosen-container-active"),this.active_field=!0,this.search_field.val(this.search_field.val()),this.search_field.focus()},Chosen.prototype.test_active_click=function(b){var c;return c=a(b.target).closest(".chosen-container"),c.length&&this.container[0]===c[0]?this.active_field=!0:this.close_field()},Chosen.prototype.results_build=function(){return this.parsing=!0,this.selected_option_count=null,this.results_data=SelectParser.select_to_array(this.form_field),this.is_multiple?this.search_choices.find("li.search-choice").remove():this.is_multiple||(this.single_set_selected_text(),this.disable_search||this.form_field.options.length<=this.disable_search_threshold?(this.search_field[0].readOnly=!0,this.container.addClass("chosen-container-single-nosearch")):(this.search_field[0].readOnly=!1,this.container.removeClass("chosen-container-single-nosearch"))),this.update_results_content(this.results_option_build({first:!0})),this.search_field_disabled(),this.show_search_field_default(),this.search_field_scale(),this.parsing=!1},Chosen.prototype.result_do_highlight=function(a){var b,c,d,e,f;if(a.length){if(this.result_clear_highlight(),this.result_highlight=a,this.result_highlight.addClass("highlighted"),d=parseInt(this.search_results.css("maxHeight"),10),f=this.search_results.scrollTop(),e=d+f,c=this.result_highlight.position().top+this.search_results.scrollTop(),b=c+this.result_highlight.outerHeight(),b>=e)return this.search_results.scrollTop(b-d>0?b-d:0);if(f>c)return this.search_results.scrollTop(c)}},Chosen.prototype.result_clear_highlight=function(){return this.result_highlight&&this.result_highlight.removeClass("highlighted"),this.result_highlight=null},Chosen.prototype.results_show=function(){return this.is_multiple&&this.max_selected_options<=this.choices_count()?(this.form_field_jq.trigger("chosen:maxselected",{chosen:this}),!1):(this.container.addClass("chosen-with-drop"),this.results_showing=!0,this.search_field.focus(),this.search_field.val(this.search_field.val()),this.winnow_results(),this.form_field_jq.trigger("chosen:showing_dropdown",{chosen:this}))},Chosen.prototype.update_results_content=function(a){return this.search_results.html(a)},Chosen.prototype.results_hide=function(){return this.results_showing&&(this.result_clear_highlight(),this.container.removeClass("chosen-with-drop"),this.form_field_jq.trigger("chosen:hiding_dropdown",{chosen:this})),this.results_showing=!1},Chosen.prototype.set_tab_index=function(a){var b;return this.form_field.tabIndex?(b=this.form_field.tabIndex,this.form_field.tabIndex=-1,this.search_field[0].tabIndex=b):void 0},Chosen.prototype.set_label_behavior=function(){var b=this;return this.form_field_label=this.form_field_jq.parents("label"),!this.form_field_label.length&&this.form_field.id.length&&(this.form_field_label=a("label[for='"+this.form_field.id+"']")),this.form_field_label.length>0?this.form_field_label.bind("click.chosen",function(a){return b.is_multiple?b.container_mousedown(a):b.activate_field()}):void 0},Chosen.prototype.show_search_field_default=function(){return this.is_multiple&&this.choices_count()<1&&!this.active_field?(this.search_field.val(this.default_text),this.search_field.addClass("default")):(this.search_field.val(""),this.search_field.removeClass("default"))},Chosen.prototype.search_results_mouseup=function(b){var c;return c=a(b.target).hasClass("active-result")?a(b.target):a(b.target).parents(".active-result").first(),c.length?(this.result_highlight=c,this.result_select(b),this.search_field.focus()):void 0},Chosen.prototype.search_results_mouseover=function(b){var c;return c=a(b.target).hasClass("active-result")?a(b.target):a(b.target).parents(".active-result").first(),c?this.result_do_highlight(c):void 0},Chosen.prototype.search_results_mouseout=function(b){return a(b.target).hasClass("active-result")?this.result_clear_highlight():void 0},Chosen.prototype.choice_build=function(b){var c,d,e=this;return c=a("<li />",{"class":"search-choice"}).html("<span>"+this.choice_label(b)+"</span>"),b.disabled?c.addClass("search-choice-disabled"):(d=a("<a />",{"class":"search-choice-close","data-option-array-index":b.array_index}),d.bind("click.chosen",function(a){return e.choice_destroy_link_click(a)}),c.append(d)),this.search_container.before(c)},Chosen.prototype.choice_destroy_link_click=function(b){return b.preventDefault(),b.stopPropagation(),this.is_disabled?void 0:this.choice_destroy(a(b.target))},Chosen.prototype.choice_destroy=function(a){return this.result_deselect(a[0].getAttribute("data-option-array-index"))?(this.show_search_field_default(),this.is_multiple&&this.choices_count()>0&&this.search_field.val().length<1&&this.results_hide(),a.parents("li").first().remove(),this.search_field_scale()):void 0},Chosen.prototype.results_reset=function(){return this.reset_single_select_options(),this.form_field.options[0].selected=!0,this.single_set_selected_text(),this.show_search_field_default(),this.results_reset_cleanup(),this.form_field_jq.trigger("change"),this.active_field?this.results_hide():void 0},Chosen.prototype.results_reset_cleanup=function(){return this.current_selectedIndex=this.form_field.selectedIndex,this.selected_item.find("abbr").remove()},Chosen.prototype.result_select=function(a){var b,c;return this.result_highlight?(b=this.result_highlight,this.result_clear_highlight(),this.is_multiple&&this.max_selected_options<=this.choices_count()?(this.form_field_jq.trigger("chosen:maxselected",{chosen:this}),!1):(this.is_multiple?b.removeClass("active-result"):this.reset_single_select_options(),b.addClass("result-selected"),c=this.results_data[b[0].getAttribute("data-option-array-index")],c.selected=!0,this.form_field.options[c.options_index].selected=!0,this.selected_option_count=null,this.is_multiple?this.choice_build(c):this.single_set_selected_text(this.choice_label(c)),(a.metaKey||a.ctrlKey)&&this.is_multiple||this.results_hide(),this.show_search_field_default(),(this.is_multiple||this.form_field.selectedIndex!==this.current_selectedIndex)&&this.form_field_jq.trigger("change",{selected:this.form_field.options[c.options_index].value}),this.current_selectedIndex=this.form_field.selectedIndex,a.preventDefault(),this.search_field_scale())):void 0},Chosen.prototype.single_set_selected_text=function(a){return null==a&&(a=this.default_text),a===this.default_text?this.selected_item.addClass("chosen-default"):(this.single_deselect_control_build(),this.selected_item.removeClass("chosen-default")),this.selected_item.find("span").html(a)},Chosen.prototype.result_deselect=function(a){var b;return b=this.results_data[a],this.form_field.options[b.options_index].disabled?!1:(b.selected=!1,this.form_field.options[b.options_index].selected=!1,this.selected_option_count=null,this.result_clear_highlight(),this.results_showing&&this.winnow_results(),this.form_field_jq.trigger("change",{deselected:this.form_field.options[b.options_index].value}),this.search_field_scale(),!0)},Chosen.prototype.single_deselect_control_build=function(){return this.allow_single_deselect?(this.selected_item.find("abbr").length||this.selected_item.find("span").first().after('<abbr class="search-choice-close"></abbr>'),this.selected_item.addClass("chosen-single-with-deselect")):void 0},Chosen.prototype.get_search_text=function(){return a("<div/>").text(a.trim(this.search_field.val())).html()},Chosen.prototype.winnow_results_set_highlight=function(){var a,b;return b=this.is_multiple?[]:this.search_results.find(".result-selected.active-result"),a=b.length?b.first():this.search_results.find(".active-result").first(),null!=a?this.result_do_highlight(a):void 0},Chosen.prototype.no_results=function(b){var c;return c=a('<li class="no-results">'+this.results_none_found+' "<span></span>"</li>'),c.find("span").first().html(b),this.search_results.append(c),this.form_field_jq.trigger("chosen:no_results",{chosen:this})},Chosen.prototype.no_results_clear=function(){return this.search_results.find(".no-results").remove()},Chosen.prototype.keydown_arrow=function(){var a;return this.results_showing&&this.result_highlight?(a=this.result_highlight.nextAll("li.active-result").first())?this.result_do_highlight(a):void 0:this.results_show()},Chosen.prototype.keyup_arrow=function(){var a;return this.results_showing||this.is_multiple?this.result_highlight?(a=this.result_highlight.prevAll("li.active-result"),a.length?this.result_do_highlight(a.first()):(this.choices_count()>0&&this.results_hide(),this.result_clear_highlight())):void 0:this.results_show()},Chosen.prototype.keydown_backstroke=function(){var a;return this.pending_backstroke?(this.choice_destroy(this.pending_backstroke.find("a").first()),this.clear_backstroke()):(a=this.search_container.siblings("li.search-choice").last(),a.length&&!a.hasClass("search-choice-disabled")?(this.pending_backstroke=a,this.single_backstroke_delete?this.keydown_backstroke():this.pending_backstroke.addClass("search-choice-focus")):void 0)},Chosen.prototype.clear_backstroke=function(){return this.pending_backstroke&&this.pending_backstroke.removeClass("search-choice-focus"),this.pending_backstroke=null},Chosen.prototype.keydown_checker=function(a){var b,c;switch(b=null!=(c=a.which)?c:a.keyCode,this.search_field_scale(),8!==b&&this.pending_backstroke&&this.clear_backstroke(),b){case 8:this.backstroke_length=this.search_field.val().length;break;case 9:this.results_showing&&!this.is_multiple&&this.result_select(a),this.mouse_on_container=!1;break;case 13:this.results_showing&&a.preventDefault();break;case 32:this.disable_search&&a.preventDefault();break;case 38:a.preventDefault(),this.keyup_arrow();break;case 40:a.preventDefault(),this.keydown_arrow()}},Chosen.prototype.search_field_scale=function(){var b,c,d,e,f,g,h,i,j;if(this.is_multiple){for(d=0,h=0,f="position:absolute; left: -1000px; top: -1000px; display:none;",g=["font-size","font-style","font-weight","font-family","line-height","text-transform","letter-spacing"],i=0,j=g.length;j>i;i++)e=g[i],f+=e+":"+this.search_field.css(e)+";";return b=a("<div />",{style:f}),b.text(this.search_field.val()),a("body").append(b),h=b.width()+25,b.remove(),c=this.container.outerWidth(),h>c-10&&(h=c-10),this.search_field.css({width:h+"px"})}},Chosen}(AbstractChosen)}).call(this);
  • _plugins_/chosen/trunk/lib/chosen/chosen.proto.js

    r97865 r98557  
    33by Patrick Filler for Harvest, http://getharvest.com
    44
    5 Version 1.1.0
     5Version 1.6.1
    66Full source at https://github.com/harvesthq/chosen
    7 Copyright (c) 2011 Harvest http://getharvest.com
     7Copyright (c) 2011-2016 Harvest http://getharvest.com
    88
    99MIT License, https://github.com/harvesthq/chosen/blob/master/LICENSE.md
    1010This file is generated by `grunt build`, do not edit it by hand.
    11 
    12 Attention : this is a forked version to add the create option (https://github.com/harvesthq/chosen/pull/166)
    13 This release is issued from https://github.com/koenpunt/chosen/releases
    1411*/
    1512
    1613(function() {
    17   var $, AbstractChosen, Chosen, ChosenOptionAdding, SelectParser, _ref, _ref1,
     14  var AbstractChosen, SelectParser, _ref,
    1815    __hasProp = {}.hasOwnProperty,
    1916    __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; };
     
    4037        group: true,
    4138        label: this.escapeExpression(group.label),
     39        title: group.title ? group.title : void 0,
    4240        children: 0,
    43         disabled: group.disabled
     41        disabled: group.disabled,
     42        classes: group.className
    4443      });
    4544      _ref = group.childNodes;
     
    6463            text: option.text,
    6564            html: option.innerHTML,
     65            title: option.title ? option.title : void 0,
    6666            selected: option.selected,
    6767            disabled: group_disabled === true ? group_disabled : option.disabled,
    6868            group_array_index: group_position,
     69            group_label: group_position != null ? this.parsed[group_position].label : null,
    6970            classes: option.className,
    7071            style: option.style.cssText
     
    130131      this.set_up_html();
    131132      this.register_observers();
     133      this.on_ready();
    132134    }
    133135
     
    154156      this.inherit_select_classes = this.options.inherit_select_classes || false;
    155157      this.display_selected_options = this.options.display_selected_options != null ? this.options.display_selected_options : true;
    156       return this.display_disabled_options = this.options.display_disabled_options != null ? this.options.display_disabled_options : true;
     158      this.display_disabled_options = this.options.display_disabled_options != null ? this.options.display_disabled_options : true;
     159      this.include_group_label_in_selected = this.options.include_group_label_in_selected || false;
     160      this.max_shown_results = this.options.max_shown_results || Number.POSITIVE_INFINITY;
     161      return this.case_sensitive_search = this.options.case_sensitive_search || false;
    157162    };
    158163
     
    166171      }
    167172      return this.results_none_found = this.form_field.getAttribute("data-no_results_text") || this.options.no_results_text || AbstractChosen.default_no_result_text;
     173    };
     174
     175    AbstractChosen.prototype.choice_label = function(item) {
     176      if (this.include_group_label_in_selected && (item.group_label != null)) {
     177        return "<b class='group-name'>" + item.group_label + "</b>" + item.html;
     178      } else {
     179        return item.html;
     180      }
    168181    };
    169182
     
    202215
    203216    AbstractChosen.prototype.results_option_build = function(options) {
    204       var content, data, _i, _len, _ref;
     217      var content, data, data_content, shown_results, _i, _len, _ref;
    205218      content = '';
     219      shown_results = 0;
    206220      _ref = this.results_data;
    207221      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
    208222        data = _ref[_i];
     223        data_content = '';
    209224        if (data.group) {
    210           content += this.result_add_group(data);
     225          data_content = this.result_add_group(data);
    211226        } else {
    212           content += this.result_add_option(data);
     227          data_content = this.result_add_option(data);
     228        }
     229        if (data_content !== '') {
     230          shown_results++;
     231          content += data_content;
    213232        }
    214233        if (options != null ? options.first : void 0) {
     
    216235            this.choice_build(data);
    217236          } else if (data.selected && !this.is_multiple) {
    218             this.single_set_selected_text(data.text);
    219           }
     237            this.single_set_selected_text(this.choice_label(data));
     238          }
     239        }
     240        if (shown_results >= this.max_shown_results) {
     241          break;
    220242        }
    221243      }
     
    252274      option_el.setAttribute("data-option-array-index", option.array_index);
    253275      option_el.innerHTML = option.search_text;
     276      if (option.title) {
     277        option_el.title = option.title;
     278      }
    254279      return this.outerHTML(option_el);
    255280    };
    256281
    257282    AbstractChosen.prototype.result_add_group = function(group) {
    258       var group_el;
     283      var classes, group_el;
    259284      if (!(group.search_match || group.group_match)) {
    260285        return '';
     
    263288        return '';
    264289      }
     290      classes = [];
     291      classes.push("group-result");
     292      if (group.classes) {
     293        classes.push(group.classes);
     294      }
    265295      group_el = document.createElement("li");
    266       group_el.className = "group-result";
     296      group_el.className = classes.join(" ");
    267297      group_el.innerHTML = group.search_text;
     298      if (group.title) {
     299        group_el.title = group.title;
     300      }
    268301      return this.outerHTML(group_el);
    269302    };
     
    313346
    314347    AbstractChosen.prototype.winnow_results = function() {
    315       var escapedSearchText, option, regex, regexAnchor, results, results_group, searchText, startpos, text, zregex, _i, _len, _ref;
     348      var escapedSearchText, option, regex, results, results_group, searchText, startpos, text, zregex, _i, _len, _ref;
    316349      this.no_results_clear();
    317350      results = 0;
    318351      searchText = this.get_search_text();
    319352      escapedSearchText = searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
    320       regexAnchor = this.search_contains ? "" : "^";
    321       regex = new RegExp(regexAnchor + escapedSearchText, 'i');
    322353      zregex = new RegExp(escapedSearchText, 'i');
     354      regex = this.get_search_regex(escapedSearchText);
    323355      _ref = this.results_data;
    324356      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
     
    338370            results_group.active_options += 1;
    339371          }
     372          option.search_text = option.group ? option.label : option.html;
    340373          if (!(option.group && !this.group_search)) {
    341             option.search_text = option.group ? option.label : option.html;
    342374            option.search_match = this.search_string_match(option.search_text, regex);
    343375            if (option.search_match && !option.group) {
     
    369401    };
    370402
     403    AbstractChosen.prototype.get_search_regex = function(escaped_search_string) {
     404      var regex_anchor, regex_flag;
     405      regex_anchor = this.search_contains ? "" : "^";
     406      regex_flag = this.case_sensitive_search ? "" : "i";
     407      return new RegExp(regex_anchor + escaped_search_string, regex_flag);
     408    };
     409
    371410    AbstractChosen.prototype.search_string_match = function(search_string, regex) {
    372411      var part, parts, _i, _len;
     
    439478        case 91:
    440479        case 17:
     480        case 18:
    441481          break;
    442482        default:
    443483          return this.results_search();
    444484      }
     485    };
     486
     487    AbstractChosen.prototype.clipboard_event_checker = function(evt) {
     488      var _this = this;
     489      return setTimeout((function() {
     490        return _this.results_search();
     491      }), 50);
    445492    };
    446493
     
    493540
    494541    AbstractChosen.browser_is_supported = function() {
    495       if (window.navigator.appName === "Microsoft Internet Explorer") {
     542      if ("Microsoft Internet Explorer" === window.navigator.appName) {
    496543        return document.documentMode >= 8;
    497544      }
    498       if (/iP(od|hone)/i.test(window.navigator.userAgent)) {
     545      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)) {
    499546        return false;
    500547      }
    501       if (/Android/i.test(window.navigator.userAgent)) {
    502         if (/Mobile/i.test(window.navigator.userAgent)) {
    503           return false;
    504         }
    505       }
    506548      return true;
    507549    };
     
    517559  })();
    518560
    519   $ = jQuery;
    520 
    521   $.fn.extend({
    522     chosen: function(options) {
    523       if (!AbstractChosen.browser_is_supported()) {
    524         return this;
    525       }
    526       return this.each(function(input_field) {
    527         var $this, chosen;
    528         $this = $(this);
    529         chosen = $this.data('chosen');
    530         if (options === 'destroy' && chosen) {
    531           chosen.destroy();
    532         } else if (!chosen) {
    533           $this.data('chosen', new Chosen(this, options));
    534         }
    535       });
    536     }
    537   });
    538 
    539   Chosen = (function(_super) {
     561  this.Chosen = (function(_super) {
    540562    __extends(Chosen, _super);
    541563
     
    546568
    547569    Chosen.prototype.setup = function() {
    548       this.form_field_jq = $(this.form_field);
    549570      this.current_selectedIndex = this.form_field.selectedIndex;
    550       return this.is_rtl = this.form_field_jq.hasClass("chosen-rtl");
     571      return this.is_rtl = this.form_field.hasClassName("chosen-rtl");
     572    };
     573
     574    Chosen.prototype.set_default_values = function() {
     575      Chosen.__super__.set_default_values.call(this);
     576      this.single_temp = new Template('<a class="chosen-single chosen-default"><span>#{default}</span><div><b></b></div></a><div class="chosen-drop"><div class="chosen-search"><input type="text" autocomplete="off" /></div><ul class="chosen-results"></ul></div>');
     577      this.multi_temp = new Template('<ul class="chosen-choices"><li class="search-field"><input type="text" value="#{default}" class="default" autocomplete="off" style="width:25px;" /></li></ul><div class="chosen-drop"><ul class="chosen-results"></ul></div>');
     578      return this.no_results_temp = new Template('<li class="no-results">' + this.results_none_found + ' "<span>#{terms}</span>"</li>');
    551579    };
    552580
     
    569597        container_props.id = this.form_field.id.replace(/[^\w]/g, '_') + "_chosen";
    570598      }
    571       this.container = $("<div />", container_props);
     599      this.container = this.is_multiple ? new Element('div', container_props).update(this.multi_temp.evaluate({
     600        "default": this.default_text
     601      })) : new Element('div', container_props).update(this.single_temp.evaluate({
     602        "default": this.default_text
     603      }));
     604      this.form_field.hide().insert({
     605        after: this.container
     606      });
     607      this.dropdown = this.container.down('div.chosen-drop');
     608      this.search_field = this.container.down('input');
     609      this.search_results = this.container.down('ul.chosen-results');
     610      this.search_field_scale();
     611      this.search_no_results = this.container.down('li.no-results');
    572612      if (this.is_multiple) {
    573         this.container.html('<ul class="chosen-choices"><li class="search-field"><input type="text" value="' + this.default_text + '" class="default" autocomplete="off" style="width:25px;" /></li></ul><div class="chosen-drop"><ul class="chosen-results"></ul></div>');
    574       } else {
    575         this.container.html('<a class="chosen-single chosen-default" tabindex="-1"><span>' + this.default_text + '</span><div><b></b></div></a><div class="chosen-drop"><div class="chosen-search"><input type="text" autocomplete="off" /></div><ul class="chosen-results"></ul></div>');
    576       }
    577       this.form_field_jq.hide().after(this.container);
    578       this.dropdown = this.container.find('div.chosen-drop').first();
    579       this.search_field = this.container.find('input').first();
    580       this.search_results = this.container.find('ul.chosen-results').first();
    581       this.search_field_scale();
    582       this.search_no_results = this.container.find('li.no-results').first();
    583       if (this.is_multiple) {
    584         this.search_choices = this.container.find('ul.chosen-choices').first();
    585         this.search_container = this.container.find('li.search-field').first();
    586       } else {
    587         this.search_container = this.container.find('div.chosen-search').first();
    588         this.selected_item = this.container.find('.chosen-single').first();
     613        this.search_choices = this.container.down('ul.chosen-choices');
     614        this.search_container = this.container.down('li.search-field');
     615      } else {
     616        this.search_container = this.container.down('div.chosen-search');
     617        this.selected_item = this.container.down('.chosen-single');
    589618      }
    590619      this.results_build();
    591620      this.set_tab_index();
    592       this.set_label_behavior();
    593       return this.form_field_jq.trigger("chosen:ready", {
     621      return this.set_label_behavior();
     622    };
     623
     624    Chosen.prototype.on_ready = function() {
     625      return this.form_field.fire("chosen:ready", {
    594626        chosen: this
    595627      });
     
    598630    Chosen.prototype.register_observers = function() {
    599631      var _this = this;
    600       this.container.bind('mousedown.chosen', function(evt) {
     632      this.container.observe("touchstart", function(evt) {
    601633        _this.container_mousedown(evt);
    602       });
    603       this.container.bind('mouseup.chosen', function(evt) {
     634        return evt.preventDefault();
     635      });
     636      this.container.observe("touchend", function(evt) {
    604637        _this.container_mouseup(evt);
    605       });
    606       this.container.bind('mouseenter.chosen', function(evt) {
    607         _this.mouse_enter(evt);
    608       });
    609       this.container.bind('mouseleave.chosen', function(evt) {
    610         _this.mouse_leave(evt);
    611       });
    612       this.search_results.bind('mouseup.chosen', function(evt) {
    613         _this.search_results_mouseup(evt);
    614       });
    615       this.search_results.bind('mouseover.chosen', function(evt) {
    616         _this.search_results_mouseover(evt);
    617       });
    618       this.search_results.bind('mouseout.chosen', function(evt) {
    619         _this.search_results_mouseout(evt);
    620       });
    621       this.search_results.bind('mousewheel.chosen DOMMouseScroll.chosen', function(evt) {
    622         _this.search_results_mousewheel(evt);
    623       });
    624       this.search_results.bind('touchstart.chosen', function(evt) {
    625         _this.search_results_touchstart(evt);
    626       });
    627       this.search_results.bind('touchmove.chosen', function(evt) {
    628         _this.search_results_touchmove(evt);
    629       });
    630       this.search_results.bind('touchend.chosen', function(evt) {
    631         _this.search_results_touchend(evt);
    632       });
    633       this.form_field_jq.bind("chosen:updated.chosen", function(evt) {
    634         _this.results_update_field(evt);
    635       });
    636       this.form_field_jq.bind("chosen:activate.chosen", function(evt) {
    637         _this.activate_field(evt);
    638       });
    639       this.form_field_jq.bind("chosen:open.chosen", function(evt) {
    640         _this.container_mousedown(evt);
    641       });
    642       this.search_field.bind('blur.chosen', function(evt) {
    643         _this.input_blur(evt);
    644       });
    645       this.search_field.bind('keyup.chosen', function(evt) {
    646         _this.keyup_checker(evt);
    647       });
    648       this.search_field.bind('keydown.chosen', function(evt) {
    649         _this.keydown_checker(evt);
    650       });
    651       this.search_field.bind('focus.chosen', function(evt) {
    652         _this.input_focus(evt);
     638        return evt.preventDefault();
     639      });
     640      this.container.observe("mousedown", function(evt) {
     641        return _this.container_mousedown(evt);
     642      });
     643      this.container.observe("mouseup", function(evt) {
     644        return _this.container_mouseup(evt);
     645      });
     646      this.container.observe("mouseenter", function(evt) {
     647        return _this.mouse_enter(evt);
     648      });
     649      this.container.observe("mouseleave", function(evt) {
     650        return _this.mouse_leave(evt);
     651      });
     652      this.search_results.observe("mouseup", function(evt) {
     653        return _this.search_results_mouseup(evt);
     654      });
     655      this.search_results.observe("mouseover", function(evt) {
     656        return _this.search_results_mouseover(evt);
     657      });
     658      this.search_results.observe("mouseout", function(evt) {
     659        return _this.search_results_mouseout(evt);
     660      });
     661      this.search_results.observe("mousewheel", function(evt) {
     662        return _this.search_results_mousewheel(evt);
     663      });
     664      this.search_results.observe("DOMMouseScroll", function(evt) {
     665        return _this.search_results_mousewheel(evt);
     666      });
     667      this.search_results.observe("touchstart", function(evt) {
     668        return _this.search_results_touchstart(evt);
     669      });
     670      this.search_results.observe("touchmove", function(evt) {
     671        return _this.search_results_touchmove(evt);
     672      });
     673      this.search_results.observe("touchend", function(evt) {
     674        return _this.search_results_touchend(evt);
     675      });
     676      this.form_field.observe("chosen:updated", function(evt) {
     677        return _this.results_update_field(evt);
     678      });
     679      this.form_field.observe("chosen:activate", function(evt) {
     680        return _this.activate_field(evt);
     681      });
     682      this.form_field.observe("chosen:open", function(evt) {
     683        return _this.container_mousedown(evt);
     684      });
     685      this.form_field.observe("chosen:close", function(evt) {
     686        return _this.input_blur(evt);
     687      });
     688      this.search_field.observe("blur", function(evt) {
     689        return _this.input_blur(evt);
     690      });
     691      this.search_field.observe("keyup", function(evt) {
     692        return _this.keyup_checker(evt);
     693      });
     694      this.search_field.observe("keydown", function(evt) {
     695        return _this.keydown_checker(evt);
     696      });
     697      this.search_field.observe("focus", function(evt) {
     698        return _this.input_focus(evt);
     699      });
     700      this.search_field.observe("cut", function(evt) {
     701        return _this.clipboard_event_checker(evt);
     702      });
     703      this.search_field.observe("paste", function(evt) {
     704        return _this.clipboard_event_checker(evt);
    653705      });
    654706      if (this.is_multiple) {
    655         return this.search_choices.bind('click.chosen', function(evt) {
    656           _this.choices_click(evt);
     707        return this.search_choices.observe("click", function(evt) {
     708          return _this.choices_click(evt);
    657709        });
    658710      } else {
    659         return this.container.bind('click.chosen', function(evt) {
    660           evt.preventDefault();
     711        return this.container.observe("click", function(evt) {
     712          return evt.preventDefault();
    661713        });
    662714      }
     
    664716
    665717    Chosen.prototype.destroy = function() {
    666       $(document).unbind("click.chosen", this.click_test_action);
    667       if (this.search_field[0].tabIndex) {
    668         this.form_field_jq[0].tabIndex = this.search_field[0].tabIndex;
     718      this.container.ownerDocument.stopObserving("click", this.click_test_action);
     719      this.form_field.stopObserving();
     720      this.container.stopObserving();
     721      this.search_results.stopObserving();
     722      this.search_field.stopObserving();
     723      if (this.form_field_label != null) {
     724        this.form_field_label.stopObserving();
     725      }
     726      if (this.is_multiple) {
     727        this.search_choices.stopObserving();
     728        this.container.select(".search-choice-close").each(function(choice) {
     729          return choice.stopObserving();
     730        });
     731      } else {
     732        this.selected_item.stopObserving();
     733      }
     734      if (this.search_field.tabIndex) {
     735        this.form_field.tabIndex = this.search_field.tabIndex;
    669736      }
    670737      this.container.remove();
    671       this.form_field_jq.removeData('chosen');
    672       return this.form_field_jq.show();
     738      return this.form_field.show();
    673739    };
    674740
    675741    Chosen.prototype.search_field_disabled = function() {
    676       this.is_disabled = this.form_field_jq[0].disabled;
     742      this.is_disabled = this.form_field.disabled;
    677743      if (this.is_disabled) {
    678         this.container.addClass('chosen-disabled');
    679         this.search_field[0].disabled = true;
     744        this.container.addClassName('chosen-disabled');
     745        this.search_field.disabled = true;
    680746        if (!this.is_multiple) {
    681           this.selected_item.unbind("focus.chosen", this.activate_action);
     747          this.selected_item.stopObserving("focus", this.activate_action);
    682748        }
    683749        return this.close_field();
    684750      } else {
    685         this.container.removeClass('chosen-disabled');
    686         this.search_field[0].disabled = false;
     751        this.container.removeClassName('chosen-disabled');
     752        this.search_field.disabled = false;
    687753        if (!this.is_multiple) {
    688           return this.selected_item.bind("focus.chosen", this.activate_action);
     754          return this.selected_item.observe("focus", this.activate_action);
    689755        }
    690756      }
     
    694760      if (!this.is_disabled) {
    695761        if (evt && evt.type === "mousedown" && !this.results_showing) {
    696           evt.preventDefault();
    697         }
    698         if (!((evt != null) && ($(evt.target)).hasClass("search-choice-close"))) {
     762          evt.stop();
     763        }
     764        if (!((evt != null) && evt.target.hasClassName("search-choice-close"))) {
    699765          if (!this.active_field) {
    700766            if (this.is_multiple) {
    701               this.search_field.val("");
     767              this.search_field.clear();
    702768            }
    703             $(document).bind('click.chosen', this.click_test_action);
     769            this.container.ownerDocument.observe("click", this.click_test_action);
    704770            this.results_show();
    705           } else if (!this.is_multiple && evt && (($(evt.target)[0] === this.selected_item[0]) || $(evt.target).parents("a.chosen-single").length)) {
    706             evt.preventDefault();
     771          } else if (!this.is_multiple && evt && (evt.target === this.selected_item || evt.target.up("a.chosen-single"))) {
    707772            this.results_toggle();
    708773          }
     
    720785    Chosen.prototype.search_results_mousewheel = function(evt) {
    721786      var delta;
    722       if (evt.originalEvent) {
    723         delta = -evt.originalEvent.wheelDelta || evt.originalEvent.detail;
    724       }
     787      delta = evt.deltaY || -evt.wheelDelta || evt.detail;
    725788      if (delta != null) {
    726789        evt.preventDefault();
     
    728791          delta = delta * 40;
    729792        }
    730         return this.search_results.scrollTop(delta + this.search_results.scrollTop());
     793        return this.search_results.scrollTop = delta + this.search_results.scrollTop;
    731794      }
    732795    };
    733796
    734797    Chosen.prototype.blur_test = function(evt) {
    735       if (!this.active_field && this.container.hasClass("chosen-container-active")) {
     798      if (!this.active_field && this.container.hasClassName("chosen-container-active")) {
    736799        return this.close_field();
    737800      }
     
    739802
    740803    Chosen.prototype.close_field = function() {
    741       $(document).unbind("click.chosen", this.click_test_action);
     804      this.container.ownerDocument.stopObserving("click", this.click_test_action);
    742805      this.active_field = false;
    743806      this.results_hide();
    744       this.container.removeClass("chosen-container-active");
     807      this.container.removeClassName("chosen-container-active");
    745808      this.clear_backstroke();
    746809      this.show_search_field_default();
     
    749812
    750813    Chosen.prototype.activate_field = function() {
    751       this.container.addClass("chosen-container-active");
     814      this.container.addClassName("chosen-container-active");
    752815      this.active_field = true;
    753       this.search_field.val(this.search_field.val());
     816      this.search_field.value = this.search_field.value;
    754817      return this.search_field.focus();
    755818    };
    756819
    757820    Chosen.prototype.test_active_click = function(evt) {
    758       if (this.container.is($(evt.target).closest('.chosen-container'))) {
     821      if (evt.target.up('.chosen-container') === this.container) {
    759822        return this.active_field = true;
    760823      } else {
     
    768831      this.results_data = SelectParser.select_to_array(this.form_field);
    769832      if (this.is_multiple) {
    770         this.search_choices.find("li.search-choice").remove();
    771       } else {
     833        this.search_choices.select("li.search-choice").invoke("remove");
     834      } else if (!this.is_multiple) {
    772835        this.single_set_selected_text();
    773         this.single_set_nosearch();
     836        if (this.disable_search || this.form_field.options.length <= this.disable_search_threshold) {
     837          this.search_field.readOnly = true;
     838          this.container.addClassName("chosen-container-single-nosearch");
     839        } else {
     840          this.search_field.readOnly = false;
     841          this.container.removeClassName("chosen-container-single-nosearch");
     842        }
    774843      }
    775844      this.update_results_content(this.results_option_build({
     
    782851    };
    783852
    784     Chosen.prototype.single_set_nosearch = function() {
    785       if (this.disable_search || this.form_field.options.length <= this.disable_search_threshold) {
    786         this.search_field[0].readOnly = true;
    787         return this.container.addClass("chosen-container-single-nosearch");
    788       } else {
    789         this.search_field[0].readOnly = false;
    790         return this.container.removeClass("chosen-container-single-nosearch");
    791       }
    792     };
    793 
    794853    Chosen.prototype.result_do_highlight = function(el) {
    795854      var high_bottom, high_top, maxHeight, visible_bottom, visible_top;
    796       if (el.length) {
    797         this.result_clear_highlight();
    798         this.result_highlight = el;
    799         this.result_highlight.addClass("highlighted");
    800         maxHeight = parseInt(this.search_results.css("maxHeight"), 10);
    801         visible_top = this.search_results.scrollTop();
    802         visible_bottom = maxHeight + visible_top;
    803         high_top = this.result_highlight.position().top + this.search_results.scrollTop();
    804         high_bottom = high_top + this.result_highlight.outerHeight();
    805         if (high_bottom >= visible_bottom) {
    806           return this.search_results.scrollTop((high_bottom - maxHeight) > 0 ? high_bottom - maxHeight : 0);
    807         } else if (high_top < visible_top) {
    808           return this.search_results.scrollTop(high_top);
    809         }
     855      this.result_clear_highlight();
     856      this.result_highlight = el;
     857      this.result_highlight.addClassName("highlighted");
     858      maxHeight = parseInt(this.search_results.getStyle('maxHeight'), 10);
     859      visible_top = this.search_results.scrollTop;
     860      visible_bottom = maxHeight + visible_top;
     861      high_top = this.result_highlight.positionedOffset().top;
     862      high_bottom = high_top + this.result_highlight.getHeight();
     863      if (high_bottom >= visible_bottom) {
     864        return this.search_results.scrollTop = (high_bottom - maxHeight) > 0 ? high_bottom - maxHeight : 0;
     865      } else if (high_top < visible_top) {
     866        return this.search_results.scrollTop = high_top;
    810867      }
    811868    };
     
    813870    Chosen.prototype.result_clear_highlight = function() {
    814871      if (this.result_highlight) {
    815         this.result_highlight.removeClass("highlighted");
     872        this.result_highlight.removeClassName('highlighted');
    816873      }
    817874      return this.result_highlight = null;
     
    820877    Chosen.prototype.results_show = function() {
    821878      if (this.is_multiple && this.max_selected_options <= this.choices_count()) {
    822         this.form_field_jq.trigger("chosen:maxselected", {
     879        this.form_field.fire("chosen:maxselected", {
    823880          chosen: this
    824881        });
    825882        return false;
    826883      }
    827       this.container.addClass("chosen-with-drop");
    828       this.form_field_jq.trigger("chosen:showing_dropdown", {
    829         chosen: this
    830       });
     884      this.container.addClassName("chosen-with-drop");
    831885      this.results_showing = true;
    832886      this.search_field.focus();
    833       this.search_field.val(this.search_field.val());
    834       return this.winnow_results();
     887      this.search_field.value = this.search_field.value;
     888      this.winnow_results();
     889      return this.form_field.fire("chosen:showing_dropdown", {
     890        chosen: this
     891      });
    835892    };
    836893
    837894    Chosen.prototype.update_results_content = function(content) {
    838       return this.search_results.html(content);
     895      return this.search_results.update(content);
    839896    };
    840897
     
    842899      if (this.results_showing) {
    843900        this.result_clear_highlight();
    844         this.container.removeClass("chosen-with-drop");
    845         this.form_field_jq.trigger("chosen:hiding_dropdown", {
     901        this.container.removeClassName("chosen-with-drop");
     902        this.form_field.fire("chosen:hiding_dropdown", {
    846903          chosen: this
    847904        });
     
    855912        ti = this.form_field.tabIndex;
    856913        this.form_field.tabIndex = -1;
    857         return this.search_field[0].tabIndex = ti;
     914        return this.search_field.tabIndex = ti;
    858915      }
    859916    };
     
    861918    Chosen.prototype.set_label_behavior = function() {
    862919      var _this = this;
    863       this.form_field_label = this.form_field_jq.parents("label");
    864       if (!this.form_field_label.length && this.form_field.id.length) {
    865         this.form_field_label = $("label[for='" + this.form_field.id + "']");
    866       }
    867       if (this.form_field_label.length > 0) {
    868         return this.form_field_label.bind('click.chosen', function(evt) {
     920      this.form_field_label = this.form_field.up("label");
     921      if (this.form_field_label == null) {
     922        this.form_field_label = $$("label[for='" + this.form_field.id + "']").first();
     923      }
     924      if (this.form_field_label != null) {
     925        return this.form_field_label.observe("click", function(evt) {
    869926          if (_this.is_multiple) {
    870927            return _this.container_mousedown(evt);
     
    878935    Chosen.prototype.show_search_field_default = function() {
    879936      if (this.is_multiple && this.choices_count() < 1 && !this.active_field) {
    880         this.search_field.val(this.default_text);
    881         return this.search_field.addClass("default");
    882       } else {
    883         this.search_field.val("");
    884         return this.search_field.removeClass("default");
     937        this.search_field.value = this.default_text;
     938        return this.search_field.addClassName("default");
     939      } else {
     940        this.search_field.value = "";
     941        return this.search_field.removeClassName("default");
    885942      }
    886943    };
     
    888945    Chosen.prototype.search_results_mouseup = function(evt) {
    889946      var target;
    890       target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
    891       if (target.length) {
     947      target = evt.target.hasClassName("active-result") ? evt.target : evt.target.up(".active-result");
     948      if (target) {
    892949        this.result_highlight = target;
    893950        this.result_select(evt);
     
    898955    Chosen.prototype.search_results_mouseover = function(evt) {
    899956      var target;
    900       target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
     957      target = evt.target.hasClassName("active-result") ? evt.target : evt.target.up(".active-result");
    901958      if (target) {
    902959        return this.result_do_highlight(target);
     
    905962
    906963    Chosen.prototype.search_results_mouseout = function(evt) {
    907       if ($(evt.target).hasClass("active-result" || $(evt.target).parents('.active-result').first())) {
     964      if (evt.target.hasClassName('active-result') || evt.target.up('.active-result')) {
    908965        return this.result_clear_highlight();
    909966      }
     
    913970      var choice, close_link,
    914971        _this = this;
    915       choice = $('<li />', {
     972      choice = new Element('li', {
    916973        "class": "search-choice"
    917       }).html("<span>" + item.html + "</span>");
     974      }).update("<span>" + (this.choice_label(item)) + "</span>");
    918975      if (item.disabled) {
    919         choice.addClass('search-choice-disabled');
    920       } else {
    921         close_link = $('<a />', {
     976        choice.addClassName('search-choice-disabled');
     977      } else {
     978        close_link = new Element('a', {
     979          href: '#',
    922980          "class": 'search-choice-close',
    923           'data-option-array-index': item.array_index
     981          rel: item.array_index
    924982        });
    925         close_link.bind('click.chosen', function(evt) {
     983        close_link.observe("click", function(evt) {
    926984          return _this.choice_destroy_link_click(evt);
    927985        });
    928         choice.append(close_link);
    929       }
    930       return this.search_container.before(choice);
     986        choice.insert(close_link);
     987      }
     988      return this.search_container.insert({
     989        before: choice
     990      });
    931991    };
    932992
     
    935995      evt.stopPropagation();
    936996      if (!this.is_disabled) {
    937         return this.choice_destroy($(evt.target));
     997        return this.choice_destroy(evt.target);
    938998      }
    939999    };
    9401000
    9411001    Chosen.prototype.choice_destroy = function(link) {
    942       if (this.result_deselect(link[0].getAttribute("data-option-array-index"))) {
     1002      if (this.result_deselect(link.readAttribute("rel"))) {
    9431003        this.show_search_field_default();
    944         if (this.is_multiple && this.choices_count() > 0 && this.search_field.val().length < 1) {
     1004        if (this.is_multiple && this.choices_count() > 0 && this.search_field.value.length < 1) {
    9451005          this.results_hide();
    9461006        }
    947         link.parents('li').first().remove();
     1007        link.up('li').remove();
    9481008        return this.search_field_scale();
    9491009      }
     
    9561016      this.show_search_field_default();
    9571017      this.results_reset_cleanup();
    958       this.form_field_jq.trigger("change");
     1018      if (typeof Event.simulate === 'function') {
     1019        this.form_field.simulate("change");
     1020      }
    9591021      if (this.active_field) {
    9601022        return this.results_hide();
     
    9631025
    9641026    Chosen.prototype.results_reset_cleanup = function() {
     1027      var deselect_trigger;
    9651028      this.current_selectedIndex = this.form_field.selectedIndex;
    966       return this.selected_item.find("abbr").remove();
     1029      deselect_trigger = this.selected_item.down("abbr");
     1030      if (deselect_trigger) {
     1031        return deselect_trigger.remove();
     1032      }
    9671033    };
    9681034
     
    9731039        this.result_clear_highlight();
    9741040        if (this.is_multiple && this.max_selected_options <= this.choices_count()) {
    975           this.form_field_jq.trigger("chosen:maxselected", {
     1041          this.form_field.fire("chosen:maxselected", {
    9761042            chosen: this
    9771043          });
     
    9791045        }
    9801046        if (this.is_multiple) {
    981           high.removeClass("active-result");
     1047          high.removeClassName("active-result");
    9821048        } else {
    9831049          this.reset_single_select_options();
    9841050        }
    985         item = this.results_data[high[0].getAttribute("data-option-array-index")];
     1051        high.addClassName("result-selected");
     1052        item = this.results_data[high.getAttribute("data-option-array-index")];
    9861053        item.selected = true;
    9871054        this.form_field.options[item.options_index].selected = true;
     
    9901057          this.choice_build(item);
    9911058        } else {
    992           this.single_set_selected_text(item.text);
     1059          this.single_set_selected_text(this.choice_label(item));
    9931060        }
    9941061        if (!((evt.metaKey || evt.ctrlKey) && this.is_multiple)) {
    9951062          this.results_hide();
    9961063        }
    997         this.search_field.val("");
    998         if (this.is_multiple || this.form_field.selectedIndex !== this.current_selectedIndex) {
    999           this.form_field_jq.trigger("change", {
    1000             'selected': this.form_field.options[item.options_index].value
    1001           });
     1064        this.show_search_field_default();
     1065        if (typeof Event.simulate === 'function' && (this.is_multiple || this.form_field.selectedIndex !== this.current_selectedIndex)) {
     1066          this.form_field.simulate("change");
    10021067        }
    10031068        this.current_selectedIndex = this.form_field.selectedIndex;
     1069        evt.preventDefault();
    10041070        return this.search_field_scale();
    10051071      }
     
    10111077      }
    10121078      if (text === this.default_text) {
    1013         this.selected_item.addClass("chosen-default");
     1079        this.selected_item.addClassName("chosen-default");
    10141080      } else {
    10151081        this.single_deselect_control_build();
    1016         this.selected_item.removeClass("chosen-default");
    1017       }
    1018       return this.selected_item.find("span").text(text);
     1082        this.selected_item.removeClassName("chosen-default");
     1083      }
     1084      return this.selected_item.down("span").update(text);
    10191085    };
    10201086
     
    10301096          this.winnow_results();
    10311097        }
    1032         this.form_field_jq.trigger("change", {
    1033           deselected: this.form_field.options[result_data.options_index].value
    1034         });
     1098        if (typeof Event.simulate === 'function') {
     1099          this.form_field.simulate("change");
     1100        }
    10351101        this.search_field_scale();
    10361102        return true;
     
    10441110        return;
    10451111      }
    1046       if (!this.selected_item.find("abbr").length) {
    1047         this.selected_item.find("span").first().after("<abbr class=\"search-choice-close\"></abbr>");
    1048       }
    1049       return this.selected_item.addClass("chosen-single-with-deselect");
     1112      if (!this.selected_item.down("abbr")) {
     1113        this.selected_item.down("span").insert({
     1114          after: "<abbr class=\"search-choice-close\"></abbr>"
     1115        });
     1116      }
     1117      return this.selected_item.addClassName("chosen-single-with-deselect");
    10501118    };
    10511119
    10521120    Chosen.prototype.get_search_text = function() {
    1053       if (this.search_field.val() === this.default_text) {
    1054         return "";
    1055       } else {
    1056         return $('<div/>').text($.trim(this.search_field.val())).html();
    1057       }
     1121      return this.search_field.value.strip().escapeHTML();
    10581122    };
    10591123
    10601124    Chosen.prototype.winnow_results_set_highlight = function() {
    1061       var do_high, selected_results;
    1062       selected_results = !this.is_multiple ? this.search_results.find(".result-selected.active-result") : [];
    1063       do_high = selected_results.length ? selected_results.first() : this.search_results.find(".active-result").first();
     1125      var do_high;
     1126      if (!this.is_multiple) {
     1127        do_high = this.search_results.down(".result-selected.active-result");
     1128      }
     1129      if (do_high == null) {
     1130        do_high = this.search_results.down(".active-result");
     1131      }
    10641132      if (do_high != null) {
    10651133        return this.result_do_highlight(do_high);
     
    10681136
    10691137    Chosen.prototype.no_results = function(terms) {
    1070       var no_results_html;
    1071       no_results_html = $('<li class="no-results">' + this.results_none_found + ' "<span></span>"</li>');
    1072       no_results_html.find("span").first().html(terms);
    1073       return this.search_results.append(no_results_html);
     1138      this.search_results.insert(this.no_results_temp.evaluate({
     1139        terms: terms
     1140      }));
     1141      return this.form_field.fire("chosen:no_results", {
     1142        chosen: this
     1143      });
    10741144    };
    10751145
    10761146    Chosen.prototype.no_results_clear = function() {
    1077       return this.search_results.find(".no-results").remove();
     1147      var nr, _results;
     1148      nr = null;
     1149      _results = [];
     1150      while (nr = this.search_results.down(".no-results")) {
     1151        _results.push(nr.remove());
     1152      }
     1153      return _results;
    10781154    };
    10791155
     
    10811157      var next_sib;
    10821158      if (this.results_showing && this.result_highlight) {
    1083         next_sib = this.result_highlight.nextAll("li.active-result").first();
     1159        next_sib = this.result_highlight.next('.active-result');
    10841160        if (next_sib) {
    10851161          return this.result_do_highlight(next_sib);
     
    10911167
    10921168    Chosen.prototype.keyup_arrow = function() {
    1093       var prev_sibs;
     1169      var actives, prevs, sibs;
    10941170      if (!this.results_showing && !this.is_multiple) {
    10951171        return this.results_show();
    10961172      } else if (this.result_highlight) {
    1097         prev_sibs = this.result_highlight.prevAll("li.active-result");
    1098         if (prev_sibs.length) {
    1099           return this.result_do_highlight(prev_sibs.first());
     1173        sibs = this.result_highlight.previousSiblings();
     1174        actives = this.search_results.select("li.active-result");
     1175        prevs = sibs.intersect(actives);
     1176        if (prevs.length) {
     1177          return this.result_do_highlight(prevs.first());
    11001178        } else {
    11011179          if (this.choices_count() > 0) {
     
    11101188      var next_available_destroy;
    11111189      if (this.pending_backstroke) {
    1112         this.choice_destroy(this.pending_backstroke.find("a").first());
     1190        this.choice_destroy(this.pending_backstroke.down("a"));
    11131191        return this.clear_backstroke();
    11141192      } else {
    1115         next_available_destroy = this.search_container.siblings("li.search-choice").last();
    1116         if (next_available_destroy.length && !next_available_destroy.hasClass("search-choice-disabled")) {
     1193        next_available_destroy = this.search_container.siblings().last();
     1194        if (next_available_destroy && next_available_destroy.hasClassName("search-choice") && !next_available_destroy.hasClassName("search-choice-disabled")) {
    11171195          this.pending_backstroke = next_available_destroy;
     1196          if (this.pending_backstroke) {
     1197            this.pending_backstroke.addClassName("search-choice-focus");
     1198          }
    11181199          if (this.single_backstroke_delete) {
    11191200            return this.keydown_backstroke();
    11201201          } else {
    1121             return this.pending_backstroke.addClass("search-choice-focus");
     1202            return this.pending_backstroke.addClassName("search-choice-focus");
    11221203          }
    11231204        }
     
    11271208    Chosen.prototype.clear_backstroke = function() {
    11281209      if (this.pending_backstroke) {
    1129         this.pending_backstroke.removeClass("search-choice-focus");
     1210        this.pending_backstroke.removeClassName("search-choice-focus");
    11301211      }
    11311212      return this.pending_backstroke = null;
     
    11411222      switch (stroke) {
    11421223        case 8:
    1143           this.backstroke_length = this.search_field.val().length;
     1224          this.backstroke_length = this.search_field.value.length;
    11441225          break;
    11451226        case 9:
     
    11501231          break;
    11511232        case 13:
    1152           evt.preventDefault();
     1233          if (this.results_showing) {
     1234            evt.preventDefault();
     1235          }
     1236          break;
     1237        case 32:
     1238          if (this.disable_search) {
     1239            evt.preventDefault();
     1240          }
    11531241          break;
    11541242        case 38:
     
    11721260        for (_i = 0, _len = styles.length; _i < _len; _i++) {
    11731261          style = styles[_i];
    1174           style_block += style + ":" + this.search_field.css(style) + ";";
    1175         }
    1176         div = $('<div />', {
     1262          style_block += style + ":" + this.search_field.getStyle(style) + ";";
     1263        }
     1264        div = new Element('div', {
    11771265          'style': style_block
    1178         });
    1179         div.text(this.search_field.val());
    1180         $('body').append(div);
    1181         w = div.width() + 25;
     1266        }).update(this.search_field.value.escapeHTML());
     1267        document.body.appendChild(div);
     1268        w = Element.measure(div, 'width') + 25;
    11821269        div.remove();
    1183         f_width = this.container.outerWidth();
     1270        f_width = this.container.getWidth();
    11841271        if (w > f_width - 10) {
    11851272          w = f_width - 10;
    11861273        }
    1187         return this.search_field.css({
     1274        return this.search_field.setStyle({
    11881275          'width': w + 'px'
    11891276        });
     
    11951282  })(AbstractChosen);
    11961283
    1197   $ = jQuery;
    1198 
    1199   $.fn.extend({
    1200     chosen: function(options) {
    1201       if (!AbstractChosen.browser_is_supported()) {
    1202         return this;
    1203       }
    1204       return this.each(function(input_field) {
    1205         var $this, chosen;
    1206         $this = $(this);
    1207         chosen = $this.data('chosen');
    1208         if (options === 'destroy' && chosen) {
    1209           chosen.destroy();
    1210         } else if (!chosen) {
    1211           $this.data('chosen', new ChosenOptionAdding(this, options));
    1212         }
    1213       });
    1214     }
    1215   });
    1216 
    1217   ChosenOptionAdding = (function(_super) {
    1218     __extends(ChosenOptionAdding, _super);
    1219 
    1220     function ChosenOptionAdding() {
    1221       _ref1 = ChosenOptionAdding.__super__.constructor.apply(this, arguments);
    1222       return _ref1;
    1223     }
    1224 
    1225     ChosenOptionAdding.prototype.set_default_values = function() {
    1226       ChosenOptionAdding.__super__.set_default_values.apply(this, arguments);
    1227       this.create_option = this.options.create_option || false;
    1228       this.persistent_create_option = this.options.persistent_create_option || false;
    1229       return this.skip_no_results = this.options.skip_no_results || false;
    1230     };
    1231 
    1232     ChosenOptionAdding.prototype.set_default_text = function() {
    1233       ChosenOptionAdding.__super__.set_default_text.apply(this, arguments);
    1234       return this.create_option_text = this.form_field.getAttribute("data-create_option_text") || this.options.create_option_text || 'Add option ';
    1235     };
    1236 
    1237     ChosenOptionAdding.prototype.single_set_nosearch = function() {
    1238       if (this.disable_search || this.form_field.options.length <= this.disable_search_threshold && !this.create_option) {
    1239         this.search_field[0].readOnly = true;
    1240         return this.container.addClass("chosen-container-single-nosearch");
    1241       } else {
    1242         this.search_field[0].readOnly = false;
    1243         return this.container.removeClass("chosen-container-single-nosearch");
    1244       }
    1245     };
    1246 
    1247     ChosenOptionAdding.prototype.result_select = function(evt) {
    1248       if (this.result_highlight) {
    1249         if (this.result_highlight.hasClass("create-option")) {
    1250           this.select_create_option(this.search_field.val());
    1251           return this.results_hide();
    1252         }
    1253         return ChosenOptionAdding.__super__.result_select.apply(this, arguments);
    1254       }
    1255     };
    1256 
    1257     ChosenOptionAdding.prototype.show_create_option = function(terms) {
    1258       var create_option_html;
    1259       create_option_html = $('<li class="create-option active-result"><a>' + this.create_option_text + '</a>: "' + terms + '"</li>');
    1260       return this.search_results.append(create_option_html);
    1261     };
    1262 
    1263     ChosenOptionAdding.prototype.create_option_clear = function() {
    1264       return this.search_results.find(".create-option").remove();
    1265     };
    1266 
    1267     ChosenOptionAdding.prototype.select_create_option = function(terms) {
    1268       if ($.isFunction(this.create_option)) {
    1269         return this.create_option.call(this, terms);
    1270       } else {
    1271         return this.select_append_option({
    1272           value: terms,
    1273           text: terms
    1274         });
    1275       }
    1276     };
    1277 
    1278     ChosenOptionAdding.prototype.select_append_option = function(options) {
    1279       var option;
    1280       option = $('<option />', options).attr('selected', 'selected');
    1281       this.form_field_jq.append(option);
    1282       this.form_field_jq.trigger("chosen:updated");
    1283       this.form_field_jq.trigger("change");
    1284       return this.search_field.trigger("focus");
    1285     };
    1286 
    1287     ChosenOptionAdding.prototype.append_option = function(option) {
    1288       return this.select_append_option(option);
    1289     };
    1290 
    1291     ChosenOptionAdding.prototype.no_results = function(terms) {
    1292       if (!(this.create_option && this.skip_no_results)) {
    1293         return ChosenOptionAdding.__super__.no_results.call(this, terms);
    1294       }
    1295     };
    1296 
    1297     ChosenOptionAdding.prototype.keydown_arrow = function() {
    1298       var next_sib;
    1299       if (this.results_showing && this.result_highlight) {
    1300         next_sib = this.result_highlight.nextAll("li.active-result").first();
    1301         if (next_sib) {
    1302           return this.result_do_highlight(next_sib);
    1303         }
    1304       } else if (this.results_showing && this.create_option) {
    1305         return this.result_do_highlight(this.search_results.find('.create-option'));
    1306       } else {
    1307         return this.results_show();
    1308       }
    1309     };
    1310 
    1311     ChosenOptionAdding.prototype.winnow_results = function() {
    1312       var eregex, escapedSearchText, exact_result, option, regex, regexAnchor, results, results_group, searchText, startpos, text, zregex, _i, _len, _ref2;
    1313       this.no_results_clear();
    1314       results = 0;
    1315       exact_result = false;
    1316       searchText = this.get_search_text();
    1317       escapedSearchText = searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
    1318       regexAnchor = this.search_contains ? "" : "^";
    1319       regex = new RegExp(regexAnchor + escapedSearchText, 'i');
    1320       zregex = new RegExp(escapedSearchText, 'i');
    1321       eregex = new RegExp('^' + escapedSearchText + '$', 'i');
    1322       _ref2 = this.results_data;
    1323       for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
    1324         option = _ref2[_i];
    1325         option.search_match = false;
    1326         results_group = null;
    1327         if (this.include_option_in_results(option)) {
    1328           if (option.group) {
    1329             option.group_match = false;
    1330             option.active_options = 0;
    1331           }
    1332           if ((option.group_array_index != null) && this.results_data[option.group_array_index]) {
    1333             results_group = this.results_data[option.group_array_index];
    1334             if (results_group.active_options === 0 && results_group.search_match) {
    1335               results += 1;
    1336             }
    1337             results_group.active_options += 1;
    1338           }
    1339           if (!(option.group && !this.group_search)) {
    1340             option.search_text = option.group ? option.label : option.html;
    1341             option.search_match = this.search_string_match(option.search_text, regex);
    1342             if (option.search_match && !option.group) {
    1343               results += 1;
    1344             }
    1345             exact_result = eregex.test(option.html);
    1346             if (option.search_match) {
    1347               if (searchText.length) {
    1348                 startpos = option.search_text.search(zregex);
    1349                 text = option.search_text.substr(0, startpos + searchText.length) + '</em>' + option.search_text.substr(startpos + searchText.length);
    1350                 option.search_text = text.substr(0, startpos) + '<em>' + text.substr(startpos);
    1351               }
    1352               if (results_group != null) {
    1353                 results_group.group_match = true;
    1354               }
    1355             } else if ((option.group_array_index != null) && this.results_data[option.group_array_index].search_match) {
    1356               option.search_match = true;
    1357             }
    1358           }
    1359         }
    1360       }
    1361       this.result_clear_highlight();
    1362       if (results < 1 && searchText.length) {
    1363         this.update_results_content("");
    1364         if (!(this.create_option && this.skip_no_results)) {
    1365           this.no_results(searchText);
    1366         }
    1367       } else {
    1368         this.update_results_content(this.results_option_build());
    1369         this.winnow_results_set_highlight();
    1370       }
    1371       if (this.create_option && (results < 1 || (!exact_result && this.persistent_create_option)) && searchText.length) {
    1372         return this.show_create_option(searchText);
    1373       }
    1374     };
    1375 
    1376     return ChosenOptionAdding;
    1377 
    1378   })(Chosen);
    1379 
    13801284}).call(this);
Note: See TracChangeset for help on using the changeset viewer.