Commit 2b319d0496fb4eee24f78e1817235daf23d52079

Authored by mikkyhouse
2 parents 9cd8f7b0 0bdcf2e1

Merge pull request #828 from CedricGatay/feature/chosen_0.9.8_searchContains

Chosen 0.9.8 + Autocomplete contains
app/assets/javascripts/application.js
@@ -79,3 +79,13 @@ function showDiff(link) { @@ -79,3 +79,13 @@ function showDiff(link) {
79 $(link).next('table').show(); 79 $(link).next('table').show();
80 $(link).remove(); 80 $(link).remove();
81 } 81 }
  82 +
  83 +(function($){
  84 + var _chosen = $.fn.chosen;
  85 + $.fn.extend({
  86 + chosen: function(options) {
  87 + var default_options = {'search_contains' : 'true'};
  88 + $.extend(default_options, options);
  89 + return _chosen.apply(this, [default_options]);
  90 + }})
  91 +})(jQuery);
vendor/assets/javascripts/chosen.js
1 // Chosen, a Select Box Enhancer for jQuery and Protoype 1 // Chosen, a Select Box Enhancer for jQuery and Protoype
2 // by Patrick Filler for Harvest, http://getharvest.com 2 // by Patrick Filler for Harvest, http://getharvest.com
3 // 3 //
4 -// Version 0.9.5 4 +// Version 0.9.8
5 // Full source at https://github.com/harvesthq/chosen 5 // Full source at https://github.com/harvesthq/chosen
6 // Copyright (c) 2011 Harvest http://getharvest.com 6 // Copyright (c) 2011 Harvest http://getharvest.com
7 7
@@ -9,11 +9,14 @@ @@ -9,11 +9,14 @@
9 // This file is generated by `cake build`, do not edit it by hand. 9 // This file is generated by `cake build`, do not edit it by hand.
10 (function() { 10 (function() {
11 var SelectParser; 11 var SelectParser;
  12 +
12 SelectParser = (function() { 13 SelectParser = (function() {
  14 +
13 function SelectParser() { 15 function SelectParser() {
14 this.options_index = 0; 16 this.options_index = 0;
15 this.parsed = []; 17 this.parsed = [];
16 } 18 }
  19 +
17 SelectParser.prototype.add_node = function(child) { 20 SelectParser.prototype.add_node = function(child) {
18 if (child.nodeName === "OPTGROUP") { 21 if (child.nodeName === "OPTGROUP") {
19 return this.add_group(child); 22 return this.add_group(child);
@@ -21,6 +24,7 @@ @@ -21,6 +24,7 @@
21 return this.add_option(child); 24 return this.add_option(child);
22 } 25 }
23 }; 26 };
  27 +
24 SelectParser.prototype.add_group = function(group) { 28 SelectParser.prototype.add_group = function(group) {
25 var group_position, option, _i, _len, _ref, _results; 29 var group_position, option, _i, _len, _ref, _results;
26 group_position = this.parsed.length; 30 group_position = this.parsed.length;
@@ -39,12 +43,11 @@ @@ -39,12 +43,11 @@
39 } 43 }
40 return _results; 44 return _results;
41 }; 45 };
  46 +
42 SelectParser.prototype.add_option = function(option, group_position, group_disabled) { 47 SelectParser.prototype.add_option = function(option, group_position, group_disabled) {
43 if (option.nodeName === "OPTION") { 48 if (option.nodeName === "OPTION") {
44 if (option.text !== "") { 49 if (option.text !== "") {
45 - if (group_position != null) {  
46 - this.parsed[group_position].children += 1;  
47 - } 50 + if (group_position != null) this.parsed[group_position].children += 1;
48 this.parsed.push({ 51 this.parsed.push({
49 array_index: this.parsed.length, 52 array_index: this.parsed.length,
50 options_index: this.options_index, 53 options_index: this.options_index,
@@ -67,8 +70,11 @@ @@ -67,8 +70,11 @@
67 return this.options_index += 1; 70 return this.options_index += 1;
68 } 71 }
69 }; 72 };
  73 +
70 return SelectParser; 74 return SelectParser;
  75 +
71 })(); 76 })();
  77 +
72 SelectParser.select_to_array = function(select) { 78 SelectParser.select_to_array = function(select) {
73 var child, parser, _i, _len, _ref; 79 var child, parser, _i, _len, _ref;
74 parser = new SelectParser(); 80 parser = new SelectParser();
@@ -79,17 +85,23 @@ @@ -79,17 +85,23 @@
79 } 85 }
80 return parser.parsed; 86 return parser.parsed;
81 }; 87 };
  88 +
82 this.SelectParser = SelectParser; 89 this.SelectParser = SelectParser;
  90 +
83 }).call(this); 91 }).call(this);
  92 +
  93 +/*
  94 +Chosen source: generate output using 'cake build'
  95 +Copyright (c) 2011 by Harvest
  96 +*/
  97 +
84 (function() { 98 (function() {
85 - /*  
86 - Chosen source: generate output using 'cake build'  
87 - Copyright (c) 2011 by Harvest  
88 - */  
89 var AbstractChosen, root; 99 var AbstractChosen, root;
90 - var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; 100 +
91 root = this; 101 root = this;
  102 +
92 AbstractChosen = (function() { 103 AbstractChosen = (function() {
  104 +
93 function AbstractChosen(form_field, options) { 105 function AbstractChosen(form_field, options) {
94 this.form_field = form_field; 106 this.form_field = form_field;
95 this.options = options != null ? options : {}; 107 this.options = options != null ? options : {};
@@ -101,69 +113,75 @@ @@ -101,69 +113,75 @@
101 this.register_observers(); 113 this.register_observers();
102 this.finish_setup(); 114 this.finish_setup();
103 } 115 }
  116 +
104 AbstractChosen.prototype.set_default_values = function() { 117 AbstractChosen.prototype.set_default_values = function() {
105 - this.click_test_action = __bind(function(evt) {  
106 - return this.test_active_click(evt);  
107 - }, this);  
108 - this.activate_action = __bind(function(evt) {  
109 - return this.activate_field(evt);  
110 - }, this); 118 + var _this = this;
  119 + this.click_test_action = function(evt) {
  120 + return _this.test_active_click(evt);
  121 + };
  122 + this.activate_action = function(evt) {
  123 + return _this.activate_field(evt);
  124 + };
111 this.active_field = false; 125 this.active_field = false;
112 this.mouse_on_container = false; 126 this.mouse_on_container = false;
113 this.results_showing = false; 127 this.results_showing = false;
114 this.result_highlighted = null; 128 this.result_highlighted = null;
115 this.result_single_selected = null; 129 this.result_single_selected = null;
116 - this.allow_single_deselect = (this.options.allow_single_deselect != null) && this.form_field.options[0].text === "" ? this.options.allow_single_deselect : false; 130 + this.allow_single_deselect = (this.options.allow_single_deselect != null) && (this.form_field.options[0] != null) && this.form_field.options[0].text === "" ? this.options.allow_single_deselect : false;
117 this.disable_search_threshold = this.options.disable_search_threshold || 0; 131 this.disable_search_threshold = this.options.disable_search_threshold || 0;
  132 + this.search_contains = this.options.search_contains || false;
118 this.choices = 0; 133 this.choices = 0;
119 return this.results_none_found = this.options.no_results_text || "No results match"; 134 return this.results_none_found = this.options.no_results_text || "No results match";
120 }; 135 };
  136 +
121 AbstractChosen.prototype.mouse_enter = function() { 137 AbstractChosen.prototype.mouse_enter = function() {
122 return this.mouse_on_container = true; 138 return this.mouse_on_container = true;
123 }; 139 };
  140 +
124 AbstractChosen.prototype.mouse_leave = function() { 141 AbstractChosen.prototype.mouse_leave = function() {
125 return this.mouse_on_container = false; 142 return this.mouse_on_container = false;
126 }; 143 };
  144 +
127 AbstractChosen.prototype.input_focus = function(evt) { 145 AbstractChosen.prototype.input_focus = function(evt) {
  146 + var _this = this;
128 if (!this.active_field) { 147 if (!this.active_field) {
129 - return setTimeout((__bind(function() {  
130 - return this.container_mousedown();  
131 - }, this)), 50); 148 + return setTimeout((function() {
  149 + return _this.container_mousedown();
  150 + }), 50);
132 } 151 }
133 }; 152 };
  153 +
134 AbstractChosen.prototype.input_blur = function(evt) { 154 AbstractChosen.prototype.input_blur = function(evt) {
  155 + var _this = this;
135 if (!this.mouse_on_container) { 156 if (!this.mouse_on_container) {
136 this.active_field = false; 157 this.active_field = false;
137 - return setTimeout((__bind(function() {  
138 - return this.blur_test();  
139 - }, this)), 100); 158 + return setTimeout((function() {
  159 + return _this.blur_test();
  160 + }), 100);
140 } 161 }
141 }; 162 };
  163 +
142 AbstractChosen.prototype.result_add_option = function(option) { 164 AbstractChosen.prototype.result_add_option = function(option) {
143 var classes, style; 165 var classes, style;
144 if (!option.disabled) { 166 if (!option.disabled) {
145 option.dom_id = this.container_id + "_o_" + option.array_index; 167 option.dom_id = this.container_id + "_o_" + option.array_index;
146 classes = option.selected && this.is_multiple ? [] : ["active-result"]; 168 classes = option.selected && this.is_multiple ? [] : ["active-result"];
147 - if (option.selected) {  
148 - classes.push("result-selected");  
149 - }  
150 - if (option.group_array_index != null) {  
151 - classes.push("group-option");  
152 - }  
153 - if (option.classes !== "") {  
154 - classes.push(option.classes);  
155 - } 169 + if (option.selected) classes.push("result-selected");
  170 + if (option.group_array_index != null) classes.push("group-option");
  171 + if (option.classes !== "") classes.push(option.classes);
156 style = option.style.cssText !== "" ? " style=\"" + option.style + "\"" : ""; 172 style = option.style.cssText !== "" ? " style=\"" + option.style + "\"" : "";
157 return '<li id="' + option.dom_id + '" class="' + classes.join(' ') + '"' + style + '>' + option.html + '</li>'; 173 return '<li id="' + option.dom_id + '" class="' + classes.join(' ') + '"' + style + '>' + option.html + '</li>';
158 } else { 174 } else {
159 return ""; 175 return "";
160 } 176 }
161 }; 177 };
  178 +
162 AbstractChosen.prototype.results_update_field = function() { 179 AbstractChosen.prototype.results_update_field = function() {
163 this.result_clear_highlight(); 180 this.result_clear_highlight();
164 this.result_single_selected = null; 181 this.result_single_selected = null;
165 return this.results_build(); 182 return this.results_build();
166 }; 183 };
  184 +
167 AbstractChosen.prototype.results_toggle = function() { 185 AbstractChosen.prototype.results_toggle = function() {
168 if (this.results_showing) { 186 if (this.results_showing) {
169 return this.results_hide(); 187 return this.results_hide();
@@ -171,6 +189,7 @@ @@ -171,6 +189,7 @@
171 return this.results_show(); 189 return this.results_show();
172 } 190 }
173 }; 191 };
  192 +
174 AbstractChosen.prototype.results_search = function(evt) { 193 AbstractChosen.prototype.results_search = function(evt) {
175 if (this.results_showing) { 194 if (this.results_showing) {
176 return this.winnow_results(); 195 return this.winnow_results();
@@ -178,6 +197,7 @@ @@ -178,6 +197,7 @@
178 return this.results_show(); 197 return this.results_show();
179 } 198 }
180 }; 199 };
  200 +
181 AbstractChosen.prototype.keyup_checker = function(evt) { 201 AbstractChosen.prototype.keyup_checker = function(evt) {
182 var stroke, _ref; 202 var stroke, _ref;
183 stroke = (_ref = evt.which) != null ? _ref : evt.keyCode; 203 stroke = (_ref = evt.which) != null ? _ref : evt.keyCode;
@@ -193,15 +213,11 @@ @@ -193,15 +213,11 @@
193 break; 213 break;
194 case 13: 214 case 13:
195 evt.preventDefault(); 215 evt.preventDefault();
196 - if (this.results_showing) {  
197 - return this.result_select(evt);  
198 - } 216 + if (this.results_showing) return this.result_select(evt);
199 break; 217 break;
200 case 27: 218 case 27:
201 - if (this.results_showing) {  
202 - return this.results_hide();  
203 - }  
204 - break; 219 + if (this.results_showing) this.results_hide();
  220 + return true;
205 case 9: 221 case 9:
206 case 38: 222 case 38:
207 case 40: 223 case 40:
@@ -213,62 +229,71 @@ @@ -213,62 +229,71 @@
213 return this.results_search(); 229 return this.results_search();
214 } 230 }
215 }; 231 };
  232 +
216 AbstractChosen.prototype.generate_field_id = function() { 233 AbstractChosen.prototype.generate_field_id = function() {
217 var new_id; 234 var new_id;
218 new_id = this.generate_random_id(); 235 new_id = this.generate_random_id();
219 this.form_field.id = new_id; 236 this.form_field.id = new_id;
220 return new_id; 237 return new_id;
221 }; 238 };
  239 +
222 AbstractChosen.prototype.generate_random_char = function() { 240 AbstractChosen.prototype.generate_random_char = function() {
223 var chars, newchar, rand; 241 var chars, newchar, rand;
224 chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZ"; 242 chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZ";
225 rand = Math.floor(Math.random() * chars.length); 243 rand = Math.floor(Math.random() * chars.length);
226 return newchar = chars.substring(rand, rand + 1); 244 return newchar = chars.substring(rand, rand + 1);
227 }; 245 };
  246 +
228 return AbstractChosen; 247 return AbstractChosen;
  248 +
229 })(); 249 })();
  250 +
230 root.AbstractChosen = AbstractChosen; 251 root.AbstractChosen = AbstractChosen;
  252 +
231 }).call(this); 253 }).call(this);
  254 +
  255 +/*
  256 +Chosen source: generate output using 'cake build'
  257 +Copyright (c) 2011 by Harvest
  258 +*/
  259 +
