Changeset 89038 in spip-zone


Ignore:
Timestamp:
May 4, 2015, 2:06:56 PM (4 years ago)
Author:
kent1@…
Message:

Utiliser la dernière version de https://github.com/koenpunt/chosen/releases

On utilise cette version pour bénéficier de https://github.com/harvesthq/chosen/pull/166

Location:
_plugins_/chosen/trunk/lib/chosen
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • _plugins_/chosen/trunk/lib/chosen/chosen.css

    r78059 r89038  
     1/*!
     2Chosen, a Select Box Enhancer for jQuery and Prototype
     3by Patrick Filler for Harvest, http://getharvest.com
     4
     5Version 1.1.0
     6Full source at https://github.com/harvesthq/chosen
     7Copyright (c) 2011 Harvest http://getharvest.com
     8
     9MIT License, https://github.com/harvesthq/chosen/blob/master/LICENSE.md
     10This file is generated by `grunt build`, do not edit it by hand.
     11*/
     12
     13/*!
     14Chosen, a Select Box Enhancer for jQuery and Prototype
     15by Patrick Filler for Harvest, http://getharvest.com
     16
     17Version 1.1.0
     18Full source at https://github.com/harvesthq/chosen
     19Copyright (c) 2011 Harvest http://getharvest.com
     20
     21MIT License, https://github.com/harvesthq/chosen/blob/master/LICENSE.md
     22This file is generated by `grunt build`, do not edit it by hand.
     23*/
     24
    125/* @group Base */
    226.chosen-container {
     
    832  *display: inline;
    933  -moz-user-select: -moz-none;
     34  -ms-user-select: none;
    1035  -webkit-user-select: none;
    11   -ms-user-select: none;
    1236  user-select: none;
    1337}
     
    1741  left: -9999px;
    1842  z-index: 1010;
     43  -moz-box-sizing: border-box;
    1944  -webkit-box-sizing: border-box;
    20   -moz-box-sizing: border-box;
    2145  box-sizing: border-box;
    2246  width: 100%;
     
    4468  border-radius: 5px;
    4569  background-color: #fff;
    46   background: -webkit-linear-gradient(top, #ffffff 20%, #f6f6f6 50%, #eeeeee 52%, #f4f4f4 100%);
    4770  background: -moz-linear-gradient(top, #ffffff 20%, #f6f6f6 50%, #eeeeee 52%, #f4f4f4 100%);
    4871  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%);
    4973  background: linear-gradient(to bottom, #ffffff 20%, #f6f6f6 50%, #eeeeee 52%, #f4f4f4 100%);
    5074  background-clip: padding-box;
     
    106130}
    107131.chosen-container-single .chosen-search input[type="text"] {
     132  -moz-box-sizing: border-box;
    108133  -webkit-box-sizing: border-box;
    109   -moz-box-sizing: border-box;
    110134  box-sizing: border-box;
    111135  margin: 1px 0;
     
    116140  border: 1px solid #aaa;
    117141  background: white url('chosen-sprite.png') no-repeat 100% -20px;
    118   background: url('chosen-sprite.png') no-repeat 100% -20px, -webkit-linear-gradient(#eeeeee 1%, #ffffff 15%);
    119   background: url('chosen-sprite.png') no-repeat 100% -20px, -moz-linear-gradient(#eeeeee 1%, #ffffff 15%);
    120   background: url('chosen-sprite.png') no-repeat 100% -20px, -o-linear-gradient(#eeeeee 1%, #ffffff 15%);
    121   background: url('chosen-sprite.png') no-repeat 100% -20px, linear-gradient(#eeeeee 1%, #ffffff 15%);
     142  background: url('chosen-sprite.png') no-repeat 100% -20px;
    122143  font-size: 1em;
    123144  font-family: sans-serif;
     
    165186.chosen-container .chosen-results li.highlighted {
    166187  background-color: #3875d7;
    167   background-image: -webkit-linear-gradient(#3875d7 20%, #2a62bc 90%);
    168188  background-image: -moz-linear-gradient(#3875d7 20%, #2a62bc 90%);
    169189  background-image: -o-linear-gradient(#3875d7 20%, #2a62bc 90%);
     190  background-image: -webkit-linear-gradient(#3875d7 20%, #2a62bc 90%);
    170191  background-image: linear-gradient(#3875d7 20%, #2a62bc 90%);
    171192  color: #fff;
     
    193214  position: relative;
    194215  overflow: hidden;
     216  -moz-box-sizing: border-box;
    195217  -webkit-box-sizing: border-box;
    196   -moz-box-sizing: border-box;
    197218  box-sizing: border-box;
    198219  margin: 0;
     
    203224  border: 1px solid #aaa;
    204225  background-color: #fff;
    205   background-image: -webkit-linear-gradient(#eeeeee 1%, #ffffff 15%);
    206226  background-image: -moz-linear-gradient(#eeeeee 1%, #ffffff 15%);
    207227  background-image: -o-linear-gradient(#eeeeee 1%, #ffffff 15%);
     228  background-image: -webkit-linear-gradient(#eeeeee 1%, #ffffff 15%);
    208229  background-image: linear-gradient(#eeeeee 1%, #ffffff 15%);
    209230  cursor: text;
     
    242263  border-radius: 3px;
    243264  background-color: #e4e4e4;
    244   background-image: -webkit-linear-gradient(#f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%);
    245265  background-image: -moz-linear-gradient(#f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%);
    246266  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%);
    247268  background-image: linear-gradient(#f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%);
    248269  background-clip: padding-box;
     
    269290  border: 1px solid #ccc;
    270291  background-color: #e4e4e4;
    271   background-image: -webkit-linear-gradient(top, #f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%);
    272292  background-image: -moz-linear-gradient(top, #f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%);
    273293  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%);
    274295  background-image: linear-gradient(to bottom, #f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%);
    275296  color: #666;
     
    303324  -moz-border-radius-bottomleft: 0;
    304325  border-bottom-left-radius: 0;
    305   background-image: -webkit-linear-gradient(#eeeeee 20%, #ffffff 80%);
    306326  background-image: -moz-linear-gradient(#eeeeee 20%, #ffffff 80%);
    307327  background-image: -o-linear-gradient(#eeeeee 20%, #ffffff 80%);
     328  background-image: -webkit-linear-gradient(#eeeeee 20%, #ffffff 80%);
    308329  background-image: linear-gradient(#eeeeee 20%, #ffffff 80%);
    309330  box-shadow: 0 1px 0 #fff inset;
     
    394415  padding: 4px 5px 4px 20px;
    395416  background: white url('chosen-sprite.png') no-repeat -30px -20px;
    396   background: url('chosen-sprite.png') no-repeat -30px -20px, -webkit-linear-gradient(#eeeeee 1%, #ffffff 15%);
    397   background: url('chosen-sprite.png') no-repeat -30px -20px, -moz-linear-gradient(#eeeeee 1%, #ffffff 15%);
    398   background: url('chosen-sprite.png') no-repeat -30px -20px, -o-linear-gradient(#eeeeee 1%, #ffffff 15%);
    399   background: url('chosen-sprite.png') no-repeat -30px -20px, linear-gradient(#eeeeee 1%, #ffffff 15%);
     417  background: url('chosen-sprite.png') no-repeat -30px -20px;
    400418  direction: rtl;
    401419}
  • _plugins_/chosen/trunk/lib/chosen/chosen.jquery.js

    r78059 r89038  
    1 // Chosen, a Select Box Enhancer for jQuery and Prototype
    2 // by Patrick Filler for Harvest, http://getharvest.com
    3 //
    4 // Version 1.0.0
    5 // Full source at https://github.com/harvesthq/chosen
    6 // Copyright (c) 2011 Harvest http://getharvest.com
    7 
    8 // MIT License, https://github.com/harvesthq/chosen/blob/master/LICENSE.md
    9 // This file is generated by `grunt build`, do not edit it by hand.
     1/*!
     2Chosen, a Select Box Enhancer for jQuery and Prototype
     3by Patrick Filler for Harvest, http://getharvest.com
     4
     5Version 1.1.0
     6Full source at https://github.com/harvesthq/chosen
     7Copyright (c) 2011 Harvest http://getharvest.com
     8
     9MIT License, https://github.com/harvesthq/chosen/blob/master/LICENSE.md
     10This file is generated by `grunt build`, do not edit it by hand.
     11
     12Attention : this is a forked version to add the create option (https://github.com/harvesthq/chosen/pull/166)
     13This release is issued from https://github.com/koenpunt/chosen/releases
     14*/
     15
    1016(function() {
    11   var $, AbstractChosen, Chosen, SelectParser, _ref,
     17  var $, AbstractChosen, Chosen, ChosenOptionAdding, SelectParser, _ref, _ref1,
    1218    __hasProp = {}.hasOwnProperty,
    1319    __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; };
     
    148154      this.inherit_select_classes = this.options.inherit_select_classes || false;
    149155      this.display_selected_options = this.options.display_selected_options != null ? this.options.display_selected_options : true;
    150       this.display_disabled_options = this.options.display_disabled_options != null ? this.options.display_disabled_options : true;
    151       this.create_option = this.options.create_option || false;
    152       this.persistent_create_option = this.options.persistent_create_option || false;
    153       return this.skip_no_results = this.options.skip_no_results || false;
     156      return this.display_disabled_options = this.options.display_disabled_options != null ? this.options.display_disabled_options : true;
    154157    };
    155158
     
    162165        this.default_text = this.options.placeholder_text_single || this.options.placeholder_text || AbstractChosen.default_single_text;
    163166      }
    164       this.results_none_found = this.form_field.getAttribute("data-no_results_text") || this.options.no_results_text || AbstractChosen.default_no_result_text;
    165       return this.create_option_text = this.form_field.getAttribute("data-create_option_text") || this.options.create_option_text || AbstractChosen.default_create_option_text;
     167      return this.results_none_found = this.form_field.getAttribute("data-no_results_text") || this.options.no_results_text || AbstractChosen.default_no_result_text;
    166168    };
    167169
     
    267269    };
    268270
    269     AbstractChosen.prototype.append_option = function(option) {
    270       return this.select_append_option(option);
    271     };
    272 
    273271    AbstractChosen.prototype.results_update_field = function() {
    274272      this.set_default_text();
     
    315313
    316314    AbstractChosen.prototype.winnow_results = function() {
    317       var eregex, escapedSearchText, exact_result, option, regex, regexAnchor, results, results_group, searchText, startpos, text, zregex, _i, _len, _ref;
     315      var escapedSearchText, option, regex, regexAnchor, results, results_group, searchText, startpos, text, zregex, _i, _len, _ref;
     316      this.no_results_clear();
     317      results = 0;
     318      searchText = this.get_search_text();
     319      escapedSearchText = searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
     320      regexAnchor = this.search_contains ? "" : "^";
     321      regex = new RegExp(regexAnchor + escapedSearchText, 'i');
     322      zregex = new RegExp(escapedSearchText, 'i');
     323      _ref = this.results_data;
     324      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
     325        option = _ref[_i];
     326        option.search_match = false;
     327        results_group = null;
     328        if (this.include_option_in_results(option)) {
     329          if (option.group) {
     330            option.group_match = false;
     331            option.active_options = 0;
     332          }
     333          if ((option.group_array_index != null) && this.results_data[option.group_array_index]) {
     334            results_group = this.results_data[option.group_array_index];
     335            if (results_group.active_options === 0 && results_group.search_match) {
     336              results += 1;
     337            }
     338            results_group.active_options += 1;
     339          }
     340          if (!(option.group && !this.group_search)) {
     341            option.search_text = option.group ? option.label : option.html;
     342            option.search_match = this.search_string_match(option.search_text, regex);
     343            if (option.search_match && !option.group) {
     344              results += 1;
     345            }
     346            if (option.search_match) {
     347              if (searchText.length) {
     348                startpos = option.search_text.search(zregex);
     349                text = option.search_text.substr(0, startpos + searchText.length) + '</em>' + option.search_text.substr(startpos + searchText.length);
     350                option.search_text = text.substr(0, startpos) + '<em>' + text.substr(startpos);
     351              }
     352              if (results_group != null) {
     353                results_group.group_match = true;
     354              }
     355            } else if ((option.group_array_index != null) && this.results_data[option.group_array_index].search_match) {
     356              option.search_match = true;
     357            }
     358          }
     359        }
     360      }
     361      this.result_clear_highlight();
     362      if (results < 1 && searchText.length) {
     363        this.update_results_content("");
     364        return this.no_results(searchText);
     365      } else {
     366        this.update_results_content(this.results_option_build());
     367        return this.winnow_results_set_highlight();
     368      }
     369    };
     370
     371    AbstractChosen.prototype.search_string_match = function(search_string, regex) {
     372      var part, parts, _i, _len;
     373      if (regex.test(search_string)) {
     374        return true;
     375      } else if (this.enable_split_word_search && (search_string.indexOf(" ") >= 0 || search_string.indexOf("[") === 0)) {
     376        parts = search_string.replace(/\[|\]/g, "").split(" ");
     377        if (parts.length) {
     378          for (_i = 0, _len = parts.length; _i < _len; _i++) {
     379            part = parts[_i];
     380            if (regex.test(part)) {
     381              return true;
     382            }
     383          }
     384        }
     385      }
     386    };
     387
     388    AbstractChosen.prototype.choices_count = function() {
     389      var option, _i, _len, _ref;
     390      if (this.selected_option_count != null) {
     391        return this.selected_option_count;
     392      }
     393      this.selected_option_count = 0;
     394      _ref = this.form_field.options;
     395      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
     396        option = _ref[_i];
     397        if (option.selected) {
     398          this.selected_option_count += 1;
     399        }
     400      }
     401      return this.selected_option_count;
     402    };
     403
     404    AbstractChosen.prototype.choices_click = function(evt) {
     405      evt.preventDefault();
     406      if (!(this.results_showing || this.is_disabled)) {
     407        return this.results_show();
     408      }
     409    };
     410
     411    AbstractChosen.prototype.keyup_checker = function(evt) {
     412      var stroke, _ref;
     413      stroke = (_ref = evt.which) != null ? _ref : evt.keyCode;
     414      this.search_field_scale();
     415      switch (stroke) {
     416        case 8:
     417          if (this.is_multiple && this.backstroke_length < 1 && this.choices_count() > 0) {
     418            return this.keydown_backstroke();
     419          } else if (!this.pending_backstroke) {
     420            this.result_clear_highlight();
     421            return this.results_search();
     422          }
     423          break;
     424        case 13:
     425          evt.preventDefault();
     426          if (this.results_showing) {
     427            return this.result_select(evt);
     428          }
     429          break;
     430        case 27:
     431          if (this.results_showing) {
     432            this.results_hide();
     433          }
     434          return true;
     435        case 9:
     436        case 38:
     437        case 40:
     438        case 16:
     439        case 91:
     440        case 17:
     441          break;
     442        default:
     443          return this.results_search();
     444      }
     445    };
     446
     447    AbstractChosen.prototype.container_width = function() {
     448      if (this.options.width != null) {
     449        return this.options.width;
     450      } else {
     451        return "" + this.form_field.offsetWidth + "px";
     452      }
     453    };
     454
     455    AbstractChosen.prototype.include_option_in_results = function(option) {
     456      if (this.is_multiple && (!this.display_selected_options && option.selected)) {
     457        return false;
     458      }
     459      if (!this.display_disabled_options && option.disabled) {
     460        return false;
     461      }
     462      if (option.empty) {
     463        return false;
     464      }
     465      return true;
     466    };
     467
     468    AbstractChosen.prototype.search_results_touchstart = function(evt) {
     469      this.touch_started = true;
     470      return this.search_results_mouseover(evt);
     471    };
     472
     473    AbstractChosen.prototype.search_results_touchmove = function(evt) {
     474      this.touch_started = false;
     475      return this.search_results_mouseout(evt);
     476    };
     477
     478    AbstractChosen.prototype.search_results_touchend = function(evt) {
     479      if (this.touch_started) {
     480        return this.search_results_mouseup(evt);
     481      }
     482    };
     483
     484    AbstractChosen.prototype.outerHTML = function(element) {
     485      var tmp;
     486      if (element.outerHTML) {
     487        return element.outerHTML;
     488      }
     489      tmp = document.createElement("div");
     490      tmp.appendChild(element);
     491      return tmp.innerHTML;
     492    };
     493
     494    AbstractChosen.browser_is_supported = function() {
     495      if (window.navigator.appName === "Microsoft Internet Explorer") {
     496        return document.documentMode >= 8;
     497      }
     498      if (/iP(od|hone)/i.test(window.navigator.userAgent)) {
     499        return false;
     500      }
     501      if (/Android/i.test(window.navigator.userAgent)) {
     502        if (/Mobile/i.test(window.navigator.userAgent)) {
     503          return false;
     504        }
     505      }
     506      return true;
     507    };
     508
     509    AbstractChosen.default_multiple_text = "Select Some Options";
     510
     511    AbstractChosen.default_single_text = "Select an Option";
     512
     513    AbstractChosen.default_no_result_text = "No results match";
     514
     515    return AbstractChosen;
     516
     517  })();
     518
     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) {
     540    __extends(Chosen, _super);
     541
     542    function Chosen() {
     543      _ref = Chosen.__super__.constructor.apply(this, arguments);
     544      return _ref;
     545    }
     546
     547    Chosen.prototype.setup = function() {
     548      this.form_field_jq = $(this.form_field);
     549      this.current_selectedIndex = this.form_field.selectedIndex;
     550      return this.is_rtl = this.form_field_jq.hasClass("chosen-rtl");
     551    };
     552
     553    Chosen.prototype.set_up_html = function() {
     554      var container_classes, container_props;
     555      container_classes = ["chosen-container"];
     556      container_classes.push("chosen-container-" + (this.is_multiple ? "multi" : "single"));
     557      if (this.inherit_select_classes && this.form_field.className) {
     558        container_classes.push(this.form_field.className);
     559      }
     560      if (this.is_rtl) {
     561        container_classes.push("chosen-rtl");
     562      }
     563      container_props = {
     564        'class': container_classes.join(' '),
     565        'style': "width: " + (this.container_width()) + ";",
     566        'title': this.form_field.title
     567      };
     568      if (this.form_field.id.length) {
     569        container_props.id = this.form_field.id.replace(/[^\w]/g, '_') + "_chosen";
     570      }
     571      this.container = $("<div />", container_props);
     572      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();
     589      }
     590      this.results_build();
     591      this.set_tab_index();
     592      this.set_label_behavior();
     593      return this.form_field_jq.trigger("chosen:ready", {
     594        chosen: this
     595      });
     596    };
     597
     598    Chosen.prototype.register_observers = function() {
     599      var _this = this;
     600      this.container.bind('mousedown.chosen', function(evt) {
     601        _this.container_mousedown(evt);
     602      });
     603      this.container.bind('mouseup.chosen', function(evt) {
     604        _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);
     653      });
     654      if (this.is_multiple) {
     655        return this.search_choices.bind('click.chosen', function(evt) {
     656          _this.choices_click(evt);
     657        });
     658      } else {
     659        return this.container.bind('click.chosen', function(evt) {
     660          evt.preventDefault();
     661        });
     662      }
     663    };
     664
     665    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;
     669      }
     670      this.container.remove();
     671      this.form_field_jq.removeData('chosen');
     672      return this.form_field_jq.show();
     673    };
     674
     675    Chosen.prototype.search_field_disabled = function() {
     676      this.is_disabled = this.form_field_jq[0].disabled;
     677      if (this.is_disabled) {
     678        this.container.addClass('chosen-disabled');
     679        this.search_field[0].disabled = true;
     680        if (!this.is_multiple) {
     681          this.selected_item.unbind("focus.chosen", this.activate_action);
     682        }
     683        return this.close_field();
     684      } else {
     685        this.container.removeClass('chosen-disabled');
     686        this.search_field[0].disabled = false;
     687        if (!this.is_multiple) {
     688          return this.selected_item.bind("focus.chosen", this.activate_action);
     689        }
     690      }
     691    };
     692
     693    Chosen.prototype.container_mousedown = function(evt) {
     694      if (!this.is_disabled) {
     695        if (evt && evt.type === "mousedown" && !this.results_showing) {
     696          evt.preventDefault();
     697        }
     698        if (!((evt != null) && ($(evt.target)).hasClass("search-choice-close"))) {
     699          if (!this.active_field) {
     700            if (this.is_multiple) {
     701              this.search_field.val("");
     702            }
     703            $(document).bind('click.chosen', this.click_test_action);
     704            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();
     707            this.results_toggle();
     708          }
     709          return this.activate_field();
     710        }
     711      }
     712    };
     713
     714    Chosen.prototype.container_mouseup = function(evt) {
     715      if (evt.target.nodeName === "ABBR" && !this.is_disabled) {
     716        return this.results_reset(evt);
     717      }
     718    };
     719
     720    Chosen.prototype.search_results_mousewheel = function(evt) {
     721      var delta;
     722      if (evt.originalEvent) {
     723        delta = -evt.originalEvent.wheelDelta || evt.originalEvent.detail;
     724      }
     725      if (delta != null) {
     726        evt.preventDefault();
     727        if (evt.type === 'DOMMouseScroll') {
     728          delta = delta * 40;
     729        }
     730        return this.search_results.scrollTop(delta + this.search_results.scrollTop());
     731      }
     732    };
     733
     734    Chosen.prototype.blur_test = function(evt) {
     735      if (!this.active_field && this.container.hasClass("chosen-container-active")) {
     736        return this.close_field();
     737      }
     738    };
     739
     740    Chosen.prototype.close_field = function() {
     741      $(document).unbind("click.chosen", this.click_test_action);
     742      this.active_field = false;
     743      this.results_hide();
     744      this.container.removeClass("chosen-container-active");
     745      this.clear_backstroke();
     746      this.show_search_field_default();
     747      return this.search_field_scale();
     748    };
     749
     750    Chosen.prototype.activate_field = function() {
     751      this.container.addClass("chosen-container-active");
     752      this.active_field = true;
     753      this.search_field.val(this.search_field.val());
     754      return this.search_field.focus();
     755    };
     756
     757    Chosen.prototype.test_active_click = function(evt) {
     758      if (this.container.is($(evt.target).closest('.chosen-container'))) {
     759        return this.active_field = true;
     760      } else {
     761        return this.close_field();
     762      }
     763    };
     764
     765    Chosen.prototype.results_build = function() {
     766      this.parsing = true;
     767      this.selected_option_count = null;
     768      this.results_data = SelectParser.select_to_array(this.form_field);
     769      if (this.is_multiple) {
     770        this.search_choices.find("li.search-choice").remove();
     771      } else {
     772        this.single_set_selected_text();
     773        this.single_set_nosearch();
     774      }
     775      this.update_results_content(this.results_option_build({
     776        first: true
     777      }));
     778      this.search_field_disabled();
     779      this.show_search_field_default();
     780      this.search_field_scale();
     781      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      }
     792    };
     793
     794    Chosen.prototype.result_do_highlight = function(el) {
     795      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        }
     810      }
     811    };
     812
     813    Chosen.prototype.result_clear_highlight = function() {
     814      if (this.result_highlight) {
     815        this.result_highlight.removeClass("highlighted");
     816      }
     817      return this.result_highlight = null;
     818    };
     819
     820    Chosen.prototype.results_show = function() {
     821      if (this.is_multiple && this.max_selected_options <= this.choices_count()) {
     822        this.form_field_jq.trigger("chosen:maxselected", {
     823          chosen: this
     824        });
     825        return false;
     826      }
     827      this.container.addClass("chosen-with-drop");
     828      this.form_field_jq.trigger("chosen:showing_dropdown", {
     829        chosen: this
     830      });
     831      this.results_showing = true;
     832      this.search_field.focus();
     833      this.search_field.val(this.search_field.val());
     834      return this.winnow_results();
     835    };
     836
     837    Chosen.prototype.update_results_content = function(content) {
     838      return this.search_results.html(content);
     839    };
     840
     841    Chosen.prototype.results_hide = function() {
     842      if (this.results_showing) {
     843        this.result_clear_highlight();
     844        this.container.removeClass("chosen-with-drop");
     845        this.form_field_jq.trigger("chosen:hiding_dropdown", {
     846          chosen: this
     847        });
     848      }
     849      return this.results_showing = false;
     850    };
     851
     852    Chosen.prototype.set_tab_index = function(el) {
     853      var ti;
     854      if (this.form_field.tabIndex) {
     855        ti = this.form_field.tabIndex;
     856        this.form_field.tabIndex = -1;
     857        return this.search_field[0].tabIndex = ti;
     858      }
     859    };
     860
     861    Chosen.prototype.set_label_behavior = function() {
     862      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) {
     869          if (_this.is_multiple) {
     870            return _this.container_mousedown(evt);
     871          } else {
     872            return _this.activate_field();
     873          }
     874        });
     875      }
     876    };
     877
     878    Chosen.prototype.show_search_field_default = function() {
     879      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");
     885      }
     886    };
     887
     888    Chosen.prototype.search_results_mouseup = function(evt) {
     889      var target;
     890      target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
     891      if (target.length) {
     892        this.result_highlight = target;
     893        this.result_select(evt);
     894        return this.search_field.focus();
     895      }
     896    };
     897
     898    Chosen.prototype.search_results_mouseover = function(evt) {
     899      var target;
     900      target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
     901      if (target) {
     902        return this.result_do_highlight(target);
     903      }
     904    };
     905
     906    Chosen.prototype.search_results_mouseout = function(evt) {
     907      if ($(evt.target).hasClass("active-result" || $(evt.target).parents('.active-result').first())) {
     908        return this.result_clear_highlight();
     909      }
     910    };
     911
     912    Chosen.prototype.choice_build = function(item) {
     913      var choice, close_link,
     914        _this = this;
     915      choice = $('<li />', {
     916        "class": "search-choice"
     917      }).html("<span>" + item.html + "</span>");
     918      if (item.disabled) {
     919        choice.addClass('search-choice-disabled');
     920      } else {
     921        close_link = $('<a />', {
     922          "class": 'search-choice-close',
     923          'data-option-array-index': item.array_index
     924        });
     925        close_link.bind('click.chosen', function(evt) {
     926          return _this.choice_destroy_link_click(evt);
     927        });
     928        choice.append(close_link);
     929      }
     930      return this.search_container.before(choice);
     931    };
     932
     933    Chosen.prototype.choice_destroy_link_click = function(evt) {
     934      evt.preventDefault();
     935      evt.stopPropagation();
     936      if (!this.is_disabled) {
     937        return this.choice_destroy($(evt.target));
     938      }
     939    };
     940
     941    Chosen.prototype.choice_destroy = function(link) {
     942      if (this.result_deselect(link[0].getAttribute("data-option-array-index"))) {
     943        this.show_search_field_default();
     944        if (this.is_multiple && this.choices_count() > 0 && this.search_field.val().length < 1) {
     945          this.results_hide();
     946        }
     947        link.parents('li').first().remove();
     948        return this.search_field_scale();
     949      }
     950    };
     951
     952    Chosen.prototype.results_reset = function() {
     953      this.reset_single_select_options();
     954      this.form_field.options[0].selected = true;
     955      this.single_set_selected_text();
     956      this.show_search_field_default();
     957      this.results_reset_cleanup();
     958      this.form_field_jq.trigger("change");
     959      if (this.active_field) {
     960        return this.results_hide();
     961      }
     962    };
     963
     964    Chosen.prototype.results_reset_cleanup = function() {
     965      this.current_selectedIndex = this.form_field.selectedIndex;
     966      return this.selected_item.find("abbr").remove();
     967    };
     968
     969    Chosen.prototype.result_select = function(evt) {
     970      var high, item;
     971      if (this.result_highlight) {
     972        high = this.result_highlight;
     973        this.result_clear_highlight();
     974        if (this.is_multiple && this.max_selected_options <= this.choices_count()) {
     975          this.form_field_jq.trigger("chosen:maxselected", {
     976            chosen: this
     977          });
     978          return false;
     979        }
     980        if (this.is_multiple) {
     981          high.removeClass("active-result");
     982        } else {
     983          this.reset_single_select_options();
     984        }
     985        item = this.results_data[high[0].getAttribute("data-option-array-index")];
     986        item.selected = true;
     987        this.form_field.options[item.options_index].selected = true;
     988        this.selected_option_count = null;
     989        if (this.is_multiple) {
     990          this.choice_build(item);
     991        } else {
     992          this.single_set_selected_text(item.text);
     993        }
     994        if (!((evt.metaKey || evt.ctrlKey) && this.is_multiple)) {
     995          this.results_hide();
     996        }
     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          });
     1002        }
     1003        this.current_selectedIndex = this.form_field.selectedIndex;
     1004        return this.search_field_scale();
     1005      }
     1006    };
     1007
     1008    Chosen.prototype.single_set_selected_text = function(text) {
     1009      if (text == null) {
     1010        text = this.default_text;
     1011      }
     1012      if (text === this.default_text) {
     1013        this.selected_item.addClass("chosen-default");
     1014      } else {
     1015        this.single_deselect_control_build();
     1016        this.selected_item.removeClass("chosen-default");
     1017      }
     1018      return this.selected_item.find("span").text(text);
     1019    };
     1020
     1021    Chosen.prototype.result_deselect = function(pos) {
     1022      var result_data;
     1023      result_data = this.results_data[pos];
     1024      if (!this.form_field.options[result_data.options_index].disabled) {
     1025        result_data.selected = false;
     1026        this.form_field.options[result_data.options_index].selected = false;
     1027        this.selected_option_count = null;
     1028        this.result_clear_highlight();
     1029        if (this.results_showing) {
     1030          this.winnow_results();
     1031        }
     1032        this.form_field_jq.trigger("change", {
     1033          deselected: this.form_field.options[result_data.options_index].value
     1034        });
     1035        this.search_field_scale();
     1036        return true;
     1037      } else {
     1038        return false;
     1039      }
     1040    };
     1041
     1042    Chosen.prototype.single_deselect_control_build = function() {
     1043      if (!this.allow_single_deselect) {
     1044        return;
     1045      }
     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");
     1050    };
     1051
     1052    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      }
     1058    };
     1059
     1060    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();
     1064      if (do_high != null) {
     1065        return this.result_do_highlight(do_high);
     1066      }
     1067    };
     1068
     1069    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);
     1074    };
     1075
     1076    Chosen.prototype.no_results_clear = function() {
     1077      return this.search_results.find(".no-results").remove();
     1078    };
     1079
     1080    Chosen.prototype.keydown_arrow = function() {
     1081      var next_sib;
     1082      if (this.results_showing && this.result_highlight) {
     1083        next_sib = this.result_highlight.nextAll("li.active-result").first();
     1084        if (next_sib) {
     1085          return this.result_do_highlight(next_sib);
     1086        }
     1087      } else {
     1088        return this.results_show();
     1089      }
     1090    };
     1091
     1092    Chosen.prototype.keyup_arrow = function() {
     1093      var prev_sibs;
     1094      if (!this.results_showing && !this.is_multiple) {
     1095        return this.results_show();
     1096      } 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());
     1100        } else {
     1101          if (this.choices_count() > 0) {
     1102            this.results_hide();
     1103          }
     1104          return this.result_clear_highlight();
     1105        }
     1106      }
     1107    };
     1108
     1109    Chosen.prototype.keydown_backstroke = function() {
     1110      var next_available_destroy;
     1111      if (this.pending_backstroke) {
     1112        this.choice_destroy(this.pending_backstroke.find("a").first());
     1113        return this.clear_backstroke();
     1114      } 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")) {
     1117          this.pending_backstroke = next_available_destroy;
     1118          if (this.single_backstroke_delete) {
     1119            return this.keydown_backstroke();
     1120          } else {
     1121            return this.pending_backstroke.addClass("search-choice-focus");
     1122          }
     1123        }
     1124      }
     1125    };
     1126
     1127    Chosen.prototype.clear_backstroke = function() {
     1128      if (this.pending_backstroke) {
     1129        this.pending_backstroke.removeClass("search-choice-focus");
     1130      }
     1131      return this.pending_backstroke = null;
     1132    };
     1133
     1134    Chosen.prototype.keydown_checker = function(evt) {
     1135      var stroke, _ref1;
     1136      stroke = (_ref1 = evt.which) != null ? _ref1 : evt.keyCode;
     1137      this.search_field_scale();
     1138      if (stroke !== 8 && this.pending_backstroke) {
     1139        this.clear_backstroke();
     1140      }
     1141      switch (stroke) {
     1142        case 8:
     1143          this.backstroke_length = this.search_field.val().length;
     1144          break;
     1145        case 9:
     1146          if (this.results_showing && !this.is_multiple) {
     1147            this.result_select(evt);
     1148          }
     1149          this.mouse_on_container = false;
     1150          break;
     1151        case 13:
     1152          evt.preventDefault();
     1153          break;
     1154        case 38:
     1155          evt.preventDefault();
     1156          this.keyup_arrow();
     1157          break;
     1158        case 40:
     1159          evt.preventDefault();
     1160          this.keydown_arrow();
     1161          break;
     1162      }
     1163    };
     1164
     1165    Chosen.prototype.search_field_scale = function() {
     1166      var div, f_width, h, style, style_block, styles, w, _i, _len;
     1167      if (this.is_multiple) {
     1168        h = 0;
     1169        w = 0;
     1170        style_block = "position:absolute; left: -1000px; top: -1000px; display:none;";
     1171        styles = ['font-size', 'font-style', 'font-weight', 'font-family', 'line-height', 'text-transform', 'letter-spacing'];
     1172        for (_i = 0, _len = styles.length; _i < _len; _i++) {
     1173          style = styles[_i];
     1174          style_block += style + ":" + this.search_field.css(style) + ";";
     1175        }
     1176        div = $('<div />', {
     1177          'style': style_block
     1178        });
     1179        div.text(this.search_field.val());
     1180        $('body').append(div);
     1181        w = div.width() + 25;
     1182        div.remove();
     1183        f_width = this.container.outerWidth();
     1184        if (w > f_width - 10) {
     1185          w = f_width - 10;
     1186        }
     1187        return this.search_field.css({
     1188          'width': w + 'px'
     1189        });
     1190      }
     1191    };
     1192
     1193    return Chosen;
     1194
     1195  })(AbstractChosen);
     1196
     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;
    3181313      this.no_results_clear();
    3191314      results = 0;
     
    3251320      zregex = new RegExp(escapedSearchText, 'i');
    3261321      eregex = new RegExp('^' + escapedSearchText + '$', 'i');
    327       _ref = this.results_data;
    328       for (_i = 0, _len = _ref.length; _i < _len; _i++) {
    329         option = _ref[_i];
     1322      _ref2 = this.results_data;
     1323      for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
     1324        option = _ref2[_i];
    3301325        option.search_match = false;
    3311326        results_group = null;
     
    3791374    };
    3801375
    381     AbstractChosen.prototype.search_string_match = function(search_string, regex) {
    382       var part, parts, _i, _len;
    383       if (regex.test(search_string)) {
    384         return true;
    385       } else if (this.enable_split_word_search && (search_string.indexOf(" ") >= 0 || search_string.indexOf("[") === 0)) {
    386         parts = search_string.replace(/\[|\]/g, "").split(" ");
    387         if (parts.length) {
    388           for (_i = 0, _len = parts.length; _i < _len; _i++) {
    389             part = parts[_i];
    390             if (regex.test(part)) {
    391               return true;
    392             }
    393           }
    394         }
    395       }
    396     };
    397 
    398     AbstractChosen.prototype.choices_count = function() {
    399       var option, _i, _len, _ref;
    400       if (this.selected_option_count != null) {
    401         return this.selected_option_count;
    402       }
    403       this.selected_option_count = 0;
    404       _ref = this.form_field.options;
    405       for (_i = 0, _len = _ref.length; _i < _len; _i++) {
    406         option = _ref[_i];
    407         if (option.selected) {
    408           this.selected_option_count += 1;
    409         }
    410       }
    411       return this.selected_option_count;
    412     };
    413 
    414     AbstractChosen.prototype.choices_click = function(evt) {
    415       evt.preventDefault();
    416       if (!(this.results_showing || this.is_disabled)) {
    417         return this.results_show();
    418       }
    419     };
    420 
    421     AbstractChosen.prototype.keyup_checker = function(evt) {
    422       var stroke, _ref;
    423       stroke = (_ref = evt.which) != null ? _ref : evt.keyCode;
    424       this.search_field_scale();
    425       switch (stroke) {
    426         case 8:
    427           if (this.is_multiple && this.backstroke_length < 1 && this.choices_count() > 0) {
    428             return this.keydown_backstroke();
    429           } else if (!this.pending_backstroke) {
    430             this.result_clear_highlight();
    431             return this.results_search();
    432           }
    433           break;
    434         case 13:
    435           evt.preventDefault();
    436           if (this.results_showing) {
    437             return this.result_select(evt);
    438           }
    439           break;
    440         case 27:
    441           if (this.results_showing) {
    442             this.results_hide();
    443           }
    444           return true;
    445         case 9:
    446         case 38:
    447         case 40:
    448         case 16:
    449         case 91:
    450         case 17:
    451           break;
    452         default:
    453           return this.results_search();
    454       }
    455     };
    456 
    457     AbstractChosen.prototype.container_width = function() {
    458       if (this.options.width != null) {
    459         return this.options.width;
    460       } else {
    461         return "" + this.form_field.offsetWidth + "px";
    462       }
    463     };
    464 
    465     AbstractChosen.prototype.include_option_in_results = function(option) {
    466       if (this.is_multiple && (!this.display_selected_options && option.selected)) {
    467         return false;
    468       }
    469       if (!this.display_disabled_options && option.disabled) {
    470         return false;
    471       }
    472       if (option.empty) {
    473         return false;
    474       }
    475       return true;
    476     };
    477 
    478     AbstractChosen.prototype.search_results_touchstart = function(evt) {
    479       this.touch_started = true;
    480       return this.search_results_mouseover(evt);
    481     };
    482 
    483     AbstractChosen.prototype.search_results_touchmove = function(evt) {
    484       this.touch_started = false;
    485       return this.search_results_mouseout(evt);
    486     };
    487 
    488     AbstractChosen.prototype.search_results_touchend = function(evt) {
    489       if (this.touch_started) {
    490         return this.search_results_mouseup(evt);
    491       }
    492     };
    493 
    494     AbstractChosen.prototype.outerHTML = function(element) {
    495       var tmp;
    496       if (element.outerHTML) {
    497         return element.outerHTML;
    498       }
    499       tmp = document.createElement("div");
    500       tmp.appendChild(element);
    501       return tmp.innerHTML;
    502     };
    503 
    504     AbstractChosen.browser_is_supported = function() {
    505       if (window.navigator.appName === "Microsoft Internet Explorer") {
    506         return document.documentMode >= 8;
    507       }
    508       if (/iP(od|hone)/i.test(window.navigator.userAgent)) {
    509         return false;
    510       }
    511       if (/Android/i.test(window.navigator.userAgent)) {
    512         if (/Mobile/i.test(window.navigator.userAgent)) {
    513           return false;
    514         }
    515       }
    516       return true;
    517     };
    518 
    519     AbstractChosen.default_multiple_text = "Select Some Options";
    520 
    521     AbstractChosen.default_single_text = "Select an Option";
    522 
    523     AbstractChosen.default_no_result_text = "No results match";
    524 
    525     AbstractChosen.default_create_option_text = "Add Option";
    526 
    527     return AbstractChosen;
    528 
    529   })();
    530 
    531   $ = jQuery;
    532 
    533   $.fn.extend({
    534     chosen: function(options) {
    535       if (!AbstractChosen.browser_is_supported()) {
    536         return this;
    537       }
    538       return this.each(function(input_field) {
    539         var $this, chosen;
    540         $this = $(this);
    541         chosen = $this.data('chosen');
    542         if (options === 'destroy' && chosen) {
    543           chosen.destroy();
    544         } else if (!chosen) {
    545           $this.data('chosen', new Chosen(this, options));
    546         }
    547       });
    548     }
    549   });
    550 
    551   Chosen = (function(_super) {
    552     __extends(Chosen, _super);
    553 
    554     function Chosen() {
    555       _ref = Chosen.__super__.constructor.apply(this, arguments);
    556       return _ref;
    557     }
    558 
    559     Chosen.prototype.setup = function() {
    560       this.form_field_jq = $(this.form_field);
    561       this.current_selectedIndex = this.form_field.selectedIndex;
    562       return this.is_rtl = this.form_field_jq.hasClass("chosen-rtl");
    563     };
    564 
    565     Chosen.prototype.set_up_html = function() {
    566       var container_classes, container_props;
    567       container_classes = ["chosen-container"];
    568       container_classes.push("chosen-container-" + (this.is_multiple ? "multi" : "single"));
    569       if (this.inherit_select_classes && this.form_field.className) {
    570         container_classes.push(this.form_field.className);
    571       }
    572       if (this.is_rtl) {
    573         container_classes.push("chosen-rtl");
    574       }
    575       container_props = {
    576         'class': container_classes.join(' '),
    577         'style': "width: " + (this.container_width()) + ";",
    578         'title': this.form_field.title
    579       };
    580       if (this.form_field.id.length) {
    581         container_props.id = this.form_field.id.replace(/[^\w]/g, '_') + "_chosen";
    582       }
    583       this.container = $("<div />", container_props);
    584       if (this.is_multiple) {
    585         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>');
    586       } else {
    587         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>');
    588       }
    589       this.form_field_jq.hide().after(this.container);
    590       this.dropdown = this.container.find('div.chosen-drop').first();
    591       this.search_field = this.container.find('input').first();
    592       this.search_results = this.container.find('ul.chosen-results').first();
    593       this.search_field_scale();
    594       this.search_no_results = this.container.find('li.no-results').first();
    595       if (this.is_multiple) {
    596         this.search_choices = this.container.find('ul.chosen-choices').first();
    597         this.search_container = this.container.find('li.search-field').first();
    598       } else {
    599         this.search_container = this.container.find('div.chosen-search').first();
    600         this.selected_item = this.container.find('.chosen-single').first();
    601       }
    602       this.results_build();
    603       this.set_tab_index();
    604       this.set_label_behavior();
    605       return this.form_field_jq.trigger("chosen:ready", {
    606         chosen: this
    607       });
    608     };
    609 
    610     Chosen.prototype.register_observers = function() {
    611       var _this = this;
    612       this.container.bind('mousedown.chosen', function(evt) {
    613         _this.container_mousedown(evt);
    614       });
    615       this.container.bind('mouseup.chosen', function(evt) {
    616         _this.container_mouseup(evt);
    617       });
    618       this.container.bind('mouseenter.chosen', function(evt) {
    619         _this.mouse_enter(evt);
    620       });
    621       this.container.bind('mouseleave.chosen', function(evt) {
    622         _this.mouse_leave(evt);
    623       });
    624       this.search_results.bind('mouseup.chosen', function(evt) {
    625         _this.search_results_mouseup(evt);
    626       });
    627       this.search_results.bind('mouseover.chosen', function(evt) {
    628         _this.search_results_mouseover(evt);
    629       });
    630       this.search_results.bind('mouseout.chosen', function(evt) {
    631         _this.search_results_mouseout(evt);
    632       });
    633       this.search_results.bind('mousewheel.chosen DOMMouseScroll.chosen', function(evt) {
    634         _this.search_results_mousewheel(evt);
    635       });
    636       this.search_results.bind('touchstart.chosen', function(evt) {
    637         _this.search_results_touchstart(evt);
    638       });
    639       this.search_results.bind('touchmove.chosen', function(evt) {
    640         _this.search_results_touchmove(evt);
    641       });
    642       this.search_results.bind('touchend.chosen', function(evt) {
    643         _this.search_results_touchend(evt);
    644       });
    645       this.form_field_jq.bind("chosen:updated.chosen", function(evt) {
    646         _this.results_update_field(evt);
    647       });
    648       this.form_field_jq.bind("chosen:activate.chosen", function(evt) {
    649         _this.activate_field(evt);
    650       });
    651       this.form_field_jq.bind("chosen:open.chosen", function(evt) {
    652         _this.container_mousedown(evt);
    653       });
    654       this.search_field.bind('blur.chosen', function(evt) {
    655         _this.input_blur(evt);
    656       });
    657       this.search_field.bind('keyup.chosen', function(evt) {
    658         _this.keyup_checker(evt);
    659       });
    660       this.search_field.bind('keydown.chosen', function(evt) {
    661         _this.keydown_checker(evt);
    662       });
    663       this.search_field.bind('focus.chosen', function(evt) {
    664         _this.input_focus(evt);
    665       });
    666       if (this.is_multiple) {
    667         return this.search_choices.bind('click.chosen', function(evt) {
    668           _this.choices_click(evt);
    669         });
    670       } else {
    671         return this.container.bind('click.chosen', function(evt) {
    672           evt.preventDefault();
    673         });
    674       }
    675     };
    676 
    677     Chosen.prototype.destroy = function() {
    678       $(document).unbind("click.chosen", this.click_test_action);
    679       if (this.search_field[0].tabIndex) {
    680         this.form_field_jq[0].tabIndex = this.search_field[0].tabIndex;
    681       }
    682       this.container.remove();
    683       this.form_field_jq.removeData('chosen');
    684       return this.form_field_jq.show();
    685     };
    686 
    687     Chosen.prototype.search_field_disabled = function() {
    688       this.is_disabled = this.form_field_jq[0].disabled;
    689       if (this.is_disabled) {
    690         this.container.addClass('chosen-disabled');
    691         this.search_field[0].disabled = true;
    692         if (!this.is_multiple) {
    693           this.selected_item.unbind("focus.chosen", this.activate_action);
    694         }
    695         return this.close_field();
    696       } else {
    697         this.container.removeClass('chosen-disabled');
    698         this.search_field[0].disabled = false;
    699         if (!this.is_multiple) {
    700           return this.selected_item.bind("focus.chosen", this.activate_action);
    701         }
    702       }
    703     };
    704 
    705     Chosen.prototype.container_mousedown = function(evt) {
    706       if (!this.is_disabled) {
    707         if (evt && evt.type === "mousedown" && !this.results_showing) {
    708           evt.preventDefault();
    709         }
    710         if (!((evt != null) && ($(evt.target)).hasClass("search-choice-close"))) {
    711           if (!this.active_field) {
    712             if (this.is_multiple) {
    713               this.search_field.val("");
    714             }
    715             $(document).bind('click.chosen', this.click_test_action);
    716             this.results_show();
    717           } else if (!this.is_multiple && evt && (($(evt.target)[0] === this.selected_item[0]) || $(evt.target).parents("a.chosen-single").length)) {
    718             evt.preventDefault();
    719             this.results_toggle();
    720           }
    721           return this.activate_field();
    722         }
    723       }
    724     };
    725 
    726     Chosen.prototype.container_mouseup = function(evt) {
    727       if (evt.target.nodeName === "ABBR" && !this.is_disabled) {
    728         return this.results_reset(evt);
    729       }
    730     };
    731 
    732     Chosen.prototype.search_results_mousewheel = function(evt) {
    733       var delta, _ref1, _ref2;
    734       delta = -((_ref1 = evt.originalEvent) != null ? _ref1.wheelDelta : void 0) || ((_ref2 = evt.originialEvent) != null ? _ref2.detail : void 0);
    735       if (delta != null) {
    736         evt.preventDefault();
    737         if (evt.type === 'DOMMouseScroll') {
    738           delta = delta * 40;
    739         }
    740         return this.search_results.scrollTop(delta + this.search_results.scrollTop());
    741       }
    742     };
    743 
    744     Chosen.prototype.blur_test = function(evt) {
    745       if (!this.active_field && this.container.hasClass("chosen-container-active")) {
    746         return this.close_field();
    747       }
    748     };
    749 
    750     Chosen.prototype.close_field = function() {
    751       $(document).unbind("click.chosen", this.click_test_action);
    752       this.active_field = false;
    753       this.results_hide();
    754       this.container.removeClass("chosen-container-active");
    755       this.clear_backstroke();
    756       this.show_search_field_default();
    757       return this.search_field_scale();
    758     };
    759 
    760     Chosen.prototype.activate_field = function() {
    761       this.container.addClass("chosen-container-active");
    762       this.active_field = true;
    763       this.search_field.val(this.search_field.val());
    764       return this.search_field.focus();
    765     };
    766 
    767     Chosen.prototype.test_active_click = function(evt) {
    768       if (this.container.is($(evt.target).closest('.chosen-container'))) {
    769         return this.active_field = true;
    770       } else {
    771         return this.close_field();
    772       }
    773     };
    774 
    775     Chosen.prototype.results_build = function() {
    776       this.parsing = true;
    777       this.selected_option_count = null;
    778       this.results_data = SelectParser.select_to_array(this.form_field);
    779       if (this.is_multiple) {
    780         this.search_choices.find("li.search-choice").remove();
    781       } else if (!this.is_multiple) {
    782         this.single_set_selected_text();
    783         if (this.disable_search || this.form_field.options.length <= this.disable_search_threshold && !this.create_option) {
    784           this.search_field[0].readOnly = true;
    785           this.container.addClass("chosen-container-single-nosearch");
    786         } else {
    787           this.search_field[0].readOnly = false;
    788           this.container.removeClass("chosen-container-single-nosearch");
    789         }
    790       }
    791       this.update_results_content(this.results_option_build({
    792         first: true
    793       }));
    794       this.search_field_disabled();
    795       this.show_search_field_default();
    796       this.search_field_scale();
    797       return this.parsing = false;
    798     };
    799 
    800     Chosen.prototype.result_do_highlight = function(el) {
    801       var high_bottom, high_top, maxHeight, visible_bottom, visible_top;
    802       if (el.length) {
    803         this.result_clear_highlight();
    804         this.result_highlight = el;
    805         this.result_highlight.addClass("highlighted");
    806         maxHeight = parseInt(this.search_results.css("maxHeight"), 10);
    807         visible_top = this.search_results.scrollTop();
    808         visible_bottom = maxHeight + visible_top;
    809         high_top = this.result_highlight.position().top + this.search_results.scrollTop();
    810         high_bottom = high_top + this.result_highlight.outerHeight();
    811         if (high_bottom >= visible_bottom) {
    812           return this.search_results.scrollTop((high_bottom - maxHeight) > 0 ? high_bottom - maxHeight : 0);
    813         } else if (high_top < visible_top) {
    814           return this.search_results.scrollTop(high_top);
    815         }
    816       }
    817     };
    818 
    819     Chosen.prototype.result_clear_highlight = function() {
    820       if (this.result_highlight) {
    821         this.result_highlight.removeClass("highlighted");
    822       }
    823       return this.result_highlight = null;
    824     };
    825 
    826     Chosen.prototype.results_show = function() {
    827       if (this.is_multiple && this.max_selected_options <= this.choices_count()) {
    828         this.form_field_jq.trigger("chosen:maxselected", {
    829           chosen: this
    830         });
    831         return false;
    832       }
    833       this.container.addClass("chosen-with-drop");
    834       this.form_field_jq.trigger("chosen:showing_dropdown", {
    835         chosen: this
    836       });
    837       this.results_showing = true;
    838       this.search_field.focus();
    839       this.search_field.val(this.search_field.val());
    840       return this.winnow_results();
    841     };
    842 
    843     Chosen.prototype.update_results_content = function(content) {
    844       return this.search_results.html(content);
    845     };
    846 
    847     Chosen.prototype.results_hide = function() {
    848       if (this.results_showing) {
    849         this.result_clear_highlight();
    850         this.container.removeClass("chosen-with-drop");
    851         this.form_field_jq.trigger("chosen:hiding_dropdown", {
    852           chosen: this
    853         });
    854       }
    855       return this.results_showing = false;
    856     };
    857 
    858     Chosen.prototype.set_tab_index = function(el) {
    859       var ti;
    860       if (this.form_field.tabIndex) {
    861         ti = this.form_field.tabIndex;
    862         this.form_field.tabIndex = -1;
    863         return this.search_field[0].tabIndex = ti;
    864       }
    865     };
    866 
    867     Chosen.prototype.set_label_behavior = function() {
    868       var _this = this;
    869       this.form_field_label = this.form_field_jq.parents("label");
    870       if (!this.form_field_label.length && this.form_field.id.length) {
    871         this.form_field_label = $("label[for='" + this.form_field.id + "']");
    872       }
    873       if (this.form_field_label.length > 0) {
    874         return this.form_field_label.bind('click.chosen', function(evt) {
    875           if (_this.is_multiple) {
    876             return _this.container_mousedown(evt);
    877           } else {
    878             return _this.activate_field();
    879           }
    880         });
    881       }
    882     };
    883 
    884     Chosen.prototype.show_search_field_default = function() {
    885       if (this.is_multiple && this.choices_count() < 1 && !this.active_field) {
    886         this.search_field.val(this.default_text);
    887         return this.search_field.addClass("default");
    888       } else {
    889         this.search_field.val("");
    890         return this.search_field.removeClass("default");
    891       }
    892     };
    893 
    894     Chosen.prototype.search_results_mouseup = function(evt) {
    895       var target;
    896       target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
    897       if (target.length) {
    898         this.result_highlight = target;
    899         this.result_select(evt);
    900         return this.search_field.focus();
    901       }
    902     };
    903 
    904     Chosen.prototype.search_results_mouseover = function(evt) {
    905       var target;
    906       target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
    907       if (target) {
    908         return this.result_do_highlight(target);
    909       }
    910     };
    911 
    912     Chosen.prototype.search_results_mouseout = function(evt) {
    913       if ($(evt.target).hasClass("active-result" || $(evt.target).parents('.active-result').first())) {
    914         return this.result_clear_highlight();
    915       }
    916     };
    917 
    918     Chosen.prototype.choice_build = function(item) {
    919       var choice, close_link,
    920         _this = this;
    921       choice = $('<li />', {
    922         "class": "search-choice"
    923       }).html("<span>" + item.html + "</span>");
    924       if (item.disabled) {
    925         choice.addClass('search-choice-disabled');
    926       } else {
    927         close_link = $('<a />', {
    928           "class": 'search-choice-close',
    929           'data-option-array-index': item.array_index
    930         });
    931         close_link.bind('click.chosen', function(evt) {
    932           return _this.choice_destroy_link_click(evt);
    933         });
    934         choice.append(close_link);
    935       }
    936       return this.search_container.before(choice);
    937     };
    938 
    939     Chosen.prototype.choice_destroy_link_click = function(evt) {
    940       evt.preventDefault();
    941       evt.stopPropagation();
    942       if (!this.is_disabled) {
    943         return this.choice_destroy($(evt.target));
    944       }
    945     };
    946 
    947     Chosen.prototype.choice_destroy = function(link) {
    948       if (this.result_deselect(link[0].getAttribute("data-option-array-index"))) {
    949         this.show_search_field_default();
    950         if (this.is_multiple && this.choices_count() > 0 && this.search_field.val().length < 1) {
    951           this.results_hide();
    952         }
    953         link.parents('li').first().remove();
    954         return this.search_field_scale();
    955       }
    956     };
    957 
    958     Chosen.prototype.results_reset = function() {
    959       this.reset_single_select_options();
    960       this.form_field.options[0].selected = true;
    961       this.single_set_selected_text();
    962       this.show_search_field_default();
    963       this.results_reset_cleanup();
    964       this.form_field_jq.trigger("change");
    965       if (this.active_field) {
    966         return this.results_hide();
    967       }
    968     };
    969 
    970     Chosen.prototype.results_reset_cleanup = function() {
    971       this.current_selectedIndex = this.form_field.selectedIndex;
    972       return this.selected_item.find("abbr").remove();
    973     };
    974 
    975     Chosen.prototype.result_select = function(evt) {
    976       var high, item;
    977       if (this.result_highlight) {
    978         high = this.result_highlight;
    979         if (high.hasClass("create-option")) {
    980           this.select_create_option(this.search_field.val());
    981           return this.results_hide();
    982         }
    983         this.result_clear_highlight();
    984         if (this.is_multiple && this.max_selected_options <= this.choices_count()) {
    985           this.form_field_jq.trigger("chosen:maxselected", {
    986             chosen: this
    987           });
    988           return false;
    989         }
    990         if (this.is_multiple) {
    991           high.removeClass("active-result");
    992         } else {
    993           this.reset_single_select_options();
    994         }
    995         item = this.results_data[high[0].getAttribute("data-option-array-index")];
    996         item.selected = true;
    997         this.form_field.options[item.options_index].selected = true;
    998         this.selected_option_count = null;
    999         if (this.is_multiple) {
    1000           this.choice_build(item);
    1001         } else {
    1002           this.single_set_selected_text(item.text);
    1003         }
    1004         if (!((evt.metaKey || evt.ctrlKey) && this.is_multiple)) {
    1005           this.results_hide();
    1006         }
    1007         this.search_field.val("");
    1008         if (this.is_multiple || this.form_field.selectedIndex !== this.current_selectedIndex) {
    1009           this.form_field_jq.trigger("change", {
    1010             'selected': this.form_field.options[item.options_index].value
    1011           });
    1012         }
    1013         this.current_selectedIndex = this.form_field.selectedIndex;
    1014         return this.search_field_scale();
    1015       }
    1016     };
    1017 
    1018     Chosen.prototype.single_set_selected_text = function(text) {
    1019       if (text == null) {
    1020         text = this.default_text;
    1021       }
    1022       if (text === this.default_text) {
    1023         this.selected_item.addClass("chosen-default");
    1024       } else {
    1025         this.single_deselect_control_build();
    1026         this.selected_item.removeClass("chosen-default");
    1027       }
    1028       return this.selected_item.find("span").text(text);
    1029     };
    1030 
    1031     Chosen.prototype.result_deselect = function(pos) {
    1032       var result_data;
    1033       result_data = this.results_data[pos];
    1034       if (!this.form_field.options[result_data.options_index].disabled) {
    1035         result_data.selected = false;
    1036         this.form_field.options[result_data.options_index].selected = false;
    1037         this.selected_option_count = null;
    1038         this.result_clear_highlight();
    1039         if (this.results_showing) {
    1040           this.winnow_results();
    1041         }
    1042         this.form_field_jq.trigger("change", {
    1043           deselected: this.form_field.options[result_data.options_index].value
    1044         });
    1045         this.search_field_scale();
    1046         return true;
    1047       } else {
    1048         return false;
    1049       }
    1050     };
    1051 
    1052     Chosen.prototype.single_deselect_control_build = function() {
    1053       if (!this.allow_single_deselect) {
    1054         return;
    1055       }
    1056       if (!this.selected_item.find("abbr").length) {
    1057         this.selected_item.find("span").first().after("<abbr class=\"search-choice-close\"></abbr>");
    1058       }
    1059       return this.selected_item.addClass("chosen-single-with-deselect");
    1060     };
    1061 
    1062     Chosen.prototype.get_search_text = function() {
    1063       if (this.search_field.val() === this.default_text) {
    1064         return "";
    1065       } else {
    1066         return $('<div/>').text($.trim(this.search_field.val())).html();
    1067       }
    1068     };
    1069 
    1070     Chosen.prototype.winnow_results_set_highlight = function() {
    1071       var do_high, selected_results;
    1072       selected_results = !this.is_multiple ? this.search_results.find(".result-selected.active-result") : [];
    1073       do_high = selected_results.length ? selected_results.first() : this.search_results.find(".active-result").first();
    1074       if (do_high != null) {
    1075         return this.result_do_highlight(do_high);
    1076       }
    1077     };
    1078 
    1079     Chosen.prototype.no_results = function(terms) {
    1080       var no_results_html;
    1081       no_results_html = $('<li class="no-results">' + this.results_none_found + ' "<span></span>"</li>');
    1082       no_results_html.find("span").first().html(terms);
    1083       return this.search_results.append(no_results_html);
    1084     };
    1085 
    1086     Chosen.prototype.show_create_option = function(terms) {
    1087       var create_option_html;
    1088       create_option_html = $('<li class="create-option active-result"><a href="javascript:void(0);">' + this.create_option_text + '</a>: "' + terms + '"</li>');
    1089       return this.search_results.append(create_option_html);
    1090     };
    1091 
    1092     Chosen.prototype.create_option_clear = function() {
    1093       return this.search_results.find(".create-option").remove();
    1094     };
    1095 
    1096     Chosen.prototype.select_create_option = function(terms) {
    1097       if ($.isFunction(this.create_option)) {
    1098         return this.create_option.call(this, terms);
    1099       } else {
    1100         return this.select_append_option({
    1101           value: terms,
    1102           text: terms
    1103         });
    1104       }
    1105     };
    1106 
    1107     Chosen.prototype.select_append_option = function(options) {
    1108       var option;
    1109       option = $('<option />', options).attr('selected', 'selected');
    1110       this.form_field_jq.append(option);
    1111       this.form_field_jq.trigger("chosen:updated");
    1112       this.form_field_jq.trigger("change");
    1113       return this.search_field.trigger("focus");
    1114     };
    1115 
    1116     Chosen.prototype.no_results_clear = function() {
    1117       return this.search_results.find(".no-results").remove();
    1118     };
    1119 
    1120     Chosen.prototype.keydown_arrow = function() {
    1121       var next_sib;
    1122       if (this.results_showing && this.result_highlight) {
    1123         next_sib = this.result_highlight.nextAll("li.active-result").first();
    1124         if (next_sib) {
    1125           return this.result_do_highlight(next_sib);
    1126         }
    1127       } else if (this.results_showing && this.create_option) {
    1128         return this.result_do_highlight(this.search_results.find('.create-option'));
    1129       } else {
    1130         return this.results_show();
    1131       }
    1132     };
    1133 
    1134     Chosen.prototype.keyup_arrow = function() {
    1135       var prev_sibs;
    1136       if (!this.results_showing && !this.is_multiple) {
    1137         return this.results_show();
    1138       } else if (this.result_highlight) {
    1139         prev_sibs = this.result_highlight.prevAll("li.active-result");
    1140         if (prev_sibs.length) {
    1141           return this.result_do_highlight(prev_sibs.first());
    1142         } else {
    1143           if (this.choices_count() > 0) {
    1144             this.results_hide();
    1145           }
    1146           return this.result_clear_highlight();
    1147         }
    1148       }
    1149     };
    1150 
    1151     Chosen.prototype.keydown_backstroke = function() {
    1152       var next_available_destroy;
    1153       if (this.pending_backstroke) {
    1154         this.choice_destroy(this.pending_backstroke.find("a").first());
    1155         return this.clear_backstroke();
    1156       } else {
    1157         next_available_destroy = this.search_container.siblings("li.search-choice").last();
    1158         if (next_available_destroy.length && !next_available_destroy.hasClass("search-choice-disabled")) {
    1159           this.pending_backstroke = next_available_destroy;
    1160           if (this.single_backstroke_delete) {
    1161             return this.keydown_backstroke();
    1162           } else {
    1163             return this.pending_backstroke.addClass("search-choice-focus");
    1164           }
    1165         }
    1166       }
    1167     };
    1168 
    1169     Chosen.prototype.clear_backstroke = function() {
    1170       if (this.pending_backstroke) {
    1171         this.pending_backstroke.removeClass("search-choice-focus");
    1172       }
    1173       return this.pending_backstroke = null;
    1174     };
    1175 
    1176     Chosen.prototype.keydown_checker = function(evt) {
    1177       var stroke, _ref1;
    1178       stroke = (_ref1 = evt.which) != null ? _ref1 : evt.keyCode;
    1179       this.search_field_scale();
    1180       if (stroke !== 8 && this.pending_backstroke) {
    1181         this.clear_backstroke();
    1182       }
    1183       switch (stroke) {
    1184         case 8:
    1185           this.backstroke_length = this.search_field.val().length;
    1186           break;
    1187         case 9:
    1188           if (this.results_showing && !this.is_multiple) {
    1189             this.result_select(evt);
    1190           }
    1191           this.mouse_on_container = false;
    1192           break;
    1193         case 13:
    1194           evt.preventDefault();
    1195           break;
    1196         case 38:
    1197           evt.preventDefault();
    1198           this.keyup_arrow();
    1199           break;
    1200         case 40:
    1201           evt.preventDefault();
    1202           this.keydown_arrow();
    1203           break;
    1204       }
    1205     };
    1206 
    1207     Chosen.prototype.search_field_scale = function() {
    1208       var div, f_width, h, style, style_block, styles, w, _i, _len;
    1209       if (this.is_multiple) {
    1210         h = 0;
    1211         w = 0;
    1212         style_block = "position:absolute; left: -1000px; top: -1000px; display:none;";
    1213         styles = ['font-size', 'font-style', 'font-weight', 'font-family', 'line-height', 'text-transform', 'letter-spacing'];
    1214         for (_i = 0, _len = styles.length; _i < _len; _i++) {
    1215           style = styles[_i];
    1216           style_block += style + ":" + this.search_field.css(style) + ";";
    1217         }
    1218         div = $('<div />', {
    1219           'style': style_block
    1220         });
    1221         div.text(this.search_field.val());
    1222         $('body').append(div);
    1223         w = div.width() + 25;
    1224         div.remove();
    1225         f_width = this.container.outerWidth();
    1226         if (w > f_width - 10) {
    1227           w = f_width - 10;
    1228         }
    1229         return this.search_field.css({
    1230           'width': w + 'px'
    1231         });
    1232       }
    1233     };
    1234 
    1235     return Chosen;
    1236 
    1237   })(AbstractChosen);
     1376    return ChosenOptionAdding;
     1377
     1378  })(Chosen);
    12381379
    12391380}).call(this);
  • _plugins_/chosen/trunk/lib/chosen/chosen.jquery.min.js

    r78059 r89038  
    1 /* Chosen v1.0.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.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.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.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(document).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(document).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,c,d;return b=-(null!=(c=a.originalEvent)?c.wheelDelta:void 0)||(null!=(d=a.originialEvent)?d.detail:void 0),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(document).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){return this.container.is(a(b.target).closest(".chosen-container"))?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.form_field_jq.trigger("chosen:showing_dropdown",{chosen:this}),this.results_showing=!0,this.search_field.focus(),this.search_field.val(this.search_field.val()),this.winnow_results())},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)},Chosen.prototype.show_create_option=function(b){var c;return c=a('<li class="create-option active-result"><a href="javascript:void(0);">'+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.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);
Note: See TracChangeset for help on using the changeset viewer.