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