232 (function() { 260 (function() {
233 - /*  
234 - Chosen source: generate output using 'cake build'  
235 - Copyright (c) 2011 by Harvest  
236 - */  
237 - var $, Chosen, get_side_border_padding, root;  
238 - var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) {  
239 - for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }  
240 - function ctor() { this.constructor = child; }  
241 - ctor.prototype = parent.prototype;  
242 - child.prototype = new ctor;  
243 - child.__super__ = parent.prototype;  
244 - return child;  
245 - }, __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; 261 + var $, Chosen, get_side_border_padding, root,
  262 + __hasProp = Object.prototype.hasOwnProperty,
  263 + __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; };
  264 +
246 root = this; 265 root = this;
  266 +
247 $ = jQuery; 267 $ = jQuery;
  268 +
248 $.fn.extend({ 269 $.fn.extend({
249 chosen: function(options) { 270 chosen: function(options) {
250 if ($.browser.msie && ($.browser.version === "6.0" || $.browser.version === "7.0")) { 271 if ($.browser.msie && ($.browser.version === "6.0" || $.browser.version === "7.0")) {
251 return this; 272 return this;
252 } 273 }
253 return $(this).each(function(input_field) { 274 return $(this).each(function(input_field) {
254 - if (!($(this)).hasClass("chzn-done")) {  
255 - return new Chosen(this, options);  
256 - } 275 + if (!($(this)).hasClass("chzn-done")) return new Chosen(this, options);
257 }); 276 });
258 } 277 }
259 }); 278 });
260 - Chosen = (function() {  
261 - __extends(Chosen, AbstractChosen); 279 +
  280 + Chosen = (function(_super) {
  281 +
  282 + __extends(Chosen, _super);
  283 +
262 function Chosen() { 284 function Chosen() {
263 Chosen.__super__.constructor.apply(this, arguments); 285 Chosen.__super__.constructor.apply(this, arguments);
264 } 286 }
  287 +
265 Chosen.prototype.setup = function() { 288 Chosen.prototype.setup = function() {
266 this.form_field_jq = $(this.form_field); 289 this.form_field_jq = $(this.form_field);
267 return this.is_rtl = this.form_field_jq.hasClass("chzn-rtl"); 290 return this.is_rtl = this.form_field_jq.hasClass("chzn-rtl");
268 }; 291 };
  292 +
269 Chosen.prototype.finish_setup = function() { 293 Chosen.prototype.finish_setup = function() {
270 return this.form_field_jq.addClass("chzn-done"); 294 return this.form_field_jq.addClass("chzn-done");
271 }; 295 };
  296 +
272 Chosen.prototype.set_up_html = function() { 297 Chosen.prototype.set_up_html = function() {
273 var container_div, dd_top, dd_width, sf_width; 298 var container_div, dd_top, dd_width, sf_width;
274 this.container_id = this.form_field.id.length ? this.form_field.id.replace(/(:|\.)/g, '_') : this.generate_field_id(); 299 this.container_id = this.form_field.id.length ? this.form_field.id.replace(/(:|\.)/g, '_') : this.generate_field_id();
@@ -283,7 +308,7 @@ @@ -283,7 +308,7 @@
283 if (this.is_multiple) { 308 if (this.is_multiple) {
284 container_div.html('<ul class="chzn-choices"><li class="search-field"><input type="text" value="' + this.default_text + '" class="default" autocomplete="off" style="width:25px;" /></li></ul><div class="chzn-drop" style="left:-9000px;"><ul class="chzn-results"></ul></div>'); 309 container_div.html('<ul class="chzn-choices"><li class="search-field"><input type="text" value="' + this.default_text + '" class="default" autocomplete="off" style="width:25px;" /></li></ul><div class="chzn-drop" style="left:-9000px;"><ul class="chzn-results"></ul></div>');
285 } else { 310 } else {
286 - container_div.html('<a href="javascript:void(0)" class="chzn-single"><span>' + this.default_text + '</span><div><b></b></div></a><div class="chzn-drop" style="left:-9000px;"><div class="chzn-search"><input type="text" autocomplete="off" /></div><ul class="chzn-results"></ul></div>'); 311 + container_div.html('<a href="javascript:void(0)" class="chzn-single chzn-default"><span>' + this.default_text + '</span><div><b></b></div></a><div class="chzn-drop" style="left:-9000px;"><div class="chzn-search"><input type="text" autocomplete="off" /></div><ul class="chzn-results"></ul></div>');
287 } 312 }
288 this.form_field_jq.hide().after(container_div); 313 this.form_field_jq.hide().after(container_div);
289 this.container = $('#' + this.container_id); 314 this.container = $('#' + this.container_id);
@@ -316,49 +341,56 @@ @@ -316,49 +341,56 @@
316 chosen: this 341 chosen: this
317 }); 342 });
318 }; 343 };
  344 +
319 Chosen.prototype.register_observers = function() { 345 Chosen.prototype.register_observers = function() {
320 - this.container.mousedown(__bind(function(evt) {  
321 - return this.container_mousedown(evt);  
322 - }, this));  
323 - this.container.mouseup(__bind(function(evt) {  
324 - return this.container_mouseup(evt);  
325 - }, this));  
326 - this.container.mouseenter(__bind(function(evt) {  
327 - return this.mouse_enter(evt);  
328 - }, this));  
329 - this.container.mouseleave(__bind(function(evt) {  
330 - return this.mouse_leave(evt);  
331 - }, this));  
332 - this.search_results.mouseup(__bind(function(evt) {  
333 - return this.search_results_mouseup(evt);  
334 - }, this));  
335 - this.search_results.mouseover(__bind(function(evt) {  
336 - return this.search_results_mouseover(evt);  
337 - }, this));  
338 - this.search_results.mouseout(__bind(function(evt) {  
339 - return this.search_results_mouseout(evt);  
340 - }, this));  
341 - this.form_field_jq.bind("liszt:updated", __bind(function(evt) {  
342 - return this.results_update_field(evt);  
343 - }, this));  
344 - this.search_field.blur(__bind(function(evt) {  
345 - return this.input_blur(evt);  
346 - }, this));  
347 - this.search_field.keyup(__bind(function(evt) {  
348 - return this.keyup_checker(evt);  
349 - }, this));  
350 - this.search_field.keydown(__bind(function(evt) {  
351 - return this.keydown_checker(evt);  
352 - }, this)); 346 + var _this = this;
  347 + this.container.mousedown(function(evt) {
  348 + return _this.container_mousedown(evt);
  349 + });
  350 + this.container.mouseup(function(evt) {
  351 + return _this.container_mouseup(evt);
  352 + });
  353 + this.container.mouseenter(function(evt) {
  354 + return _this.mouse_enter(evt);
  355 + });
  356 + this.container.mouseleave(function(evt) {
  357 + return _this.mouse_leave(evt);
  358 + });
  359 + this.search_results.mouseup(function(evt) {
  360 + return _this.search_results_mouseup(evt);
  361 + });
  362 + this.search_results.mouseover(function(evt) {
  363 + return _this.search_results_mouseover(evt);
  364 + });
  365 + this.search_results.mouseout(function(evt) {
  366 + return _this.search_results_mouseout(evt);
  367 + });
  368 + this.form_field_jq.bind("liszt:updated", function(evt) {
  369 + return _this.results_update_field(evt);
  370 + });
  371 + this.search_field.blur(function(evt) {
  372 + return _this.input_blur(evt);
  373 + });
  374 + this.search_field.keyup(function(evt) {
  375 + return _this.keyup_checker(evt);
  376 + });
  377 + this.search_field.keydown(function(evt) {
  378 + return _this.keydown_checker(evt);
  379 + });
353 if (this.is_multiple) { 380 if (this.is_multiple) {
354 - this.search_choices.click(__bind(function(evt) {  
355 - return this.choices_click(evt);  
356 - }, this));  
357 - return this.search_field.focus(__bind(function(evt) {  
358 - return this.input_focus(evt);  
359 - }, this)); 381 + this.search_choices.click(function(evt) {
  382 + return _this.choices_click(evt);
  383 + });
  384 + return this.search_field.focus(function(evt) {
  385 + return _this.input_focus(evt);
  386 + });
  387 + } else {
  388 + return this.container.click(function(evt) {
  389 + return evt.preventDefault();
  390 + });
360 } 391 }
361 }; 392 };
  393 +
362 Chosen.prototype.search_field_disabled = function() { 394 Chosen.prototype.search_field_disabled = function() {
363 this.is_disabled = this.form_field_jq[0].disabled; 395 this.is_disabled = this.form_field_jq[0].disabled;
364 if (this.is_disabled) { 396 if (this.is_disabled) {
@@ -376,21 +408,20 @@ @@ -376,21 +408,20 @@
376 } 408 }
377 } 409 }
378 }; 410 };
  411 +
