|
|
|
@ -1,7 +1,7 @@ |
|
|
|
|
// Chosen, a Select Box Enhancer for jQuery and Protoype
|
|
|
|
|
// by Patrick Filler for Harvest, http://getharvest.com
|
|
|
|
|
//
|
|
|
|
|
// Version 0.9.8
|
|
|
|
|
//
|
|
|
|
|
// Version 0.9.11
|
|
|
|
|
// Full source at https://github.com/harvesthq/chosen
|
|
|
|
|
// Copyright (c) 2011 Harvest http://getharvest.com
|
|
|
|
|
|
|
|
|
@ -18,7 +18,7 @@ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
SelectParser.prototype.add_node = function(child) { |
|
|
|
|
if (child.nodeName === "OPTGROUP") { |
|
|
|
|
if (child.nodeName.toUpperCase() === "OPTGROUP") { |
|
|
|
|
return this.add_group(child); |
|
|
|
|
} else { |
|
|
|
|
return this.add_option(child); |
|
|
|
@ -45,9 +45,11 @@ |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
SelectParser.prototype.add_option = function(option, group_position, group_disabled) { |
|
|
|
|
if (option.nodeName === "OPTION") { |
|
|
|
|
if (option.nodeName.toUpperCase() === "OPTION") { |
|
|
|
|
if (option.text !== "") { |
|
|
|
|
if (group_position != null) this.parsed[group_position].children += 1; |
|
|
|
|
if (group_position != null) { |
|
|
|
|
this.parsed[group_position].children += 1; |
|
|
|
|
} |
|
|
|
|
this.parsed.push({ |
|
|
|
|
array_index: this.parsed.length, |
|
|
|
|
options_index: this.options_index, |
|
|
|
@ -95,6 +97,7 @@ Chosen source: generate output using 'cake build' |
|
|
|
|
Copyright (c) 2011 by Harvest |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(function() { |
|
|
|
|
var AbstractChosen, root; |
|
|
|
|
|
|
|
|
@ -105,9 +108,9 @@ Copyright (c) 2011 by Harvest |
|
|
|
|
function AbstractChosen(form_field, options) { |
|
|
|
|
this.form_field = form_field; |
|
|
|
|
this.options = options != null ? options : {}; |
|
|
|
|
this.set_default_values(); |
|
|
|
|
this.is_multiple = this.form_field.multiple; |
|
|
|
|
this.set_default_text(); |
|
|
|
|
this.set_default_values(); |
|
|
|
|
this.setup(); |
|
|
|
|
this.set_up_html(); |
|
|
|
|
this.register_observers(); |
|
|
|
@ -129,10 +132,13 @@ Copyright (c) 2011 by Harvest |
|
|
|
|
this.result_single_selected = null; |
|
|
|
|
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; |
|
|
|
|
this.disable_search_threshold = this.options.disable_search_threshold || 0; |
|
|
|
|
this.disable_search = this.options.disable_search || false; |
|
|
|
|
this.enable_split_word_search = this.options.enable_split_word_search != null ? this.options.enable_split_word_search : true; |
|
|
|
|
this.search_contains = this.options.search_contains || false; |
|
|
|
|
this.choices = 0; |
|
|
|
|
this.single_backstroke_delete = this.options.single_backstroke_delete || false; |
|
|
|
|
return this.max_selected_options = this.options.max_selected_options || Infinity; |
|
|
|
|
this.max_selected_options = this.options.max_selected_options || Infinity; |
|
|
|
|
return this.inherit_select_classes = this.options.inherit_select_classes || false; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
AbstractChosen.prototype.set_default_text = function() { |
|
|
|
@ -156,10 +162,16 @@ Copyright (c) 2011 by Harvest |
|
|
|
|
|
|
|
|
|
AbstractChosen.prototype.input_focus = function(evt) { |
|
|
|
|
var _this = this; |
|
|
|
|
if (!this.active_field) { |
|
|
|
|
return setTimeout((function() { |
|
|
|
|
return _this.container_mousedown(); |
|
|
|
|
}), 50); |
|
|
|
|
if (this.is_multiple) { |
|
|
|
|
if (!this.active_field) { |
|
|
|
|
return setTimeout((function() { |
|
|
|
|
return _this.container_mousedown(); |
|
|
|
|
}), 50); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
if (!this.active_field) { |
|
|
|
|
return this.activate_field(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
@ -178,9 +190,15 @@ Copyright (c) 2011 by Harvest |
|
|
|
|
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); |
|
|
|
|
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 { |
|
|
|
@ -189,7 +207,9 @@ Copyright (c) 2011 by Harvest |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
AbstractChosen.prototype.results_update_field = function() { |
|
|
|
|
if (!this.is_multiple) this.results_reset_cleanup(); |
|
|
|
|
if (!this.is_multiple) { |
|
|
|
|
this.results_reset_cleanup(); |
|
|
|
|
} |
|
|
|
|
this.result_clear_highlight(); |
|
|
|
|
this.result_single_selected = null; |
|
|
|
|
return this.results_build(); |
|
|
|
@ -226,10 +246,14 @@ Copyright (c) 2011 by Harvest |
|
|
|
|
break; |
|
|
|
|
case 13: |
|
|
|
|
evt.preventDefault(); |
|
|
|
|
if (this.results_showing) return this.result_select(evt); |
|
|
|
|
if (this.results_showing) { |
|
|
|
|
return this.result_select(evt); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case 27: |
|
|
|
|
if (this.results_showing) this.results_hide(); |
|
|
|
|
if (this.results_showing) { |
|
|
|
|
this.results_hide(); |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
case 9: |
|
|
|
|
case 38: |
|
|
|
@ -270,10 +294,11 @@ Chosen source: generate output using 'cake build' |
|
|
|
|
Copyright (c) 2011 by Harvest |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(function() { |
|
|
|
|
var $, Chosen, get_side_border_padding, root, |
|
|
|
|
__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; }; |
|
|
|
|
__hasProp = {}.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; }; |
|
|
|
|
|
|
|
|
|
root = this; |
|
|
|
|
|
|
|
|
@ -281,7 +306,14 @@ Copyright (c) 2011 by Harvest |
|
|
|
|
|
|
|
|
|
$.fn.extend({ |
|
|
|
|
chosen: function(options) { |
|
|
|
|
if ($.browser.msie && ($.browser.version === "6.0" || $.browser.version === "7.0")) { |
|
|
|
|
var browser, match, ua; |
|
|
|
|
ua = navigator.userAgent.toLowerCase(); |
|
|
|
|
match = /(msie) ([\w.]+)/.exec(ua) || []; |
|
|
|
|
browser = { |
|
|
|
|
name: match[1] || "", |
|
|
|
|
version: match[2] || "0" |
|
|
|
|
}; |
|
|
|
|
if (browser.name === "msie" && (browser.version === "6.0" || (browser.version === "7.0" && document.documentMode === 7))) { |
|
|
|
|
return this; |
|
|
|
|
} |
|
|
|
|
return this.each(function(input_field) { |
|
|
|
@ -299,7 +331,7 @@ Copyright (c) 2011 by Harvest |
|
|
|
|
__extends(Chosen, _super); |
|
|
|
|
|
|
|
|
|
function Chosen() { |
|
|
|
|
Chosen.__super__.constructor.apply(this, arguments); |
|
|
|
|
return Chosen.__super__.constructor.apply(this, arguments); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Chosen.prototype.setup = function() { |
|
|
|
@ -313,23 +345,32 @@ Copyright (c) 2011 by Harvest |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
Chosen.prototype.set_up_html = function() { |
|
|
|
|
var container_div, dd_top, dd_width, sf_width; |
|
|
|
|
var container_classes, container_div, container_props, dd_top, dd_width, sf_width; |
|
|
|
|
this.container_id = this.form_field.id.length ? this.form_field.id.replace(/[^\w]/g, '_') : this.generate_field_id(); |
|
|
|
|
this.container_id += "_chzn"; |
|
|
|
|
container_classes = ["chzn-container"]; |
|
|
|
|
container_classes.push("chzn-container-" + (this.is_multiple ? "multi" : "single")); |
|
|
|
|
if (this.inherit_select_classes && this.form_field.className) { |
|
|
|
|
container_classes.push(this.form_field.className); |
|
|
|
|
} |
|
|
|
|
if (this.is_rtl) { |
|
|
|
|
container_classes.push("chzn-rtl"); |
|
|
|
|
} |
|
|
|
|
this.f_width = this.form_field_jq.outerWidth(); |
|
|
|
|
container_div = $("<div />", { |
|
|
|
|
container_props = { |
|
|
|
|
id: this.container_id, |
|
|
|
|
"class": "chzn-container" + (this.is_rtl ? ' chzn-rtl' : ''), |
|
|
|
|
style: 'width: ' + this.f_width + 'px;' |
|
|
|
|
}); |
|
|
|
|
"class": container_classes.join(' '), |
|
|
|
|
style: 'width: ' + this.f_width + 'px;', |
|
|
|
|
title: this.form_field.title |
|
|
|
|
}; |
|
|
|
|
container_div = $("<div />", container_props); |
|
|
|
|
if (this.is_multiple) { |
|
|
|
|
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>'); |
|
|
|
|
} else { |
|
|
|
|
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="text" autocomplete="off" /></div><ul class="chzn-results"></ul></div>'); |
|
|
|
|
container_div.html('<a href="javascript:void(0)" class="chzn-single chzn-default" tabindex="-1"><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>'); |
|
|
|
|
} |
|
|
|
|
this.form_field_jq.hide().after(container_div); |
|
|
|
|
this.container = $('#' + this.container_id); |
|
|
|
|
this.container.addClass("chzn-container-" + (this.is_multiple ? "multi" : "single")); |
|
|
|
|
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); |
|
|
|
@ -385,6 +426,12 @@ Copyright (c) 2011 by Harvest |
|
|
|
|
this.form_field_jq.bind("liszt:updated", function(evt) { |
|
|
|
|
return _this.results_update_field(evt); |
|
|
|
|
}); |
|
|
|
|
this.form_field_jq.bind("liszt:activate", function(evt) { |
|
|
|
|
return _this.activate_field(evt); |
|
|
|
|
}); |
|
|
|
|
this.form_field_jq.bind("liszt:open", function(evt) { |
|
|
|
|
return _this.container_mousedown(evt); |
|
|
|
|
}); |
|
|
|
|
this.search_field.blur(function(evt) { |
|
|
|
|
return _this.input_blur(evt); |
|
|
|
|
}); |
|
|
|
@ -394,13 +441,13 @@ Copyright (c) 2011 by Harvest |
|
|
|
|
this.search_field.keydown(function(evt) { |
|
|
|
|
return _this.keydown_checker(evt); |
|
|
|
|
}); |
|
|
|
|
this.search_field.focus(function(evt) { |
|
|
|
|
return _this.input_focus(evt); |
|
|
|
|
}); |
|
|
|
|
if (this.is_multiple) { |
|
|
|
|
this.search_choices.click(function(evt) { |
|
|
|
|
return this.search_choices.click(function(evt) { |
|
|
|
|
return _this.choices_click(evt); |
|
|
|
|
}); |
|
|
|
|
return this.search_field.focus(function(evt) { |
|
|
|
|
return _this.input_focus(evt); |
|
|
|
|
}); |
|
|
|
|
} else { |
|
|
|
|
return this.container.click(function(evt) { |
|
|
|
|
return evt.preventDefault(); |
|
|
|
@ -431,11 +478,13 @@ Copyright (c) 2011 by Harvest |
|
|
|
|
if (!this.is_disabled) { |
|
|
|
|
target_closelink = evt != null ? ($(evt.target)).hasClass("search-choice-close") : false; |
|
|
|
|
if (evt && evt.type === "mousedown" && !this.results_showing) { |
|
|
|
|
evt.stopPropagation(); |
|
|
|
|
evt.preventDefault(); |
|
|
|
|
} |
|
|
|
|
if (!this.pending_destroy_click && !target_closelink) { |
|
|
|
|
if (!this.active_field) { |
|
|
|
|
if (this.is_multiple) this.search_field.val(""); |
|
|
|
|
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)[0] === this.selected_item[0]) || $(evt.target).parents("a.chzn-single").length)) { |
|
|
|
@ -463,10 +512,6 @@ Copyright (c) 2011 by Harvest |
|
|
|
|
|
|
|
|
|
Chosen.prototype.close_field = function() { |
|
|
|
|
$(document).unbind("click", this.click_test_action); |
|
|
|
|
if (!this.is_multiple) { |
|
|
|
|
this.selected_item.attr("tabindex", this.search_field.attr("tabindex")); |
|
|
|
|
this.search_field.attr("tabindex", -1); |
|
|
|
|
} |
|
|
|
|
this.active_field = false; |
|
|
|
|
this.results_hide(); |
|
|
|
|
this.container.removeClass("chzn-container-active"); |
|
|
|
@ -477,10 +522,6 @@ Copyright (c) 2011 by Harvest |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
Chosen.prototype.activate_field = function() { |
|
|
|
|
if (!this.is_multiple && !this.active_field) { |
|
|
|
|
this.search_field.attr("tabindex", this.selected_item.attr("tabindex")); |
|
|
|
|
this.selected_item.attr("tabindex", -1); |
|
|
|
|
} |
|
|
|
|
this.container.addClass("chzn-container-active"); |
|
|
|
|
this.active_field = true; |
|
|
|
|
this.search_field.val(this.search_field.val()); |
|
|
|
@ -504,7 +545,7 @@ Copyright (c) 2011 by Harvest |
|
|
|
|
this.choices = 0; |
|
|
|
|
} else if (!this.is_multiple) { |
|
|
|
|
this.selected_item.addClass("chzn-default").find("span").text(this.default_text); |
|
|
|
|
if (this.form_field.options.length <= this.disable_search_threshold) { |
|
|
|
|
if (this.disable_search || this.form_field.options.length <= this.disable_search_threshold) { |
|
|
|
|
this.container.addClass("chzn-container-single-nosearch"); |
|
|
|
|
} else { |
|
|
|
|
this.container.removeClass("chzn-container-single-nosearch"); |
|
|
|
@ -522,7 +563,9 @@ Copyright (c) 2011 by Harvest |
|
|
|
|
this.choice_build(data); |
|
|
|
|
} else if (data.selected && !this.is_multiple) { |
|
|
|
|
this.selected_item.removeClass("chzn-default").find("span").text(data.text); |
|
|
|
|
if (this.allow_single_deselect) this.single_deselect_control_build(); |
|
|
|
|
if (this.allow_single_deselect) { |
|
|
|
|
this.single_deselect_control_build(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -562,7 +605,9 @@ Copyright (c) 2011 by Harvest |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
Chosen.prototype.result_clear_highlight = function() { |
|
|
|
|
if (this.result_highlight) this.result_highlight.removeClass("highlighted"); |
|
|
|
|
if (this.result_highlight) { |
|
|
|
|
this.result_highlight.removeClass("highlighted"); |
|
|
|
|
} |
|
|
|
|
return this.result_highlight = null; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
@ -612,12 +657,7 @@ Copyright (c) 2011 by Harvest |
|
|
|
|
if (this.form_field_jq.attr("tabindex")) { |
|
|
|
|
ti = this.form_field_jq.attr("tabindex"); |
|
|
|
|
this.form_field_jq.attr("tabindex", -1); |
|
|
|
|
if (this.is_multiple) { |
|
|
|
|
return this.search_field.attr("tabindex", ti); |
|
|
|
|
} else { |
|
|
|
|
this.selected_item.attr("tabindex", ti); |
|
|
|
|
return this.search_field.attr("tabindex", -1); |
|
|
|
|
} |
|
|
|
|
return this.search_field.attr("tabindex", ti); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
@ -636,14 +676,17 @@ Copyright (c) 2011 by Harvest |
|
|
|
|
target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first(); |
|
|
|
|
if (target.length) { |
|
|
|
|
this.result_highlight = target; |
|
|
|
|
return this.result_select(evt); |
|
|
|
|
this.result_select(evt); |
|
|
|
|
return this.search_field.focus(); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
Chosen.prototype.search_results_mouseover = function(evt) { |
|
|
|
|
var target; |
|
|
|
|
target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first(); |
|
|
|
|
if (target) return this.result_do_highlight(target); |
|
|
|
|
if (target) { |
|
|
|
|
return this.result_do_highlight(target); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
Chosen.prototype.search_results_mouseout = function(evt) { |
|
|
|
@ -660,7 +703,7 @@ Copyright (c) 2011 by Harvest |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
Chosen.prototype.choice_build = function(item) { |
|
|
|
|
var choice_id, link, |
|
|
|
|
var choice_id, html, link, |
|
|
|
|
_this = this; |
|
|
|
|
if (this.is_multiple && this.max_selected_options <= this.choices) { |
|
|
|
|
this.form_field_jq.trigger("liszt:maxselected", { |
|
|
|
@ -670,7 +713,12 @@ Copyright (c) 2011 by Harvest |
|
|
|
|
} |
|
|
|
|
choice_id = this.container_id + "_c_" + item.array_index; |
|
|
|
|
this.choices += 1; |
|
|
|
|
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>'); |
|
|
|
|
if (item.disabled) { |
|
|
|
|
html = '<li class="search-choice search-choice-disabled" id="' + choice_id + '"><span>' + item.html + '</span></li>'; |
|
|
|
|
} else { |
|
|
|
|
html = '<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>'; |
|
|
|
|
} |
|
|
|
|
this.search_container.before(html); |
|
|
|
|
link = $('#' + choice_id).find("a").first(); |
|
|
|
|
return link.click(function(evt) { |
|
|
|
|
return _this.choice_destroy_link_click(evt); |
|
|
|
@ -688,26 +736,33 @@ Copyright (c) 2011 by Harvest |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
Chosen.prototype.choice_destroy = function(link) { |
|
|
|
|
this.choices -= 1; |
|
|
|
|
this.show_search_field_default(); |
|
|
|
|
if (this.is_multiple && this.choices > 0 && this.search_field.val().length < 1) { |
|
|
|
|
this.results_hide(); |
|
|
|
|
if (this.result_deselect(link.attr("rel"))) { |
|
|
|
|
this.choices -= 1; |
|
|
|
|
this.show_search_field_default(); |
|
|
|
|
if (this.is_multiple && this.choices > 0 && this.search_field.val().length < 1) { |
|
|
|
|
this.results_hide(); |
|
|
|
|
} |
|
|
|
|
link.parents('li').first().remove(); |
|
|
|
|
return this.search_field_scale(); |
|
|
|
|
} |
|
|
|
|
this.result_deselect(link.attr("rel")); |
|
|
|
|
return link.parents('li').first().remove(); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
Chosen.prototype.results_reset = function() { |
|
|
|
|
this.form_field.options[0].selected = true; |
|
|
|
|
this.selected_item.find("span").text(this.default_text); |
|
|
|
|
if (!this.is_multiple) this.selected_item.addClass("chzn-default"); |
|
|
|
|
if (!this.is_multiple) { |
|
|
|
|
this.selected_item.addClass("chzn-default"); |
|
|
|
|
} |
|
|
|
|
this.show_search_field_default(); |
|
|
|
|
this.results_reset_cleanup(); |
|
|
|
|
this.form_field_jq.trigger("change"); |
|
|
|
|
if (this.active_field) return this.results_hide(); |
|
|
|
|
if (this.active_field) { |
|
|
|
|
return this.results_hide(); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
Chosen.prototype.results_reset_cleanup = function() { |
|
|
|
|
this.current_value = this.form_field_jq.val(); |
|
|
|
|
return this.selected_item.find("abbr").remove(); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
@ -733,9 +788,13 @@ Copyright (c) 2011 by Harvest |
|
|
|
|
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 (this.allow_single_deselect) { |
|
|
|
|
this.single_deselect_control_build(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (!((evt.metaKey || evt.ctrlKey) && this.is_multiple)) { |
|
|
|
|
this.results_hide(); |
|
|
|
|
} |
|
|
|
|
if (!(evt.metaKey && this.is_multiple)) this.results_hide(); |
|
|
|
|
this.search_field.val(""); |
|
|
|
|
if (this.is_multiple || this.form_field_jq.val() !== this.current_value) { |
|
|
|
|
this.form_field_jq.trigger("change", { |
|
|
|
@ -758,16 +817,21 @@ Copyright (c) 2011 by Harvest |
|
|
|
|
Chosen.prototype.result_deselect = function(pos) { |
|
|
|
|
var result, result_data; |
|
|
|
|
result_data = this.results_data[pos]; |
|
|
|
|
result_data.selected = false; |
|
|
|
|
this.form_field.options[result_data.options_index].selected = false; |
|
|
|
|
result = $("#" + this.container_id + "_o_" + pos); |
|
|
|
|
result.removeClass("result-selected").addClass("active-result").show(); |
|
|
|
|
this.result_clear_highlight(); |
|
|
|
|
this.winnow_results(); |
|
|
|
|
this.form_field_jq.trigger("change", { |
|
|
|
|
deselected: this.form_field.options[result_data.options_index].value |
|
|
|
|
}); |
|
|
|
|
return this.search_field_scale(); |
|
|
|
|
if (!this.form_field.options[result_data.options_index].disabled) { |
|
|
|
|
result_data.selected = false; |
|
|
|
|
this.form_field.options[result_data.options_index].selected = false; |
|
|
|
|
result = $("#" + this.container_id + "_o_" + pos); |
|
|
|
|
result.removeClass("result-selected").addClass("active-result").show(); |
|
|
|
|
this.result_clear_highlight(); |
|
|
|
|
this.winnow_results(); |
|
|
|
|
this.form_field_jq.trigger("change", { |
|
|
|
|
deselected: this.form_field.options[result_data.options_index].value |
|
|
|
|
}); |
|
|
|
|
this.search_field_scale(); |
|
|
|
|
return true; |
|
|
|
|
} else { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
Chosen.prototype.single_deselect_control_build = function() { |
|
|
|
@ -777,7 +841,7 @@ Copyright (c) 2011 by Harvest |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
Chosen.prototype.winnow_results = function() { |
|
|
|
|
var found, option, part, parts, regex, regexAnchor, result, result_id, results, searchText, startpos, text, zregex, _i, _j, _len, _len2, _ref; |
|
|
|
|
var found, option, part, parts, regex, regexAnchor, result, result_id, results, searchText, startpos, text, zregex, _i, _j, _len, _len1, _ref; |
|
|
|
|
this.no_results_clear(); |
|
|
|
|
results = 0; |
|
|
|
|
searchText = this.search_field.val() === this.default_text ? "" : $('<div/>').text($.trim(this.search_field.val())).html(); |
|
|
|
@ -797,10 +861,10 @@ Copyright (c) 2011 by Harvest |
|
|
|
|
if (regex.test(option.html)) { |
|
|
|
|
found = true; |
|
|
|
|
results += 1; |
|
|
|
|
} else if (option.html.indexOf(" ") >= 0 || option.html.indexOf("[") === 0) { |
|
|
|
|
} else if (this.enable_split_word_search && (option.html.indexOf(" ") >= 0 || option.html.indexOf("[") === 0)) { |
|
|
|
|
parts = option.html.replace(/\[|\]/g, "").split(" "); |
|
|
|
|
if (parts.length) { |
|
|
|
|
for (_j = 0, _len2 = parts.length; _j < _len2; _j++) { |
|
|
|
|
for (_j = 0, _len1 = parts.length; _j < _len1; _j++) { |
|
|
|
|
part = parts[_j]; |
|
|
|
|
if (regex.test(part)) { |
|
|
|
|
found = true; |
|
|
|
@ -862,7 +926,9 @@ Copyright (c) 2011 by Harvest |
|
|
|
|
if (!this.result_highlight) { |
|
|
|
|
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); |
|
|
|
|
if (do_high != null) { |
|
|
|
|
return this.result_do_highlight(do_high); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
@ -881,12 +947,18 @@ Copyright (c) 2011 by Harvest |
|
|
|
|
var first_active, next_sib; |
|
|
|
|
if (!this.result_highlight) { |
|
|
|
|
first_active = this.search_results.find("li.active-result").first(); |
|
|
|
|
if (first_active) this.result_do_highlight($(first_active)); |
|
|
|
|
if (first_active) { |
|
|
|
|
this.result_do_highlight($(first_active)); |
|
|
|
|
} |
|
|
|
|
} else if (this.results_showing) { |
|
|
|
|
next_sib = this.result_highlight.nextAll("li.active-result").first(); |
|
|
|
|
if (next_sib) this.result_do_highlight(next_sib); |
|
|
|
|
if (next_sib) { |
|
|
|
|
this.result_do_highlight(next_sib); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (!this.results_showing) { |
|
|
|
|
return this.results_show(); |
|
|
|
|
} |
|
|
|
|
if (!this.results_showing) return this.results_show(); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
Chosen.prototype.keyup_arrow = function() { |
|
|
|
@ -898,22 +970,28 @@ Copyright (c) 2011 by Harvest |
|
|
|
|
if (prev_sibs.length) { |
|
|
|
|
return this.result_do_highlight(prev_sibs.first()); |
|
|
|
|
} else { |
|
|
|
|
if (this.choices > 0) this.results_hide(); |
|
|
|
|
if (this.choices > 0) { |
|
|
|
|
this.results_hide(); |
|
|
|
|
} |
|
|
|
|
return this.result_clear_highlight(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
Chosen.prototype.keydown_backstroke = function() { |
|
|
|
|
var next_available_destroy; |
|
|
|
|
if (this.pending_backstroke) { |
|
|
|
|
this.choice_destroy(this.pending_backstroke.find("a").first()); |
|
|
|
|
return this.clear_backstroke(); |
|
|
|
|
} else { |
|
|
|
|
this.pending_backstroke = this.search_container.siblings("li.search-choice").last(); |
|
|
|
|
if (this.single_backstroke_delete) { |
|
|
|
|
return this.keydown_backstroke(); |
|
|
|
|
} else { |
|
|
|
|
return this.pending_backstroke.addClass("search-choice-focus"); |
|
|
|
|
next_available_destroy = this.search_container.siblings("li.search-choice").last(); |
|
|
|
|
if (next_available_destroy.length && !next_available_destroy.hasClass("search-choice-disabled")) { |
|
|
|
|
this.pending_backstroke = next_available_destroy; |
|
|
|
|
if (this.single_backstroke_delete) { |
|
|
|
|
return this.keydown_backstroke(); |
|
|
|
|
} else { |
|
|
|
|
return this.pending_backstroke.addClass("search-choice-focus"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
@ -929,13 +1007,17 @@ Copyright (c) 2011 by Harvest |
|
|
|
|
var stroke, _ref; |
|
|
|
|
stroke = (_ref = evt.which) != null ? _ref : evt.keyCode; |
|
|
|
|
this.search_field_scale(); |
|
|
|
|
if (stroke !== 8 && this.pending_backstroke) this.clear_backstroke(); |
|
|
|
|
if (stroke !== 8 && this.pending_backstroke) { |
|
|
|
|
this.clear_backstroke(); |
|
|
|
|
} |
|
|
|
|
switch (stroke) { |
|
|
|
|
case 8: |
|
|
|
|
this.backstroke_length = this.search_field.val().length; |
|
|
|
|
break; |
|
|
|
|
case 9: |
|
|
|
|
if (this.results_showing && !this.is_multiple) this.result_select(evt); |
|
|
|
|
if (this.results_showing && !this.is_multiple) { |
|
|
|
|
this.result_select(evt); |
|
|
|
|
} |
|
|
|
|
this.mouse_on_container = false; |
|
|
|
|
break; |
|
|
|
|
case 13: |
|
|
|
@ -969,7 +1051,9 @@ Copyright (c) 2011 by Harvest |
|
|
|
|
$('body').append(div); |
|
|
|
|
w = div.width() + 25; |
|
|
|
|
div.remove(); |
|
|
|
|
if (w > this.f_width - 10) w = this.f_width - 10; |
|
|
|
|
if (w > this.f_width - 10) { |
|
|
|
|
w = this.f_width - 10; |
|
|
|
|
} |
|
|
|
|
this.search_field.css({ |
|
|
|
|
'width': w + 'px' |
|
|
|
|
}); |
|
|
|
@ -993,6 +1077,8 @@ Copyright (c) 2011 by Harvest |
|
|
|
|
|
|
|
|
|
})(AbstractChosen); |
|
|
|
|
|
|
|
|
|
root.Chosen = Chosen; |
|
|
|
|
|
|
|
|
|
get_side_border_padding = function(elmt) { |
|
|
|
|
var side_border_padding; |
|
|
|
|
return side_border_padding = elmt.outerWidth() - elmt.width(); |
|
|
|
@ -1000,4 +1086,4 @@ Copyright (c) 2011 by Harvest |
|
|
|
|
|
|
|
|
|
root.get_side_border_padding = get_side_border_padding; |
|
|
|
|
|
|
|
|
|
}).call(this); |
|
|
|
|
}).call(this); |