|
@@ -1,57 +1,274 @@
|
|
|
// Chosen, a Select Box Enhancer for jQuery and Protoype
|
|
|
// by Patrick Filler for Harvest, http://getharvest.com
|
|
|
//
|
|
|
-// Version 0.9.3
|
|
|
+// Version 0.9.5
|
|
|
// Full source at https://github.com/harvesthq/chosen
|
|
|
// Copyright (c) 2011 Harvest http://getharvest.com
|
|
|
|
|
|
// MIT License, https://github.com/harvesthq/chosen/blob/master/LICENSE.md
|
|
|
// This file is generated by `cake build`, do not edit it by hand.
|
|
|
+(function() {
|
|
|
+ var SelectParser;
|
|
|
+ SelectParser = (function() {
|
|
|
+ function SelectParser() {
|
|
|
+ this.options_index = 0;
|
|
|
+ this.parsed = [];
|
|
|
+ }
|
|
|
+ SelectParser.prototype.add_node = function(child) {
|
|
|
+ if (child.nodeName === "OPTGROUP") {
|
|
|
+ return this.add_group(child);
|
|
|
+ } else {
|
|
|
+ return this.add_option(child);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ SelectParser.prototype.add_group = function(group) {
|
|
|
+ var group_position, option, _i, _len, _ref, _results;
|
|
|
+ group_position = this.parsed.length;
|
|
|
+ this.parsed.push({
|
|
|
+ array_index: group_position,
|
|
|
+ group: true,
|
|
|
+ label: group.label,
|
|
|
+ children: 0,
|
|
|
+ disabled: group.disabled
|
|
|
+ });
|
|
|
+ _ref = group.childNodes;
|
|
|
+ _results = [];
|
|
|
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
|
+ option = _ref[_i];
|
|
|
+ _results.push(this.add_option(option, group_position, group.disabled));
|
|
|
+ }
|
|
|
+ return _results;
|
|
|
+ };
|
|
|
+ SelectParser.prototype.add_option = function(option, group_position, group_disabled) {
|
|
|
+ if (option.nodeName === "OPTION") {
|
|
|
+ if (option.text !== "") {
|
|
|
+ if (group_position != null) {
|
|
|
+ this.parsed[group_position].children += 1;
|
|
|
+ }
|
|
|
+ this.parsed.push({
|
|
|
+ array_index: this.parsed.length,
|
|
|
+ options_index: this.options_index,
|
|
|
+ value: option.value,
|
|
|
+ text: option.text,
|
|
|
+ html: option.innerHTML,
|
|
|
+ selected: option.selected,
|
|
|
+ disabled: group_disabled === true ? group_disabled : option.disabled,
|
|
|
+ group_array_index: group_position,
|
|
|
+ classes: option.className,
|
|
|
+ style: option.style.cssText
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ this.parsed.push({
|
|
|
+ array_index: this.parsed.length,
|
|
|
+ options_index: this.options_index,
|
|
|
+ empty: true
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return this.options_index += 1;
|
|
|
+ }
|
|
|
+ };
|
|
|
+ return SelectParser;
|
|
|
+ })();
|
|
|
+ SelectParser.select_to_array = function(select) {
|
|
|
+ var child, parser, _i, _len, _ref;
|
|
|
+ parser = new SelectParser();
|
|
|
+ _ref = select.childNodes;
|
|
|
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
|
+ child = _ref[_i];
|
|
|
+ parser.add_node(child);
|
|
|
+ }
|
|
|
+ return parser.parsed;
|
|
|
+ };
|
|
|
+ this.SelectParser = SelectParser;
|
|
|
+}).call(this);
|
|
|
(function() {
|
|
|
/*
|
|
|
Chosen source: generate output using 'cake build'
|
|
|
Copyright (c) 2011 by Harvest
|
|
|
- */ var $, Chosen, get_side_border_padding, root;
|
|
|
+ */
|
|
|
+ var AbstractChosen, root;
|
|
|
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
|
|
|
root = this;
|
|
|
- $ = jQuery;
|
|
|
- $.fn.extend({
|
|
|
- chosen: function(options) {
|
|
|
- if ($.browser === "msie" && ($.browser.version === "6.0" || $.browser.version === "7.0")) {
|
|
|
- return this;
|
|
|
- }
|
|
|
- return $(this).each(function(input_field) {
|
|
|
- if (!($(this)).hasClass("chzn-done")) {
|
|
|
- return new Chosen(this, options);
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- });
|
|
|
- Chosen = (function() {
|
|
|
- function Chosen(elmn, options) {
|
|
|
- this.options = options || {};
|
|
|
+ AbstractChosen = (function() {
|
|
|
+ function AbstractChosen(form_field, options) {
|
|
|
+ this.form_field = form_field;
|
|
|
+ this.options = options != null ? options : {};
|
|
|
this.set_default_values();
|
|
|
- this.form_field = elmn;
|
|
|
- this.form_field_jq = $(this.form_field);
|
|
|
this.is_multiple = this.form_field.multiple;
|
|
|
- this.is_rtl = this.form_field_jq.hasClass("chzn-rtl");
|
|
|
- this.default_text_default = this.form_field.multiple ? "Select Some Options" : "Select an Option";
|
|
|
+ this.default_text_default = this.is_multiple ? "Select Some Options" : "Select an Option";
|
|
|
+ this.setup();
|
|
|
this.set_up_html();
|
|
|
this.register_observers();
|
|
|
- this.form_field_jq.addClass("chzn-done");
|
|
|
+ this.finish_setup();
|
|
|
}
|
|
|
- Chosen.prototype.set_default_values = function() {
|
|
|
+ AbstractChosen.prototype.set_default_values = function() {
|
|
|
this.click_test_action = __bind(function(evt) {
|
|
|
return this.test_active_click(evt);
|
|
|
}, this);
|
|
|
+ this.activate_action = __bind(function(evt) {
|
|
|
+ return this.activate_field(evt);
|
|
|
+ }, this);
|
|
|
this.active_field = false;
|
|
|
this.mouse_on_container = false;
|
|
|
this.results_showing = false;
|
|
|
this.result_highlighted = null;
|
|
|
this.result_single_selected = null;
|
|
|
+ this.allow_single_deselect = (this.options.allow_single_deselect != null) && this.form_field.options[0].text === "" ? this.options.allow_single_deselect : false;
|
|
|
+ this.disable_search_threshold = this.options.disable_search_threshold || 0;
|
|
|
this.choices = 0;
|
|
|
return this.results_none_found = this.options.no_results_text || "No results match";
|
|
|
};
|
|
|
+ AbstractChosen.prototype.mouse_enter = function() {
|
|
|
+ return this.mouse_on_container = true;
|
|
|
+ };
|
|
|
+ AbstractChosen.prototype.mouse_leave = function() {
|
|
|
+ return this.mouse_on_container = false;
|
|
|
+ };
|
|
|
+ AbstractChosen.prototype.input_focus = function(evt) {
|
|
|
+ if (!this.active_field) {
|
|
|
+ return setTimeout((__bind(function() {
|
|
|
+ return this.container_mousedown();
|
|
|
+ }, this)), 50);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ AbstractChosen.prototype.input_blur = function(evt) {
|
|
|
+ if (!this.mouse_on_container) {
|
|
|
+ this.active_field = false;
|
|
|
+ return setTimeout((__bind(function() {
|
|
|
+ return this.blur_test();
|
|
|
+ }, this)), 100);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ AbstractChosen.prototype.result_add_option = function(option) {
|
|
|
+ var classes, style;
|
|
|
+ if (!option.disabled) {
|
|
|
+ option.dom_id = this.container_id + "_o_" + option.array_index;
|
|
|
+ classes = option.selected && this.is_multiple ? [] : ["active-result"];
|
|
|
+ if (option.selected) {
|
|
|
+ classes.push("result-selected");
|
|
|
+ }
|
|
|
+ if (option.group_array_index != null) {
|
|
|
+ classes.push("group-option");
|
|
|
+ }
|
|
|
+ if (option.classes !== "") {
|
|
|
+ classes.push(option.classes);
|
|
|
+ }
|
|
|
+ style = option.style.cssText !== "" ? " style=\"" + option.style + "\"" : "";
|
|
|
+ return '<li id="' + option.dom_id + '" class="' + classes.join(' ') + '"' + style + '>' + option.html + '</li>';
|
|
|
+ } else {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ };
|
|
|
+ AbstractChosen.prototype.results_update_field = function() {
|
|
|
+ this.result_clear_highlight();
|
|
|
+ this.result_single_selected = null;
|
|
|
+ return this.results_build();
|
|
|
+ };
|
|
|
+ AbstractChosen.prototype.results_toggle = function() {
|
|
|
+ if (this.results_showing) {
|
|
|
+ return this.results_hide();
|
|
|
+ } else {
|
|
|
+ return this.results_show();
|
|
|
+ }
|
|
|
+ };
|
|
|
+ AbstractChosen.prototype.results_search = function(evt) {
|
|
|
+ if (this.results_showing) {
|
|
|
+ return this.winnow_results();
|
|
|
+ } else {
|
|
|
+ return this.results_show();
|
|
|
+ }
|
|
|
+ };
|
|
|
+ AbstractChosen.prototype.keyup_checker = function(evt) {
|
|
|
+ var stroke, _ref;
|
|
|
+ stroke = (_ref = evt.which) != null ? _ref : evt.keyCode;
|
|
|
+ this.search_field_scale();
|
|
|
+ switch (stroke) {
|
|
|
+ case 8:
|
|
|
+ if (this.is_multiple && this.backstroke_length < 1 && this.choices > 0) {
|
|
|
+ return this.keydown_backstroke();
|
|
|
+ } else if (!this.pending_backstroke) {
|
|
|
+ this.result_clear_highlight();
|
|
|
+ return this.results_search();
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 13:
|
|
|
+ evt.preventDefault();
|
|
|
+ if (this.results_showing) {
|
|
|
+ return this.result_select(evt);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 27:
|
|
|
+ if (this.results_showing) {
|
|
|
+ return this.results_hide();
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 9:
|
|
|
+ case 38:
|
|
|
+ case 40:
|
|
|
+ case 16:
|
|
|
+ case 91:
|
|
|
+ case 17:
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ return this.results_search();
|
|
|
+ }
|
|
|
+ };
|
|
|
+ AbstractChosen.prototype.generate_field_id = function() {
|
|
|
+ var new_id;
|
|
|
+ new_id = this.generate_random_id();
|
|
|
+ this.form_field.id = new_id;
|
|
|
+ return new_id;
|
|
|
+ };
|
|
|
+ AbstractChosen.prototype.generate_random_char = function() {
|
|
|
+ var chars, newchar, rand;
|
|
|
+ chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZ";
|
|
|
+ rand = Math.floor(Math.random() * chars.length);
|
|
|
+ return newchar = chars.substring(rand, rand + 1);
|
|
|
+ };
|
|
|
+ return AbstractChosen;
|
|
|
+ })();
|
|
|
+ root.AbstractChosen = AbstractChosen;
|
|
|
+}).call(this);
|
|
|
+(function() {
|
|
|
+ /*
|
|
|
+ Chosen source: generate output using 'cake build'
|
|
|
+ Copyright (c) 2011 by Harvest
|
|
|
+ */
|
|
|
+ var $, Chosen, get_side_border_padding, root;
|
|
|
+ var __hasProp = Object.prototype.hasOwnProperty, __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;
|
|
|
+ }, __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
|
|
|
+ root = this;
|
|
|
+ $ = jQuery;
|
|
|
+ $.fn.extend({
|
|
|
+ chosen: function(options) {
|
|
|
+ if ($.browser.msie && ($.browser.version === "6.0" || $.browser.version === "7.0")) {
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+ return $(this).each(function(input_field) {
|
|
|
+ if (!($(this)).hasClass("chzn-done")) {
|
|
|
+ return new Chosen(this, options);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ Chosen = (function() {
|
|
|
+ __extends(Chosen, AbstractChosen);
|
|
|
+ function Chosen() {
|
|
|
+ Chosen.__super__.constructor.apply(this, arguments);
|
|
|
+ }
|
|
|
+ Chosen.prototype.setup = function() {
|
|
|
+ this.form_field_jq = $(this.form_field);
|
|
|
+ return this.is_rtl = this.form_field_jq.hasClass("chzn-rtl");
|
|
|
+ };
|
|
|
+ Chosen.prototype.finish_setup = function() {
|
|
|
+ return this.form_field_jq.addClass("chzn-done");
|
|
|
+ };
|
|
|
Chosen.prototype.set_up_html = function() {
|
|
|
var container_div, dd_top, dd_width, sf_width;
|
|
|
this.container_id = this.form_field.id.length ? this.form_field.id.replace(/(:|\.)/g, '_') : this.generate_field_id();
|
|
@@ -60,7 +277,7 @@
|
|
|
this.default_text = this.form_field_jq.data('placeholder') ? this.form_field_jq.data('placeholder') : this.default_text_default;
|
|
|
container_div = $("<div />", {
|
|
|
id: this.container_id,
|
|
|
- "class": "chzn-container " + (this.is_rtl ? 'chzn-rtl' : ''),
|
|
|
+ "class": "chzn-container" + (this.is_rtl ? ' chzn-rtl' : ''),
|
|
|
style: 'width: ' + this.f_width + 'px;'
|
|
|
});
|
|
|
if (this.is_multiple) {
|
|
@@ -71,6 +288,9 @@
|
|
|
this.form_field_jq.hide().after(container_div);
|
|
|
this.container = $('#' + this.container_id);
|
|
|
this.container.addClass("chzn-container-" + (this.is_multiple ? "multi" : "single"));
|
|
|
+ if (!this.is_multiple && this.form_field.options.length <= this.disable_search_threshold) {
|
|
|
+ this.container.addClass("chzn-container-single-nosearch");
|
|
|
+ }
|
|
|
this.dropdown = this.container.find('div.chzn-drop').first();
|
|
|
dd_top = this.container.height();
|
|
|
dd_width = this.f_width - get_side_border_padding(this.dropdown);
|
|
@@ -94,12 +314,18 @@
|
|
|
});
|
|
|
}
|
|
|
this.results_build();
|
|
|
- return this.set_tab_index();
|
|
|
+ this.set_tab_index();
|
|
|
+ return this.form_field_jq.trigger("liszt:ready", {
|
|
|
+ chosen: this
|
|
|
+ });
|
|
|
};
|
|
|
Chosen.prototype.register_observers = function() {
|
|
|
this.container.mousedown(__bind(function(evt) {
|
|
|
return this.container_mousedown(evt);
|
|
|
}, this));
|
|
|
+ this.container.mouseup(__bind(function(evt) {
|
|
|
+ return this.container_mouseup(evt);
|
|
|
+ }, this));
|
|
|
this.container.mouseenter(__bind(function(evt) {
|
|
|
return this.mouse_enter(evt);
|
|
|
}, this));
|
|
@@ -134,51 +360,52 @@
|
|
|
return this.search_field.focus(__bind(function(evt) {
|
|
|
return this.input_focus(evt);
|
|
|
}, this));
|
|
|
- } else {
|
|
|
- return this.selected_item.focus(__bind(function(evt) {
|
|
|
- return this.activate_field(evt);
|
|
|
- }, this));
|
|
|
}
|
|
|
};
|
|
|
- Chosen.prototype.container_mousedown = function(evt) {
|
|
|
- if (evt && evt.type === "mousedown") {
|
|
|
- evt.stopPropagation();
|
|
|
- }
|
|
|
- if (!this.pending_destroy_click) {
|
|
|
- if (!this.active_field) {
|
|
|
- if (this.is_multiple) {
|
|
|
- this.search_field.val("");
|
|
|
- }
|
|
|
- $(document).click(this.click_test_action);
|
|
|
- this.results_show();
|
|
|
- } else if (!this.is_multiple && evt && ($(evt.target) === this.selected_item || $(evt.target).parents("a.chzn-single").length)) {
|
|
|
- evt.preventDefault();
|
|
|
- this.results_toggle();
|
|
|
+ Chosen.prototype.search_field_disabled = function() {
|
|
|
+ this.is_disabled = this.form_field_jq.attr('disabled');
|
|
|
+ if (this.is_disabled) {
|
|
|
+ this.container.addClass('chzn-disabled');
|
|
|
+ this.search_field.attr('disabled', true);
|
|
|
+ if (!this.is_multiple) {
|
|
|
+ this.selected_item.unbind("focus", this.activate_action);
|
|
|
}
|
|
|
- return this.activate_field();
|
|
|
+ return this.close_field();
|
|
|
} else {
|
|
|
- return this.pending_destroy_click = false;
|
|
|
+ this.container.removeClass('chzn-disabled');
|
|
|
+ this.search_field.attr('disabled', false);
|
|
|
+ if (!this.is_multiple) {
|
|
|
+ return this.selected_item.bind("focus", this.activate_action);
|
|
|
+ }
|
|
|
}
|
|
|
};
|
|
|
- Chosen.prototype.mouse_enter = function() {
|
|
|
- return this.mouse_on_container = true;
|
|
|
- };
|
|
|
- Chosen.prototype.mouse_leave = function() {
|
|
|
- return this.mouse_on_container = false;
|
|
|
- };
|
|
|
- Chosen.prototype.input_focus = function(evt) {
|
|
|
- if (!this.active_field) {
|
|
|
- return setTimeout((__bind(function() {
|
|
|
- return this.container_mousedown();
|
|
|
- }, this)), 50);
|
|
|
+ Chosen.prototype.container_mousedown = function(evt) {
|
|
|
+ var target_closelink;
|
|
|
+ if (!this.is_disabled) {
|
|
|
+ target_closelink = evt != null ? ($(evt.target)).hasClass("search-choice-close") : false;
|
|
|
+ if (evt && evt.type === "mousedown") {
|
|
|
+ evt.stopPropagation();
|
|
|
+ }
|
|
|
+ if (!this.pending_destroy_click && !target_closelink) {
|
|
|
+ if (!this.active_field) {
|
|
|
+ if (this.is_multiple) {
|
|
|
+ this.search_field.val("");
|
|
|
+ }
|
|
|
+ $(document).click(this.click_test_action);
|
|
|
+ this.results_show();
|
|
|
+ } else if (!this.is_multiple && evt && ($(evt.target) === this.selected_item || $(evt.target).parents("a.chzn-single").length)) {
|
|
|
+ evt.preventDefault();
|
|
|
+ this.results_toggle();
|
|
|
+ }
|
|
|
+ return this.activate_field();
|
|
|
+ } else {
|
|
|
+ return this.pending_destroy_click = false;
|
|
|
+ }
|
|
|
}
|
|
|
};
|
|
|
- Chosen.prototype.input_blur = function(evt) {
|
|
|
- if (!this.mouse_on_container) {
|
|
|
- this.active_field = false;
|
|
|
- return setTimeout((__bind(function() {
|
|
|
- return this.blur_test();
|
|
|
- }, this)), 100);
|
|
|
+ Chosen.prototype.container_mouseup = function(evt) {
|
|
|
+ if (evt.target.nodeName === "ABBR") {
|
|
|
+ return this.results_reset(evt);
|
|
|
}
|
|
|
};
|
|
|
Chosen.prototype.blur_test = function(evt) {
|
|
@@ -240,9 +467,13 @@
|
|
|
this.choice_build(data);
|
|
|
} else if (data.selected && !this.is_multiple) {
|
|
|
this.selected_item.find("span").text(data.text);
|
|
|
+ if (this.allow_single_deselect) {
|
|
|
+ this.single_deselect_control_build();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ this.search_field_disabled();
|
|
|
this.show_search_field_default();
|
|
|
this.search_field_scale();
|
|
|
this.search_results.html(content);
|
|
@@ -256,27 +487,6 @@
|
|
|
return "";
|
|
|
}
|
|
|
};
|
|
|
- Chosen.prototype.result_add_option = function(option) {
|
|
|
- var classes;
|
|
|
- if (!option.disabled) {
|
|
|
- option.dom_id = this.container_id + "_o_" + option.array_index;
|
|
|
- classes = option.selected && this.is_multiple ? [] : ["active-result"];
|
|
|
- if (option.selected) {
|
|
|
- classes.push("result-selected");
|
|
|
- }
|
|
|
- if (option.group_array_index != null) {
|
|
|
- classes.push("group-option");
|
|
|
- }
|
|
|
- return '<li id="' + option.dom_id + '" class="' + classes.join(' ') + '">' + option.html + '</li>';
|
|
|
- } else {
|
|
|
- return "";
|
|
|
- }
|
|
|
- };
|
|
|
- Chosen.prototype.results_update_field = function() {
|
|
|
- this.result_clear_highlight();
|
|
|
- this.result_single_selected = null;
|
|
|
- return this.results_build();
|
|
|
- };
|
|
|
Chosen.prototype.result_do_highlight = function(el) {
|
|
|
var high_bottom, high_top, maxHeight, visible_bottom, visible_top;
|
|
|
if (el.length) {
|
|
@@ -301,13 +511,6 @@
|
|
|
}
|
|
|
return this.result_highlight = null;
|
|
|
};
|
|
|
- Chosen.prototype.results_toggle = function() {
|
|
|
- if (this.results_showing) {
|
|
|
- return this.results_hide();
|
|
|
- } else {
|
|
|
- return this.results_show();
|
|
|
- }
|
|
|
- };
|
|
|
Chosen.prototype.results_show = function() {
|
|
|
var dd_top;
|
|
|
if (!this.is_multiple) {
|
|
@@ -396,8 +599,12 @@
|
|
|
};
|
|
|
Chosen.prototype.choice_destroy_link_click = function(evt) {
|
|
|
evt.preventDefault();
|
|
|
- this.pending_destroy_click = true;
|
|
|
- return this.choice_destroy($(evt.target));
|
|
|
+ if (!this.is_disabled) {
|
|
|
+ this.pending_destroy_click = true;
|
|
|
+ return this.choice_destroy($(evt.target));
|
|
|
+ } else {
|
|
|
+ return evt.stopPropagation;
|
|
|
+ }
|
|
|
};
|
|
|
Chosen.prototype.choice_destroy = function(link) {
|
|
|
this.choices -= 1;
|
|
@@ -408,18 +615,29 @@
|
|
|
this.result_deselect(link.attr("rel"));
|
|
|
return link.parents('li').first().remove();
|
|
|
};
|
|
|
+ Chosen.prototype.results_reset = function(evt) {
|
|
|
+ this.form_field.options[0].selected = true;
|
|
|
+ this.selected_item.find("span").text(this.default_text);
|
|
|
+ this.show_search_field_default();
|
|
|
+ $(evt.target).remove();
|
|
|
+ this.form_field_jq.trigger("change");
|
|
|
+ if (this.active_field) {
|
|
|
+ return this.results_hide();
|
|
|
+ }
|
|
|
+ };
|
|
|
Chosen.prototype.result_select = function(evt) {
|
|
|
var high, high_id, item, position;
|
|
|
if (this.result_highlight) {
|
|
|
high = this.result_highlight;
|
|
|
high_id = high.attr("id");
|
|
|
this.result_clear_highlight();
|
|
|
- high.addClass("result-selected");
|
|
|
if (this.is_multiple) {
|
|
|
this.result_deactivate(high);
|
|
|
} else {
|
|
|
+ this.search_results.find(".result-selected").removeClass("result-selected");
|
|
|
this.result_single_selected = high;
|
|
|
}
|
|
|
+ high.addClass("result-selected");
|
|
|
position = high_id.substr(high_id.lastIndexOf("_") + 1);
|
|
|
item = this.results_data[position];
|
|
|
item.selected = true;
|
|
@@ -428,6 +646,9 @@
|
|
|
this.choice_build(item);
|
|
|
} else {
|
|
|
this.selected_item.find("span").first().text(item.text);
|
|
|
+ if (this.allow_single_deselect) {
|
|
|
+ this.single_deselect_control_build();
|
|
|
+ }
|
|
|
}
|
|
|
if (!(evt.metaKey && this.is_multiple)) {
|
|
|
this.results_hide();
|
|
@@ -438,10 +659,10 @@
|
|
|
}
|
|
|
};
|
|
|
Chosen.prototype.result_activate = function(el) {
|
|
|
- return el.addClass("active-result").show();
|
|
|
+ return el.addClass("active-result");
|
|
|
};
|
|
|
Chosen.prototype.result_deactivate = function(el) {
|
|
|
- return el.removeClass("active-result").hide();
|
|
|
+ return el.removeClass("active-result");
|
|
|
};
|
|
|
Chosen.prototype.result_deselect = function(pos) {
|
|
|
var result, result_data;
|
|
@@ -455,11 +676,9 @@
|
|
|
this.form_field_jq.trigger("change");
|
|
|
return this.search_field_scale();
|
|
|
};
|
|
|
- Chosen.prototype.results_search = function(evt) {
|
|
|
- if (this.results_showing) {
|
|
|
- return this.winnow_results();
|
|
|
- } else {
|
|
|
- return this.results_show();
|
|
|
+ Chosen.prototype.single_deselect_control_build = function() {
|
|
|
+ if (this.allow_single_deselect && this.selected_item.find("abbr").length < 1) {
|
|
|
+ return this.selected_item.find("span").first().after("<abbr class=\"search-choice-close\"></abbr>");
|
|
|
}
|
|
|
};
|
|
|
Chosen.prototype.winnow_results = function() {
|
|
@@ -539,7 +758,7 @@
|
|
|
Chosen.prototype.winnow_results_set_highlight = function() {
|
|
|
var do_high, selected_results;
|
|
|
if (!this.result_highlight) {
|
|
|
- selected_results = !this.is_multiple ? this.search_results.find(".result-selected") : [];
|
|
|
+ selected_results = !this.is_multiple ? this.search_results.find(".result-selected.active-result") : [];
|
|
|
do_high = selected_results.length ? selected_results.first() : this.search_results.find(".active-result").first();
|
|
|
if (do_high != null) {
|
|
|
return this.result_do_highlight(do_high);
|
|
@@ -603,41 +822,6 @@
|
|
|
}
|
|
|
return this.pending_backstroke = null;
|
|
|
};
|
|
|
- Chosen.prototype.keyup_checker = function(evt) {
|
|
|
- var stroke, _ref;
|
|
|
- stroke = (_ref = evt.which) != null ? _ref : evt.keyCode;
|
|
|
- this.search_field_scale();
|
|
|
- switch (stroke) {
|
|
|
- case 8:
|
|
|
- if (this.is_multiple && this.backstroke_length < 1 && this.choices > 0) {
|
|
|
- return this.keydown_backstroke();
|
|
|
- } else if (!this.pending_backstroke) {
|
|
|
- this.result_clear_highlight();
|
|
|
- return this.results_search();
|
|
|
- }
|
|
|
- break;
|
|
|
- case 13:
|
|
|
- evt.preventDefault();
|
|
|
- if (this.results_showing) {
|
|
|
- return this.result_select(evt);
|
|
|
- }
|
|
|
- break;
|
|
|
- case 27:
|
|
|
- if (this.results_showing) {
|
|
|
- return this.results_hide();
|
|
|
- }
|
|
|
- break;
|
|
|
- case 9:
|
|
|
- case 38:
|
|
|
- case 40:
|
|
|
- case 16:
|
|
|
- case 91:
|
|
|
- case 17:
|
|
|
- break;
|
|
|
- default:
|
|
|
- return this.results_search();
|
|
|
- }
|
|
|
- };
|
|
|
Chosen.prototype.keydown_checker = function(evt) {
|
|
|
var stroke, _ref;
|
|
|
stroke = (_ref = evt.which) != null ? _ref : evt.keyCode;
|
|
@@ -650,6 +834,9 @@
|
|
|
this.backstroke_length = this.search_field.val().length;
|
|
|
break;
|
|
|
case 9:
|
|
|
+ if (this.results_showing && !this.is_multiple) {
|
|
|
+ this.result_select(evt);
|
|
|
+ }
|
|
|
this.mouse_on_container = false;
|
|
|
break;
|
|
|
case 13:
|
|
@@ -694,12 +881,6 @@
|
|
|
});
|
|
|
}
|
|
|
};
|
|
|
- Chosen.prototype.generate_field_id = function() {
|
|
|
- var new_id;
|
|
|
- new_id = this.generate_random_id();
|
|
|
- this.form_field.id = new_id;
|
|
|
- return new_id;
|
|
|
- };
|
|
|
Chosen.prototype.generate_random_id = function() {
|
|
|
var string;
|
|
|
string = "sel" + this.generate_random_char() + this.generate_random_char() + this.generate_random_char();
|
|
@@ -708,12 +889,6 @@
|
|
|
}
|
|
|
return string;
|
|
|
};
|
|
|
- Chosen.prototype.generate_random_char = function() {
|
|
|
- var chars, newchar, rand;
|
|
|
- chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZ";
|
|
|
- rand = Math.floor(Math.random() * chars.length);
|
|
|
- return newchar = chars.substring(rand, rand + 1);
|
|
|
- };
|
|
|
return Chosen;
|
|
|
})();
|
|
|
get_side_border_padding = function(elmt) {
|
|
@@ -722,75 +897,3 @@
|
|
|
};
|
|
|
root.get_side_border_padding = get_side_border_padding;
|
|
|
}).call(this);
|
|
|
-(function() {
|
|
|
- var SelectParser;
|
|
|
- SelectParser = (function() {
|
|
|
- function SelectParser() {
|
|
|
- this.options_index = 0;
|
|
|
- this.parsed = [];
|
|
|
- }
|
|
|
- SelectParser.prototype.add_node = function(child) {
|
|
|
- if (child.nodeName === "OPTGROUP") {
|
|
|
- return this.add_group(child);
|
|
|
- } else {
|
|
|
- return this.add_option(child);
|
|
|
- }
|
|
|
- };
|
|
|
- SelectParser.prototype.add_group = function(group) {
|
|
|
- var group_position, option, _i, _len, _ref, _results;
|
|
|
- group_position = this.parsed.length;
|
|
|
- this.parsed.push({
|
|
|
- array_index: group_position,
|
|
|
- group: true,
|
|
|
- label: group.label,
|
|
|
- children: 0,
|
|
|
- disabled: group.disabled
|
|
|
- });
|
|
|
- _ref = group.childNodes;
|
|
|
- _results = [];
|
|
|
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
|
- option = _ref[_i];
|
|
|
- _results.push(this.add_option(option, group_position, group.disabled));
|
|
|
- }
|
|
|
- return _results;
|
|
|
- };
|
|
|
- SelectParser.prototype.add_option = function(option, group_position, group_disabled) {
|
|
|
- if (option.nodeName === "OPTION") {
|
|
|
- if (option.text !== "") {
|
|
|
- if (group_position != null) {
|
|
|
- this.parsed[group_position].children += 1;
|
|
|
- }
|
|
|
- this.parsed.push({
|
|
|
- array_index: this.parsed.length,
|
|
|
- options_index: this.options_index,
|
|
|
- value: option.value,
|
|
|
- text: option.text,
|
|
|
- html: option.innerHTML,
|
|
|
- selected: option.selected,
|
|
|
- disabled: group_disabled === true ? group_disabled : option.disabled,
|
|
|
- group_array_index: group_position
|
|
|
- });
|
|
|
- } else {
|
|
|
- this.parsed.push({
|
|
|
- array_index: this.parsed.length,
|
|
|
- options_index: this.options_index,
|
|
|
- empty: true
|
|
|
- });
|
|
|
- }
|
|
|
- return this.options_index += 1;
|
|
|
- }
|
|
|
- };
|
|
|
- return SelectParser;
|
|
|
- })();
|
|
|
- SelectParser.select_to_array = function(select) {
|
|
|
- var child, parser, _i, _len, _ref;
|
|
|
- parser = new SelectParser();
|
|
|
- _ref = select.childNodes;
|
|
|
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
|
- child = _ref[_i];
|
|
|
- parser.add_node(child);
|
|
|
- }
|
|
|
- return parser.parsed;
|
|
|
- };
|
|
|
- this.SelectParser = SelectParser;
|
|
|
-}).call(this);
|