379 Chosen.prototype.container_mousedown = function(evt) { 412 Chosen.prototype.container_mousedown = function(evt) {
380 var target_closelink; 413 var target_closelink;
381 if (!this.is_disabled) { 414 if (!this.is_disabled) {
382 target_closelink = evt != null ? ($(evt.target)).hasClass("search-choice-close") : false; 415 target_closelink = evt != null ? ($(evt.target)).hasClass("search-choice-close") : false;
383 - if (evt && evt.type === "mousedown") { 416 + if (evt && evt.type === "mousedown" && !this.results_showing) {
384 evt.stopPropagation(); 417 evt.stopPropagation();
385 } 418 }
386 if (!this.pending_destroy_click && !target_closelink) { 419 if (!this.pending_destroy_click && !target_closelink) {
387 if (!this.active_field) { 420 if (!this.active_field) {
388 - if (this.is_multiple) {  
389 - this.search_field.val("");  
390 - } 421 + if (this.is_multiple) this.search_field.val("");
391 $(document).click(this.click_test_action); 422 $(document).click(this.click_test_action);
392 this.results_show(); 423 this.results_show();
393 - } else if (!this.is_multiple && evt && ($(evt.target) === this.selected_item || $(evt.target).parents("a.chzn-single").length)) { 424 + } else if (!this.is_multiple && evt && (($(evt.target)[0] === this.selected_item[0]) || $(evt.target).parents("a.chzn-single").length)) {
394 evt.preventDefault(); 425 evt.preventDefault();
395 this.results_toggle(); 426 this.results_toggle();
396 } 427 }
@@ -400,16 +431,17 @@ @@ -400,16 +431,17 @@
400 } 431 }
401 } 432 }
402 }; 433 };
  434 +
