source: sandbox/expresso-solr/solr/example/work/jetty-0.0.0.0-8983-solr.war-_solr-any-/webapp/js/lib/chosen.js @ 7588

Revision 7588, 33.7 KB checked in by adir, 11 years ago (diff)

Ticket #000 - Adicionando a integracao de buscas com Solr na base a ser isnerida na comunidade

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