PageRenderTime 53ms CodeModel.GetById 2ms app.highlight 44ms RepoModel.GetById 1ms app.codeStats 0ms

/Docs/07-Implementacion/Source/trunk/EDUAR_Regular/EDUAR/EDUAR_UI/Scripts/chosen/chosen.jquery.js

http://blpm.googlecode.com/
JavaScript | 794 lines | 782 code | 1 blank | 11 comment | 161 complexity | 39e22bc2b83961c21e05b591faa7a741 MD5 | raw file
  1// Chosen, a Select Box Enhancer for jQuery and Protoype
  2// by Patrick Filler for Harvest, http://getharvest.com
  3// 
  4// Version 0.9.1
  5// Full source at https://github.com/harvesthq/chosen
  6// Copyright (c) 2011 Harvest http://getharvest.com
  7
  8// MIT License, https://github.com/harvesthq/chosen/blob/master/LICENSE.md
  9// This file is generated by `cake build`, do not edit it by hand.
 10(function() {
 11  /*
 12  Chosen source: generate output using 'cake build'
 13  Copyright (c) 2011 by Harvest
 14  */  var $, Chosen, get_side_border_padding, root;
 15  var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
 16  root = this;
 17  $ = jQuery;
 18  $.fn.extend({
 19    chosen: function(data, options) {
 20      if ($.browser === "msie" && ($.browser.version === "6.0" || $.browser.version === "7.0")) {
 21        return this;
 22      }
 23      return $(this).each(function(input_field) {
 24        if (!($(this)).hasClass("chzn-done")) {
 25          return new Chosen(this, data, options);
 26        }
 27      });
 28    }
 29  });
 30  Chosen = (function() {
 31    function Chosen(elmn) {
 32      this.set_default_values();
 33      this.form_field = elmn;
 34      this.form_field_jq = $(this.form_field);
 35      this.is_multiple = this.form_field.multiple;
 36      this.is_rtl = this.form_field_jq.hasClass("chzn-rtl");
 37      this.default_text_default = this.form_field.multiple ? "Seleccione las opciones" : "Seleccione una opciĆ³n";
 38      this.set_up_html();
 39      this.register_observers();
 40      this.form_field_jq.addClass("chzn-done");
 41    }
 42    Chosen.prototype.set_default_values = function() {
 43      this.click_test_action = __bind(function(evt) {
 44        return this.test_active_click(evt);
 45      }, this);
 46      this.active_field = false;
 47      this.mouse_on_container = false;
 48      this.results_showing = false;
 49      this.result_highlighted = null;
 50      this.result_single_selected = null;
 51      return this.choices = 0;
 52    };
 53    Chosen.prototype.set_up_html = function() {
 54      var container_div, dd_top, dd_width, sf_width;
 55      this.container_id = this.form_field.id.length ? this.form_field.id.replace(/(:|\.)/g, '_') : this.generate_field_id();
 56      this.container_id += "_chzn";
 57      this.f_width = this.form_field_jq.width();
 58      this.default_text = this.form_field_jq.data('placeholder') ? this.form_field_jq.data('placeholder') : this.default_text_default;
 59      container_div = $("<div />", {
 60        id: this.container_id,
 61        "class": "chzn-container " + (this.is_rtl ? 'chzn-rtl' : ''),
 62        style: 'width: ' + this.f_width + 'px;'
 63      });
 64      if (this.is_multiple) {
 65        container_div.html('<ul class="chzn-choices"><li class="search-field"><input type="text" value="' + this.default_text + '" class="default" autocomplete="off" style="width:25px;" /></li></ul><div class="chzn-drop" style="left:-9000px;"><ul class="chzn-results"></ul></div>');
 66      } else {
 67        container_div.html('<a href="javascript:void(0)" class="chzn-single"><span>' + this.default_text + '</span><div><b></b></div></a><div class="chzn-drop" style="left:-9000px;"><div class="chzn-search"><input type="text" autocomplete="off" /></div><ul class="chzn-results"></ul></div>');
 68      }
 69      this.form_field_jq.hide().after(container_div);
 70      this.container = $('#' + this.container_id);
 71      this.container.addClass("chzn-container-" + (this.is_multiple ? "multi" : "single"));
 72      this.dropdown = this.container.find('div.chzn-drop').first();
 73      dd_top = this.container.height();
 74      dd_width = this.f_width - get_side_border_padding(this.dropdown);
 75      this.dropdown.css({
 76        "width": dd_width + "px",
 77        "top": dd_top + "px"
 78      });
 79      this.search_field = this.container.find('input').first();
 80      this.search_results = this.container.find('ul.chzn-results').first();
 81      this.search_field_scale();
 82      this.search_no_results = this.container.find('li.no-results').first();
 83      if (this.is_multiple) {
 84        this.search_choices = this.container.find('ul.chzn-choices').first();
 85        this.search_container = this.container.find('li.search-field').first();
 86      } else {
 87        this.search_container = this.container.find('div.chzn-search').first();
 88        this.selected_item = this.container.find('.chzn-single').first();
 89        sf_width = dd_width - get_side_border_padding(this.search_container) - get_side_border_padding(this.search_field);
 90        this.search_field.css({
 91          "width": sf_width + "px"
 92        });
 93      }
 94      this.results_build();
 95      return this.set_tab_index();
 96    };
 97    Chosen.prototype.register_observers = function() {
 98      this.container.mousedown(__bind(function(evt) {
 99        return this.container_mousedown(evt);
100      }, this));
101      this.container.mouseenter(__bind(function(evt) {
102        return this.mouse_enter(evt);
103      }, this));
104      this.container.mouseleave(__bind(function(evt) {
105        return this.mouse_leave(evt);
106      }, this));
107      this.search_results.mouseup(__bind(function(evt) {
108        return this.search_results_mouseup(evt);
109      }, this));
110      this.search_results.mouseover(__bind(function(evt) {
111        return this.search_results_mouseover(evt);
112      }, this));
113      this.search_results.mouseout(__bind(function(evt) {
114        return this.search_results_mouseout(evt);
115      }, this));
116      this.form_field_jq.bind("liszt:updated", __bind(function(evt) {
117        return this.results_update_field(evt);
118      }, this));
119      this.search_field.blur(__bind(function(evt) {
120        return this.input_blur(evt);
121      }, this));
122      this.search_field.keyup(__bind(function(evt) {
123        return this.keyup_checker(evt);
124      }, this));
125      this.search_field.keydown(__bind(function(evt) {
126        return this.keydown_checker(evt);
127      }, this));
128      if (this.is_multiple) {
129        this.search_choices.click(__bind(function(evt) {
130          return this.choices_click(evt);
131        }, this));
132        return this.search_field.focus(__bind(function(evt) {
133          return this.input_focus(evt);
134        }, this));
135      } else {
136        return this.selected_item.focus(__bind(function(evt) {
137          return this.activate_field(evt);
138        }, this));
139      }
140    };
141    Chosen.prototype.container_mousedown = function(evt) {
142      if (evt && evt.type === "mousedown") {
143        evt.stopPropagation();
144      }
145      if (!this.pending_destroy_click) {
146        if (!this.active_field) {
147          if (this.is_multiple) {
148            this.search_field.val("");
149          }
150          $(document).click(this.click_test_action);
151          this.results_show();
152        } else if (!this.is_multiple && evt && ($(evt.target) === this.selected_item || $(evt.target).parents("a.chzn-single").length)) {
153          evt.preventDefault();
154          this.results_toggle();
155        }
156        return this.activate_field();
157      } else {
158        return this.pending_destroy_click = false;
159      }
160    };
161    Chosen.prototype.mouse_enter = function() {
162      return this.mouse_on_container = true;
163    };
164    Chosen.prototype.mouse_leave = function() {
165      return this.mouse_on_container = false;
166    };
167    Chosen.prototype.input_focus = function(evt) {
168      if (!this.active_field) {
169        return setTimeout((__bind(function() {
170          return this.container_mousedown();
171        }, this)), 50);
172      }
173    };
174    Chosen.prototype.input_blur = function(evt) {
175      if (!this.mouse_on_container) {
176        this.active_field = false;
177        return setTimeout((__bind(function() {
178          return this.blur_test();
179        }, this)), 100);
180      }
181    };
182    Chosen.prototype.blur_test = function(evt) {
183      if (!this.active_field && this.container.hasClass("chzn-container-active")) {
184        return this.close_field();
185      }
186    };
187    Chosen.prototype.close_field = function() {
188      $(document).unbind("click", this.click_test_action);
189      if (!this.is_multiple) {
190        this.selected_item.attr("tabindex", this.search_field.attr("tabindex"));
191        this.search_field.attr("tabindex", -1);
192      }
193      this.active_field = false;
194      this.results_hide();
195      this.container.removeClass("chzn-container-active");
196      this.winnow_results_clear();
197      this.clear_backstroke();
198      this.show_search_field_default();
199      return this.search_field_scale();
200    };
201    Chosen.prototype.activate_field = function() {
202      if (!this.is_multiple && !this.active_field) {
203        this.search_field.attr("tabindex", this.selected_item.attr("tabindex"));
204        this.selected_item.attr("tabindex", -1);
205      }
206      this.container.addClass("chzn-container-active");
207      this.active_field = true;
208      this.search_field.val(this.search_field.val());
209      return this.search_field.focus();
210    };
211    Chosen.prototype.test_active_click = function(evt) {
212      if ($(evt.target).parents('#' + this.container_id).length) {
213        return this.active_field = true;
214      } else {
215        return this.close_field();
216      }
217    };
218    Chosen.prototype.results_build = function() {
219      var content, data, startTime, _i, _len, _ref;
220      startTime = new Date();
221      this.parsing = true;
222      this.results_data = root.SelectParser.select_to_array(this.form_field);
223      if (this.is_multiple && this.choices > 0) {
224        this.search_choices.find("li.search-choice").remove();
225        this.choices = 0;
226      } else if (!this.is_multiple) {
227        this.selected_item.find("span").text(this.default_text);
228      }
229      content = '';
230      _ref = this.results_data;
231      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
232        data = _ref[_i];
233        if (data.group) {
234          content += this.result_add_group(data);
235        } else if (!data.empty) {
236          content += this.result_add_option(data);
237          if (data.selected && this.is_multiple) {
238            this.choice_build(data);
239          } else if (data.selected && !this.is_multiple) {
240            this.selected_item.find("span").text(data.text);
241          }
242        }
243      }
244      this.show_search_field_default();
245      this.search_field_scale();
246      this.search_results.html(content);
247      return this.parsing = false;
248    };
249    Chosen.prototype.result_add_group = function(group) {
250      if (!group.disabled) {
251        group.dom_id = this.container_id + "_g_" + group.array_index;
252        return '<li id="' + group.dom_id + '" class="group-result">' + $("<div />").text(group.label).html() + '</li>';
253      } else {
254        return "";
255      }
256    };
257    Chosen.prototype.result_add_option = function(option) {
258      var classes;
259      if (!option.disabled) {
260        option.dom_id = this.container_id + "_o_" + option.array_index;
261        classes = option.selected && this.is_multiple ? [] : ["active-result"];
262        if (option.selected) {
263          classes.push("result-selected");
264        }
265        if (option.group_array_index != null) {
266          classes.push("group-option");
267        }
268        return '<li id="' + option.dom_id + '" class="' + classes.join(' ') + '">' + option.html + '</li>';
269      } else {
270        return "";
271      }
272    };
273    Chosen.prototype.results_update_field = function() {
274      this.result_clear_highlight();
275      this.result_single_selected = null;
276      return this.results_build();
277    };
278    Chosen.prototype.result_do_highlight = function(el) {
279      var high_bottom, high_top, maxHeight, visible_bottom, visible_top;
280      if (el.length) {
281        this.result_clear_highlight();
282        this.result_highlight = el;
283        this.result_highlight.addClass("highlighted");
284        maxHeight = parseInt(this.search_results.css("maxHeight"), 10);
285        visible_top = this.search_results.scrollTop();
286        visible_bottom = maxHeight + visible_top;
287        high_top = this.result_highlight.position().top + this.search_results.scrollTop();
288        high_bottom = high_top + this.result_highlight.outerHeight();
289        if (high_bottom >= visible_bottom) {
290          return this.search_results.scrollTop((high_bottom - maxHeight) > 0 ? high_bottom - maxHeight : 0);
291        } else if (high_top < visible_top) {
292          return this.search_results.scrollTop(high_top);
293        }
294      }
295    };
296    Chosen.prototype.result_clear_highlight = function() {
297      if (this.result_highlight) {
298        this.result_highlight.removeClass("highlighted");
299      }
300      return this.result_highlight = null;
301    };
302    Chosen.prototype.results_toggle = function() {
303      if (this.results_showing) {
304        return this.results_hide();
305      } else {
306        return this.results_show();
307      }
308    };
309    Chosen.prototype.results_show = function() {
310      var dd_top;
311      if (!this.is_multiple) {
312        this.selected_item.addClass("chzn-single-with-drop");
313        if (this.result_single_selected) {
314          this.result_do_highlight(this.result_single_selected);
315        }
316      }
317      dd_top = this.is_multiple ? this.container.height() : this.container.height() - 1;
318      this.dropdown.css({
319        "top": dd_top + "px",
320        "left": 0
321      });
322      this.results_showing = true;
323      this.search_field.focus();
324      this.search_field.val(this.search_field.val());
325      return this.winnow_results();
326    };
327    Chosen.prototype.results_hide = function() {
328      if (!this.is_multiple) {
329        this.selected_item.removeClass("chzn-single-with-drop");
330      }
331      this.result_clear_highlight();
332      this.dropdown.css({
333        "left": "-9000px"
334      });
335      return this.results_showing = false;
336    };
337    Chosen.prototype.set_tab_index = function(el) {
338      var ti;
339      if (this.form_field_jq.attr("tabindex")) {
340        ti = this.form_field_jq.attr("tabindex");
341        this.form_field_jq.attr("tabindex", -1);
342        if (this.is_multiple) {
343          return this.search_field.attr("tabindex", ti);
344        } else {
345          this.selected_item.attr("tabindex", ti);
346          return this.search_field.attr("tabindex", -1);
347        }
348      }
349    };
350    Chosen.prototype.show_search_field_default = function() {
351      if (this.is_multiple && this.choices < 1 && !this.active_field) {
352        this.search_field.val(this.default_text);
353        return this.search_field.addClass("default");
354      } else {
355        this.search_field.val("");
356        return this.search_field.removeClass("default");
357      }
358    };
359    Chosen.prototype.search_results_mouseup = function(evt) {
360      var target;
361      target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
362      if (target.length) {
363        this.result_highlight = target;
364        return this.result_select(evt);
365      }
366    };
367    Chosen.prototype.search_results_mouseover = function(evt) {
368      var target;
369      target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
370      if (target) {
371        return this.result_do_highlight(target);
372      }
373    };
374    Chosen.prototype.search_results_mouseout = function(evt) {
375      if ($(evt.target).hasClass("active-result" || $(evt.target).parents('.active-result').first())) {
376        return this.result_clear_highlight();
377      }
378    };
379    Chosen.prototype.choices_click = function(evt) {
380      evt.preventDefault();
381      if (this.active_field && !($(evt.target).hasClass("search-choice" || $(evt.target).parents('.search-choice').first)) && !this.results_showing) {
382        return this.results_show();
383      }
384    };
385    Chosen.prototype.choice_build = function(item) {
386      var choice_id, link;
387      choice_id = this.container_id + "_c_" + item.array_index;
388      this.choices += 1;
389      this.search_container.before('<li class="search-choice" id="' + choice_id + '"><span>' + item.html + '</span><a href="javascript:void(0)" class="search-choice-close" rel="' + item.array_index + '"></a></li>');
390      link = $('#' + choice_id).find("a").first();
391      return link.click(__bind(function(evt) {
392        return this.choice_destroy_link_click(evt);
393      }, this));
394    };
395    Chosen.prototype.choice_destroy_link_click = function(evt) {
396      evt.preventDefault();
397      this.pending_destroy_click = true;
398      return this.choice_destroy($(evt.target));
399    };
400    Chosen.prototype.choice_destroy = function(link) {
401      this.choices -= 1;
402      this.show_search_field_default();
403      if (this.is_multiple && this.choices > 0 && this.search_field.val().length < 1) {
404        this.results_hide();
405      }
406      this.result_deselect(link.attr("rel"));
407      return link.parents('li').first().remove();
408    };
409    Chosen.prototype.result_select = function(evt) {
410      var high, high_id, item, position;
411      if (this.result_highlight) {
412        high = this.result_highlight;
413        high_id = high.attr("id");
414        this.result_clear_highlight();
415        high.addClass("result-selected");
416        if (this.is_multiple) {
417          this.result_deactivate(high);
418        } else {
419          this.result_single_selected = high;
420        }
421        position = high_id.substr(high_id.lastIndexOf("_") + 1);
422        item = this.results_data[position];
423        item.selected = true;
424        this.form_field.options[item.options_index].selected = true;
425        if (this.is_multiple) {
426          this.choice_build(item);
427        } else {
428          this.selected_item.find("span").first().text(item.text);
429        }
430        if (!(evt.metaKey && this.is_multiple)) {
431          this.results_hide();
432        }
433        this.search_field.val("");
434        this.form_field_jq.trigger("change");
435        return this.search_field_scale();
436      }
437    };
438    Chosen.prototype.result_activate = function(el) {
439      return el.addClass("active-result").show();
440    };
441    Chosen.prototype.result_deactivate = function(el) {
442      return el.removeClass("active-result").hide();
443    };
444    Chosen.prototype.result_deselect = function(pos) {
445      var result, result_data;
446      result_data = this.results_data[pos];
447      result_data.selected = false;
448      this.form_field.options[result_data.options_index].selected = false;
449      result = $("#" + this.container_id + "_o_" + pos);
450      result.removeClass("result-selected").addClass("active-result").show();
451      this.result_clear_highlight();
452      this.winnow_results();
453      this.form_field_jq.trigger("change");
454      return this.search_field_scale();
455    };
456    Chosen.prototype.results_search = function(evt) {
457      if (this.results_showing) {
458        return this.winnow_results();
459      } else {
460        return this.results_show();
461      }
462    };
463    Chosen.prototype.winnow_results = function() {
464      var found, option, part, parts, regex, result_id, results, searchText, startTime, startpos, text, zregex, _i, _j, _len, _len2, _ref;
465      startTime = new Date();
466      this.no_results_clear();
467      results = 0;
468      searchText = this.search_field.val() === this.default_text ? "" : $('<div/>').text($.trim(this.search_field.val())).html();
469      regex = new RegExp('^' + searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
470      zregex = new RegExp(searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
471      _ref = this.results_data;
472      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
473        option = _ref[_i];
474        if (!option.disabled && !option.empty) {
475          if (option.group) {
476            $('#' + option.dom_id).hide();
477          } else if (!(this.is_multiple && option.selected)) {
478            found = false;
479            result_id = option.dom_id;
480            if (regex.test(option.html)) {
481              found = true;
482              results += 1;
483            } else if (option.html.indexOf(" ") >= 0 || option.html.indexOf("[") === 0) {
484              parts = option.html.replace(/\[|\]/g, "").split(" ");
485              if (parts.length) {
486                for (_j = 0, _len2 = parts.length; _j < _len2; _j++) {
487                  part = parts[_j];
488                  if (regex.test(part)) {
489                    found = true;
490                    results += 1;
491                  }
492                }
493              }
494            }
495            if (found) {
496              if (searchText.length) {
497                startpos = option.html.search(zregex);
498                text = option.html.substr(0, startpos + searchText.length) + '</em>' + option.html.substr(startpos + searchText.length);
499                text = text.substr(0, startpos) + '<em>' + text.substr(startpos);
500              } else {
501                text = option.html;
502              }
503              if ($("#" + result_id).html !== text) {
504                $("#" + result_id).html(text);
505              }
506              this.result_activate($("#" + result_id));
507              if (option.group_array_index != null) {
508                $("#" + this.results_data[option.group_array_index].dom_id).show();
509              }
510            } else {
511              if (this.result_highlight && result_id === this.result_highlight.attr('id')) {
512                this.result_clear_highlight();
513              }
514              this.result_deactivate($("#" + result_id));
515            }
516          }
517        }
518      }
519      if (results < 1 && searchText.length) {
520        return this.no_results(searchText);
521      } else {
522        return this.winnow_results_set_highlight();
523      }
524    };
525    Chosen.prototype.winnow_results_clear = function() {
526      var li, lis, _i, _len, _results;
527      this.search_field.val("");
528      lis = this.search_results.find("li");
529      _results = [];
530      for (_i = 0, _len = lis.length; _i < _len; _i++) {
531        li = lis[_i];
532        li = $(li);
533        _results.push(li.hasClass("group-result") ? li.show() : !this.is_multiple || !li.hasClass("result-selected") ? this.result_activate(li) : void 0);
534      }
535      return _results;
536    };
537    Chosen.prototype.winnow_results_set_highlight = function() {
538      var do_high, selected_results;
539      if (!this.result_highlight) {
540        selected_results = !this.is_multiple ? this.search_results.find(".result-selected") : [];
541        do_high = selected_results.length ? selected_results.first() : this.search_results.find(".active-result").first();
542        if (do_high != null) {
543          return this.result_do_highlight(do_high);
544        }
545      }
546    };
547    Chosen.prototype.no_results = function(terms) {
548      var no_results_html;
549      no_results_html = $('<li class="no-results">No results match "<span></span>"</li>');
550      no_results_html.find("span").first().html(terms);
551      return this.search_results.append(no_results_html);
552    };
553    Chosen.prototype.no_results_clear = function() {
554      return this.search_results.find(".no-results").remove();
555    };
556    Chosen.prototype.keydown_arrow = function() {
557      var first_active, next_sib;
558      if (!this.result_highlight) {
559        first_active = this.search_results.find("li.active-result").first();
560        if (first_active) {
561          this.result_do_highlight($(first_active));
562        }
563      } else if (this.results_showing) {
564        next_sib = this.result_highlight.nextAll("li.active-result").first();
565        if (next_sib) {
566          this.result_do_highlight(next_sib);
567        }
568      }
569      if (!this.results_showing) {
570        return this.results_show();
571      }
572    };
573    Chosen.prototype.keyup_arrow = function() {
574      var prev_sibs;
575      if (!this.results_showing && !this.is_multiple) {
576        return this.results_show();
577      } else if (this.result_highlight) {
578        prev_sibs = this.result_highlight.prevAll("li.active-result");
579        if (prev_sibs.length) {
580          return this.result_do_highlight(prev_sibs.first());
581        } else {
582          if (this.choices > 0) {
583            this.results_hide();
584          }
585          return this.result_clear_highlight();
586        }
587      }
588    };
589    Chosen.prototype.keydown_backstroke = function() {
590      if (this.pending_backstroke) {
591        this.choice_destroy(this.pending_backstroke.find("a").first());
592        return this.clear_backstroke();
593      } else {
594        this.pending_backstroke = this.search_container.siblings("li.search-choice").last();
595        return this.pending_backstroke.addClass("search-choice-focus");
596      }
597    };
598    Chosen.prototype.clear_backstroke = function() {
599      if (this.pending_backstroke) {
600        this.pending_backstroke.removeClass("search-choice-focus");
601      }
602      return this.pending_backstroke = null;
603    };
604    Chosen.prototype.keyup_checker = function(evt) {
605      var stroke, _ref;
606      stroke = (_ref = evt.which) != null ? _ref : evt.keyCode;
607      this.search_field_scale();
608      switch (stroke) {
609        case 8:
610          if (this.is_multiple && this.backstroke_length < 1 && this.choices > 0) {
611            return this.keydown_backstroke();
612          } else if (!this.pending_backstroke) {
613            this.result_clear_highlight();
614            return this.results_search();
615          }
616          break;
617        case 13:
618          evt.preventDefault();
619          if (this.results_showing) {
620            return this.result_select(evt);
621          }
622          break;
623        case 27:
624          if (this.results_showing) {
625            return this.results_hide();
626          }
627          break;
628        case 9:
629        case 38:
630        case 40:
631        case 16:
632        case 91:
633        case 17:
634          break;
635        default:
636          return this.results_search();
637      }
638    };
639    Chosen.prototype.keydown_checker = function(evt) {
640      var stroke, _ref;
641      stroke = (_ref = evt.which) != null ? _ref : evt.keyCode;
642      this.search_field_scale();
643      if (stroke !== 8 && this.pending_backstroke) {
644        this.clear_backstroke();
645      }
646      switch (stroke) {
647        case 8:
648          this.backstroke_length = this.search_field.val().length;
649          break;
650        case 9:
651          this.mouse_on_container = false;
652          break;
653        case 13:
654          evt.preventDefault();
655          break;
656        case 38:
657          evt.preventDefault();
658          this.keyup_arrow();
659          break;
660        case 40:
661          this.keydown_arrow();
662          break;
663      }
664    };
665    Chosen.prototype.search_field_scale = function() {
666      var dd_top, div, h, style, style_block, styles, w, _i, _len;
667      if (this.is_multiple) {
668        h = 0;
669        w = 0;
670        style_block = "position:absolute; left: -1000px; top: -1000px; display:none;";
671        styles = ['font-size', 'font-style', 'font-weight', 'font-family', 'line-height', 'text-transform', 'letter-spacing'];
672        for (_i = 0, _len = styles.length; _i < _len; _i++) {
673          style = styles[_i];
674          style_block += style + ":" + this.search_field.css(style) + ";";
675        }
676        div = $('<div />', {
677          'style': style_block
678        });
679        div.text(this.search_field.val());
680        $('body').append(div);
681        w = div.width() + 25;
682        div.remove();
683        if (w > this.f_width - 10) {
684          w = this.f_width - 10;
685        }
686        this.search_field.css({
687          'width': w + 'px'
688        });
689        dd_top = this.container.height();
690        return this.dropdown.css({
691          "top": dd_top + "px"
692        });
693      }
694    };
695    Chosen.prototype.generate_field_id = function() {
696      var new_id;
697      new_id = this.generate_random_id();
698      this.form_field.id = new_id;
699      return new_id;
700    };
701    Chosen.prototype.generate_random_id = function() {
702      var string;
703      string = "sel" + this.generate_random_char() + this.generate_random_char() + this.generate_random_char();
704      while ($("#" + string).length > 0) {
705        string += this.generate_random_char();
706      }
707      return string;
708    };
709    Chosen.prototype.generate_random_char = function() {
710      var chars, newchar, rand;
711      chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZ";
712      rand = Math.floor(Math.random() * chars.length);
713      return newchar = chars.substring(rand, rand + 1);
714    };
715    return Chosen;
716  })();
717  get_side_border_padding = function(elmt) {
718    var side_border_padding;
719    return side_border_padding = elmt.outerWidth() - elmt.width();
720  };
721  root.get_side_border_padding = get_side_border_padding;
722}).call(this);
723(function() {
724  var SelectParser;
725  SelectParser = (function() {
726    function SelectParser() {
727      this.options_index = 0;
728      this.parsed = [];
729    }
730    SelectParser.prototype.add_node = function(child) {
731      if (child.nodeName === "OPTGROUP") {
732        return this.add_group(child);
733      } else {
734        return this.add_option(child);
735      }
736    };
737    SelectParser.prototype.add_group = function(group) {
738      var group_position, option, _i, _len, _ref, _results;
739      group_position = this.parsed.length;
740      this.parsed.push({
741        array_index: group_position,
742        group: true,
743        label: group.label,
744        children: 0,
745        disabled: group.disabled
746      });
747      _ref = group.childNodes;
748      _results = [];
749      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
750        option = _ref[_i];
751        _results.push(this.add_option(option, group_position, group.disabled));
752      }
753      return _results;
754    };
755    SelectParser.prototype.add_option = function(option, group_position, group_disabled) {
756      if (option.nodeName === "OPTION") {
757        if (option.text !== "") {
758          if (group_position != null) {
759            this.parsed[group_position].children += 1;
760          }
761          this.parsed.push({
762            array_index: this.parsed.length,
763            options_index: this.options_index,
764            value: option.value,
765            text: option.text,
766            html: option.innerHTML,
767            selected: option.selected,
768            disabled: group_disabled === true ? group_disabled : option.disabled,
769            group_array_index: group_position
770          });
771        } else {
772          this.parsed.push({
773            array_index: this.parsed.length,
774            options_index: this.options_index,
775            empty: true
776          });
777        }
778        return this.options_index += 1;
779      }
780    };
781    return SelectParser;
782  })();
783  SelectParser.select_to_array = function(select) {
784    var child, parser, _i, _len, _ref;
785    parser = new SelectParser();
786    _ref = select.childNodes;
787    for (_i = 0, _len = _ref.length; _i < _len; _i++) {
788      child = _ref[_i];
789      parser.add_node(child);
790    }
791    return parser.parsed;
792  };
793  this.SelectParser = SelectParser;
794}).call(this);