403 Chosen.prototype.container_mouseup = function(evt) { 435 Chosen.prototype.container_mouseup = function(evt) {
404 - if (evt.target.nodeName === "ABBR") {  
405 - return this.results_reset(evt);  
406 - } 436 + if (evt.target.nodeName === "ABBR") return this.results_reset(evt);
407 }; 437 };
  438 +
408 Chosen.prototype.blur_test = function(evt) { 439 Chosen.prototype.blur_test = function(evt) {
409 if (!this.active_field && this.container.hasClass("chzn-container-active")) { 440 if (!this.active_field && this.container.hasClass("chzn-container-active")) {
410 return this.close_field(); 441 return this.close_field();
411 } 442 }
412 }; 443 };
  444 +
413 Chosen.prototype.close_field = function() { 445 Chosen.prototype.close_field = function() {
414 $(document).unbind("click", this.click_test_action); 446 $(document).unbind("click", this.click_test_action);
415 if (!this.is_multiple) { 447 if (!this.is_multiple) {
@@ -424,6 +456,7 @@ @@ -424,6 +456,7 @@
424 this.show_search_field_default(); 456 this.show_search_field_default();
425 return this.search_field_scale(); 457 return this.search_field_scale();
426 }; 458 };
  459 +
427 Chosen.prototype.activate_field = function() { 460 Chosen.prototype.activate_field = function() {
428 if (!this.is_multiple && !this.active_field) { 461 if (!this.is_multiple && !this.active_field) {
429 this.search_field.attr("tabindex", this.selected_item.attr("tabindex")); 462 this.search_field.attr("tabindex", this.selected_item.attr("tabindex"));
@@ -434,6 +467,7 @@ @@ -434,6 +467,7 @@
434 this.search_field.val(this.search_field.val()); 467 this.search_field.val(this.search_field.val());
435 return this.search_field.focus(); 468 return this.search_field.focus();
436 }; 469 };
  470 +
437 Chosen.prototype.test_active_click = function(evt) { 471 Chosen.prototype.test_active_click = function(evt) {
438 if ($(evt.target).parents('#' + this.container_id).length) { 472 if ($(evt.target).parents('#' + this.container_id).length) {
439 return this.active_field = true; 473 return this.active_field = true;
@@ -441,9 +475,9 @@ @@ -441,9 +475,9 @@
441 return this.close_field(); 475 return this.close_field();
442 } 476 }
443 }; 477 };
  478 +
444 Chosen.prototype.results_build = function() { 479 Chosen.prototype.results_build = function() {
445 - var content, data, startTime, _i, _len, _ref;  
446 - startTime = new Date(); 480 + var content, data, _i, _len, _ref;
447 this.parsing = true; 481 this.parsing = true;
448 this.results_data = root.SelectParser.select_to_array(this.form_field); 482 this.results_data = root.SelectParser.select_to_array(this.form_field);
449 if (this.is_multiple && this.choices > 0) { 483 if (this.is_multiple && this.choices > 0) {
@@ -468,10 +502,8 @@ @@ -468,10 +502,8 @@
468 if (data.selected && this.is_multiple) { 502 if (data.selected && this.is_multiple) {
469 this.choice_build(data); 503 this.choice_build(data);
470 } else if (data.selected && !this.is_multiple) { 504 } else if (data.selected && !this.is_multiple) {
471 - this.selected_item.find("span").text(data.text);  
472 - if (this.allow_single_deselect) {  
473 - this.single_deselect_control_build();  
474 - } 505 + this.selected_item.removeClass("chzn-default").find("span").text(data.text);
  506 + if (this.allow_single_deselect) this.single_deselect_control_build();
475 } 507 }
476 } 508 }
477 } 509 }
@@ -481,6 +513,7 @@ @@ -481,6 +513,7 @@
481 this.search_results.html(content); 513 this.search_results.html(content);
482 return this.parsing = false; 514 return this.parsing = false;
483 }; 515 };
  516 +
484 Chosen.prototype.result_add_group = function(group) { 517 Chosen.prototype.result_add_group = function(group) {
485 if (!group.disabled) { 518 if (!group.disabled) {
486 group.dom_id = this.container_id + "_g_" + group.array_index; 519 group.dom_id = this.container_id + "_g_" + group.array_index;
@@ -489,6 +522,7 @@ @@ -489,6 +522,7 @@
489 return ""; 522 return "";
490 } 523 }
491 }; 524 };
  525 +
492 Chosen.prototype.result_do_highlight = function(el) { 526 Chosen.prototype.result_do_highlight = function(el) {
493 var high_bottom, high_top, maxHeight, visible_bottom, visible_top; 527 var high_bottom, high_top, maxHeight, visible_bottom, visible_top;
494 if (el.length) { 528 if (el.length) {
@@ -507,12 +541,12 @@ @@ -507,12 +541,12 @@
507 } 541 }
508 } 542 }
509 }; 543 };
  544 +
