chosen-koenpunt-rails 0.0.3 → 0.0.4

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