510 Chosen.prototype.result_clear_highlight = function() { 545 Chosen.prototype.result_clear_highlight = function() {
511 - if (this.result_highlight) {  
512 - this.result_highlight.removeClass("highlighted");  
513 - } 546 + if (this.result_highlight) this.result_highlight.removeClass("highlighted");
514 return this.result_highlight = null; 547 return this.result_highlight = null;
515 }; 548 };
  549 +
516 Chosen.prototype.results_show = function() { 550 Chosen.prototype.results_show = function() {
517 var dd_top; 551 var dd_top;
518 if (!this.is_multiple) { 552 if (!this.is_multiple) {
@@ -531,6 +565,7 @@ @@ -531,6 +565,7 @@
531 this.search_field.val(this.search_field.val()); 565 this.search_field.val(this.search_field.val());
532 return this.winnow_results(); 566 return this.winnow_results();
533 }; 567 };
  568 +
534 Chosen.prototype.results_hide = function() { 569 Chosen.prototype.results_hide = function() {
535 if (!this.is_multiple) { 570 if (!this.is_multiple) {
536 this.selected_item.removeClass("chzn-single-with-drop"); 571 this.selected_item.removeClass("chzn-single-with-drop");
@@ -541,6 +576,7 @@ @@ -541,6 +576,7 @@
541 }); 576 });
542 return this.results_showing = false; 577 return this.results_showing = false;
543 }; 578 };
  579 +
544 Chosen.prototype.set_tab_index = function(el) { 580 Chosen.prototype.set_tab_index = function(el) {
545 var ti; 581 var ti;
546 if (this.form_field_jq.attr("tabindex")) { 582 if (this.form_field_jq.attr("tabindex")) {
@@ -554,6 +590,7 @@ @@ -554,6 +590,7 @@
554 } 590 }
555 } 591 }
556 }; 592 };
  593 +
557 Chosen.prototype.show_search_field_default = function() { 594 Chosen.prototype.show_search_field_default = function() {
558 if (this.is_multiple && this.choices < 1 && !this.active_field) { 595 if (this.is_multiple && this.choices < 1 && !this.active_field) {
559 this.search_field.val(this.default_text); 596 this.search_field.val(this.default_text);
@@ -563,6 +600,7 @@ @@ -563,6 +600,7 @@
563 return this.search_field.removeClass("default"); 600 return this.search_field.removeClass("default");
564 } 601 }
565 }; 602 };
  603 +
566 Chosen.prototype.search_results_mouseup = function(evt) { 604 Chosen.prototype.search_results_mouseup = function(evt) {
567 var target; 605 var target;
568 target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first(); 606 target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
@@ -571,34 +609,38 @@ @@ -571,34 +609,38 @@
571 return this.result_select(evt); 609 return this.result_select(evt);
572 } 610 }
573 }; 611 };
  612 +
574 Chosen.prototype.search_results_mouseover = function(evt) { 613 Chosen.prototype.search_results_mouseover = function(evt) {
575 var target; 614 var target;
576 target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first(); 615 target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
577 - if (target) {  
578 - return this.result_do_highlight(target);  
579 - } 616 + if (target) return this.result_do_highlight(target);
580 }; 617 };
  618 +
581 Chosen.prototype.search_results_mouseout = function(evt) { 619 Chosen.prototype.search_results_mouseout = function(evt) {
582 if ($(evt.target).hasClass("active-result" || $(evt.target).parents('.active-result').first())) { 620 if ($(evt.target).hasClass("active-result" || $(evt.target).parents('.active-result').first())) {
583 return this.result_clear_highlight(); 621 return this.result_clear_highlight();
584 } 622 }
585 }; 623 };
  624 +
586 Chosen.prototype.choices_click = function(evt) { 625 Chosen.prototype.choices_click = function(evt) {
587 evt.preventDefault(); 626 evt.preventDefault();
588 if (this.active_field && !($(evt.target).hasClass("search-choice" || $(evt.target).parents('.search-choice').first)) && !this.results_showing) { 627 if (this.active_field && !($(evt.target).hasClass("search-choice" || $(evt.target).parents('.search-choice').first)) && !this.results_showing) {
589 return this.results_show(); 628 return this.results_show();
590 } 629 }
591 }; 630 };
  631 +
592 Chosen.prototype.choice_build = function(item) { 632 Chosen.prototype.choice_build = function(item) {
593 - var choice_id, link; 633 + var choice_id, link,
  634 + _this = this;
594 choice_id = this.container_id + "_c_" + item.array_index; 635 choice_id = this.container_id + "_c_" + item.array_index;
595 this.choices += 1; 636 this.choices += 1;
596 this.search_container.before('<li class="search-choice" id="' + choice_id + '"><span>' + item.html + '</span><a href="javascript:void(0)" class="search-choice-close" rel="' + item.array_index + '"></a></li>'); 637 this.search_container.before('<li class="search-choice" id="' + choice_id + '"><span>' + item.html + '</span><a href="javascript:void(0)" class="search-choice-close" rel="' + item.array_index + '"></a></li>');
597 link = $('#' + choice_id).find("a").first(); 638 link = $('#' + choice_id).find("a").first();
598 - return link.click(__bind(function(evt) {  
599 - return this.choice_destroy_link_click(evt);  
600 - }, this)); 639 + return link.click(function(evt) {
  640 + return _this.choice_destroy_link_click(evt);
  641 + });
601 }; 642 };
  643 +
602 Chosen.prototype.choice_destroy_link_click = function(evt) { 644 Chosen.prototype.choice_destroy_link_click = function(evt) {
603 evt.preventDefault(); 645 evt.preventDefault();
604 if (!this.is_disabled) { 646 if (!this.is_disabled) {
@@ -608,6 +650,7 @@ @@ -608,6 +650,7 @@
608 return evt.stopPropagation; 650 return evt.stopPropagation;
609 } 651 }
610 }; 652 };
  653 +
611 Chosen.prototype.choice_destroy = function(link) { 654 Chosen.prototype.choice_destroy = function(link) {
612 this.choices -= 1; 655 this.choices -= 1;
613 this.show_search_field_default(); 656 this.show_search_field_default();
@@ -617,16 +660,17 @@ @@ -617,16 +660,17 @@
617 this.result_deselect(link.attr("rel")); 660 this.result_deselect(link.attr("rel"));
618 return link.parents('li').first().remove(); 661 return link.parents('li').first().remove();
619 }; 662 };
  663 +
620 Chosen.prototype.results_reset = function(evt) { 664 Chosen.prototype.results_reset = function(evt) {
621 this.form_field.options[0].selected = true; 665 this.form_field.options[0].selected = true;
622 this.selected_item.find("span").text(this.default_text); 666 this.selected_item.find("span").text(this.default_text);
  667 + if (!this.is_multiple) this.selected_item.addClass("chzn-default");
623 this.show_search_field_default(); 668 this.show_search_field_default();
624 $(evt.target).remove(); 669 $(evt.target).remove();
625 this.form_field_jq.trigger("change"); 670 this.form_field_jq.trigger("change");
626 - if (this.active_field) {  
627 - return this.results_hide();  
628 - } 671 + if (this.active_field) return this.results_hide();
629 }; 672 };
  673 +
630 Chosen.prototype.result_select = function(evt) { 674 Chosen.prototype.result_select = function(evt) {
631 var high, high_id, item, position; 675 var high, high_id, item, position;
632 if (this.result_highlight) { 676 if (this.result_highlight) {
@@ -638,6 +682,7 @@ @@ -638,6 +682,7 @@
638 } else { 682 } else {
639 this.search_results.find(".result-selected").removeClass("result-selected"); 683 this.search_results.find(".result-selected").removeClass("result-selected");
640 this.result_single_selected = high; 684 this.result_single_selected = high;
  685 + this.selected_item.removeClass("chzn-default");
641 } 686 }
642 high.addClass("result-selected"); 687 high.addClass("result-selected");
643 position = high_id.substr(high_id.lastIndexOf("_") + 1); 688 position = high_id.substr(high_id.lastIndexOf("_") + 1);
@@ -648,24 +693,23 @@ @@ -648,24 +693,23 @@
648 this.choice_build(item); 693 this.choice_build(item);
649 } else { 694 } else {
650 this.selected_item.find("span").first().text(item.text); 695 this.selected_item.find("span").first().text(item.text);
651 - if (this.allow_single_deselect) {  
652 - this.single_deselect_control_build();  
653 - }  
654 - }  
655 - if (!(evt.metaKey && this.is_multiple)) {  
656 - this.results_hide(); 696 + if (this.allow_single_deselect) this.single_deselect_control_build();
657 } 697 }
  698 + if (!(evt.metaKey && this.is_multiple)) this.results_hide();
658 this.search_field.val(""); 699 this.search_field.val("");
659 this.form_field_jq.trigger("change"); 700 this.form_field_jq.trigger("change");
660 return this.search_field_scale(); 701 return this.search_field_scale();
661 } 702 }
662 }; 703 };
  704 +
663 Chosen.prototype.result_activate = function(el) { 705 Chosen.prototype.result_activate = function(el) {
664 return el.addClass("active-result"); 706 return el.addClass("active-result");
665 }; 707 };
  708 +
666 Chosen.prototype.result_deactivate = function(el) { 709 Chosen.prototype.result_deactivate = function(el) {
667 return el.removeClass("active-result"); 710 return el.removeClass("active-result");
668 }; 711 };
  712 +
669 Chosen.prototype.result_deselect = function(pos) { 713 Chosen.prototype.result_deselect = function(pos) {
670 var result, result_data; 714 var result, result_data;
671 result_data = this.results_data[pos]; 715 result_data = this.results_data[pos];
@@ -678,28 +722,31 @@ @@ -678,28 +722,31 @@
678 this.form_field_jq.trigger("change"); 722 this.form_field_jq.trigger("change");
679 return this.search_field_scale(); 723 return this.search_field_scale();
680 }; 724 };
  725 +
681 Chosen.prototype.single_deselect_control_build = function() { 726 Chosen.prototype.single_deselect_control_build = function() {
682 if (this.allow_single_deselect && this.selected_item.find("abbr").length < 1) { 727 if (this.allow_single_deselect && this.selected_item.find("abbr").length < 1) {
683 return this.selected_item.find("span").first().after("<abbr class=\"search-choice-close\"></abbr>"); 728 return this.selected_item.find("span").first().after("<abbr class=\"search-choice-close\"></abbr>");
684 } 729 }
685 }; 730 };
  731 +
686 Chosen.prototype.winnow_results = function() { 732 Chosen.prototype.winnow_results = function() {
687 - var found, option, part, parts, regex, result_id, results, searchText, startTime, startpos, text, zregex, _i, _j, _len, _len2, _ref;  
688 - startTime = new Date(); 733 + var found, option, part, parts, regex, regexAnchor, result, result_id, results, searchText, startpos, text, zregex, _i, _j, _len, _len2, _ref;
689 this.no_results_clear(); 734 this.no_results_clear();
690 results = 0; 735 results = 0;
691 searchText = this.search_field.val() === this.default_text ? "" : $('<div/>').text($.trim(this.search_field.val())).html(); 736 searchText = this.search_field.val() === this.default_text ? "" : $('<div/>').text($.trim(this.search_field.val())).html();
692 - regex = new RegExp('^' + searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i'); 737 + regexAnchor = this.search_contains ? "" : "^";
  738 + regex = new RegExp(regexAnchor + searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
693 zregex = new RegExp(searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i'); 739 zregex = new RegExp(searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
694 _ref = this.results_data; 740 _ref = this.results_data;
695 for (_i = 0, _len = _ref.length; _i < _len; _i++) { 741 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
696 option = _ref[_i]; 742 option = _ref[_i];
697 if (!option.disabled && !option.empty) { 743 if (!option.disabled && !option.empty) {
698 if (option.group) { 744 if (option.group) {
699 - $('#' + option.dom_id).hide(); 745 + $('#' + option.dom_id).css('display', 'none');
700 } else if (!(this.is_multiple && option.selected)) { 746 } else if (!(this.is_multiple && option.selected)) {
701 found = false; 747 found = false;
702 result_id = option.dom_id; 748 result_id = option.dom_id;
  749 + result = $("#" + result_id);
703 if (regex.test(option.html)) { 750 if (regex.test(option.html)) {
704 found = true; 751 found = true;
705 results += 1; 752 results += 1;
@@ -723,18 +770,16 @@ @@ -723,18 +770,16 @@
723 } else { 770 } else {
724 text = option.html; 771 text = option.html;
725 } 772 }
726 - if ($("#" + result_id).html !== text) {  
727 - $("#" + result_id).html(text);  
728 - }  
729 - this.result_activate($("#" + result_id)); 773 + result.html(text);
  774 + this.result_activate(result);
730 if (option.group_array_index != null) { 775 if (option.group_array_index != null) {
731 - $("#" + this.results_data[option.group_array_index].dom_id).show(); 776 + $("#" + this.results_data[option.group_array_index].dom_id).css('display', 'list-item');
732 } 777 }
733 } else { 778 } else {
734 if (this.result_highlight && result_id === this.result_highlight.attr('id')) { 779 if (this.result_highlight && result_id === this.result_highlight.attr('id')) {
735 this.result_clear_highlight(); 780 this.result_clear_highlight();
736 } 781 }
737 - this.result_deactivate($("#" + result_id)); 782 + this.result_deactivate(result);
738 } 783 }
739 } 784 }
740 } 785 }
@@ -745,6 +790,7 @@ @@ -745,6 +790,7 @@
745 return this.winnow_results_set_highlight(); 790 return this.winnow_results_set_highlight();
746 } 791 }
747 }; 792 };
  793 +
748 Chosen.prototype.winnow_results_clear = function() { 794 Chosen.prototype.winnow_results_clear = function() {
749 var li, lis, _i, _len, _results; 795 var li, lis, _i, _len, _results;
750 this.search_field.val(""); 796 this.search_field.val("");
@@ -753,46 +799,49 @@ @@ -753,46 +799,49 @@
753 for (_i = 0, _len = lis.length; _i < _len; _i++) { 799 for (_i = 0, _len = lis.length; _i < _len; _i++) {
754 li = lis[_i]; 800 li = lis[_i];
755 li = $(li); 801 li = $(li);
756 - _results.push(li.hasClass("group-result") ? li.show() : !this.is_multiple || !li.hasClass("result-selected") ? this.result_activate(li) : void 0); 802 + if (li.hasClass("group-result")) {
  803 + _results.push(li.css('display', 'auto'));
  804 + } else if (!this.is_multiple || !li.hasClass("result-selected")) {
  805 + _results.push(this.result_activate(li));
  806 + } else {
  807 + _results.push(void 0);
  808 + }
757 } 809 }
758 return _results; 810 return _results;
759 }; 811 };
  812 +
760 Chosen.prototype.winnow_results_set_highlight = function() { 813 Chosen.prototype.winnow_results_set_highlight = function() {
761 var do_high, selected_results; 814 var do_high, selected_results;
762 if (!this.result_highlight) { 815 if (!this.result_highlight) {
763 selected_results = !this.is_multiple ? this.search_results.find(".result-selected.active-result") : []; 816 selected_results = !this.is_multiple ? this.search_results.find(".result-selected.active-result") : [];
764 do_high = selected_results.length ? selected_results.first() : this.search_results.find(".active-result").first(); 817 do_high = selected_results.length ? selected_results.first() : this.search_results.find(".active-result").first();
765 - if (do_high != null) {  
766 - return this.result_do_highlight(do_high);  
767 - } 818 + if (do_high != null) return this.result_do_highlight(do_high);
768 } 819 }
769 }; 820 };
  821 +
770 Chosen.prototype.no_results = function(terms) { 822 Chosen.prototype.no_results = function(terms) {
771 var no_results_html; 823 var no_results_html;
772 no_results_html = $('<li class="no-results">' + this.results_none_found + ' "<span></span>"</li>'); 824 no_results_html = $('<li class="no-results">' + this.results_none_found + ' "<span></span>"</li>');
773 no_results_html.find("span").first().html(terms); 825 no_results_html.find("span").first().html(terms);
774 return this.search_results.append(no_results_html); 826 return this.search_results.append(no_results_html);
775 }; 827 };
  828 +
776 Chosen.prototype.no_results_clear = function() { 829 Chosen.prototype.no_results_clear = function() {
777 return this.search_results.find(".no-results").remove(); 830 return this.search_results.find(".no-results").remove();
778 }; 831 };
  832 +
779 Chosen.prototype.keydown_arrow = function() { 833 Chosen.prototype.keydown_arrow = function() {
780 var first_active, next_sib; 834 var first_active, next_sib;
781 if (!this.result_highlight) { 835 if (!this.result_highlight) {
782 first_active = this.search_results.find("li.active-result").first(); 836 first_active = this.search_results.find("li.active-result").first();
783 - if (first_active) {  
784 - this.result_do_highlight($(first_active));  
785 - } 837 + if (first_active) this.result_do_highlight($(first_active));
786 } else if (this.results_showing) { 838 } else if (this.results_showing) {
787 next_sib = this.result_highlight.nextAll("li.active-result").first(); 839 next_sib = this.result_highlight.nextAll("li.active-result").first();
788 - if (next_sib) {  
789 - this.result_do_highlight(next_sib);  
790 - }  
791 - }  
792 - if (!this.results_showing) {  
793 - return this.results_show(); 840 + if (next_sib) this.result_do_highlight(next_sib);
794 } 841 }
  842 + if (!this.results_showing) return this.results_show();
795 }; 843 };
  844 +
796 Chosen.prototype.keyup_arrow = function() { 845 Chosen.prototype.keyup_arrow = function() {
797 var prev_sibs; 846 var prev_sibs;
798 if (!this.results_showing && !this.is_multiple) { 847 if (!this.results_showing && !this.is_multiple) {
@@ -802,13 +851,12 @@ @@ -802,13 +851,12 @@
802 if (prev_sibs.length) { 851 if (prev_sibs.length) {
803 return this.result_do_highlight(prev_sibs.first()); 852 return this.result_do_highlight(prev_sibs.first());
804 } else { 853 } else {
805 - if (this.choices > 0) {  
806 - this.results_hide();  
807 - } 854 + if (this.choices > 0) this.results_hide();
808 return this.result_clear_highlight(); 855 return this.result_clear_highlight();
809 } 856 }
810 } 857 }
811 }; 858 };
  859 +
812 Chosen.prototype.keydown_backstroke = function() { 860 Chosen.prototype.keydown_backstroke = function() {
813 if (this.pending_backstroke) { 861 if (this.pending_backstroke) {
814 this.choice_destroy(this.pending_backstroke.find("a").first()); 862 this.choice_destroy(this.pending_backstroke.find("a").first());
@@ -818,27 +866,25 @@ @@ -818,27 +866,25 @@
818 return this.pending_backstroke.addClass("search-choice-focus"); 866 return this.pending_backstroke.addClass("search-choice-focus");
819 } 867 }
820 }; 868 };
  869 +
821 Chosen.prototype.clear_backstroke = function() { 870 Chosen.prototype.clear_backstroke = function() {
822 if (this.pending_backstroke) { 871 if (this.pending_backstroke) {
823 this.pending_backstroke.removeClass("search-choice-focus"); 872 this.pending_backstroke.removeClass("search-choice-focus");
824 } 873 }
825 return this.pending_backstroke = null; 874 return this.pending_backstroke = null;
826 }; 875 };
  876 +
827 Chosen.prototype.keydown_checker = function(evt) { 877 Chosen.prototype.keydown_checker = function(evt) {
828 var stroke, _ref; 878 var stroke, _ref;
829 stroke = (_ref = evt.which) != null ? _ref : evt.keyCode; 879 stroke = (_ref = evt.which) != null ? _ref : evt.keyCode;
830 this.search_field_scale(); 880 this.search_field_scale();
831 - if (stroke !== 8 && this.pending_backstroke) {  
832 - this.clear_backstroke();  
833 - } 881 + if (stroke !== 8 && this.pending_backstroke) this.clear_backstroke();
834 switch (stroke) { 882 switch (stroke) {
835 case 8: 883 case 8:
836 this.backstroke_length = this.search_field.val().length; 884 this.backstroke_length = this.search_field.val().length;
837 break; 885 break;
838 case 9: 886 case 9:
839 - if (this.results_showing && !this.is_multiple) {  
840 - this.result_select(evt);  
841 - } 887 + if (this.results_showing && !this.is_multiple) this.result_select(evt);
842 this.mouse_on_container = false; 888 this.mouse_on_container = false;
843 break; 889 break;
844 case 13: 890 case 13:
@@ -853,6 +899,7 @@ @@ -853,6 +899,7 @@
853 break; 899 break;
854 } 900 }
855 }; 901 };
  902 +
856 Chosen.prototype.search_field_scale = function() { 903 Chosen.prototype.search_field_scale = function() {
857 var dd_top, div, h, style, style_block, styles, w, _i, _len; 904 var dd_top, div, h, style, style_block, styles, w, _i, _len;
858 if (this.is_multiple) { 905 if (this.is_multiple) {
@@ -871,9 +918,7 @@ @@ -871,9 +918,7 @@
871 $('body').append(div); 918 $('body').append(div);
872 w = div.width() + 25; 919 w = div.width() + 25;
873 div.remove(); 920 div.remove();
874 - if (w > this.f_width - 10) {  
875 - w = this.f_width - 10;  
876 - } 921 + if (w > this.f_width - 10) w = this.f_width - 10;
877 this.search_field.css({ 922 this.search_field.css({
878 'width': w + 'px' 923 'width': w + 'px'
879 }); 924 });
@@ -883,6 +928,7 @@ @@ -883,6 +928,7 @@
883 }); 928 });
884 } 929 }
885 }; 930 };
  931 +
886 Chosen.prototype.generate_random_id = function() { 932 Chosen.prototype.generate_random_id = function() {
887 var string; 933 var string;
888 string = "sel" + this.generate_random_char() + this.generate_random_char() + this.generate_random_char(); 934 string = "sel" + this.generate_random_char() + this.generate_random_char() + this.generate_random_char();
@@ -891,11 +937,16 @@ @@ -891,11 +937,16 @@
891 } 937 }
892 return string; 938 return string;
893 }; 939 };
  940 +
894 return Chosen; 941 return Chosen;
895 - })(); 942 +
  943 + })(AbstractChosen);
  944 +
896 get_side_border_padding = function(elmt) { 945 get_side_border_padding = function(elmt) {
897 var side_border_padding; 946 var side_border_padding;
898 return side_border_padding = elmt.outerWidth() - elmt.width(); 947 return side_border_padding = elmt.outerWidth() - elmt.width();
899 }; 948 };
  949 +
900 root.get_side_border_padding = get_side_border_padding; 950 root.get_side_border_padding = get_side_border_padding;
  951 +
901 }).call(this); 952 }).call(this);