|
|
|
@ -1,14 +1,16 @@ |
|
|
|
|
// Chosen, a Select Box Enhancer for jQuery and Prototype
|
|
|
|
|
// by Patrick Filler for Harvest, http://getharvest.com
|
|
|
|
|
//
|
|
|
|
|
// Version 0.12.1
|
|
|
|
|
// Version 1.0.0
|
|
|
|
|
// 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 `grunt build`, do not edit it by hand.
|
|
|
|
|
(function() { |
|
|
|
|
var SelectParser; |
|
|
|
|
var $, AbstractChosen, Chosen, SelectParser, _ref, |
|
|
|
|
__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; }; |
|
|
|
|
|
|
|
|
|
SelectParser = (function() { |
|
|
|
|
function SelectParser() { |
|
|
|
@ -31,7 +33,7 @@ |
|
|
|
|
this.parsed.push({ |
|
|
|
|
array_index: group_position, |
|
|
|
|
group: true, |
|
|
|
|
label: group.label, |
|
|
|
|
label: this.escapeExpression(group.label), |
|
|
|
|
children: 0, |
|
|
|
|
disabled: group.disabled |
|
|
|
|
}); |
|
|
|
@ -73,6 +75,28 @@ |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
SelectParser.prototype.escapeExpression = function(text) { |
|
|
|
|
var map, unsafe_chars; |
|
|
|
|
|
|
|
|
|
if ((text == null) || text === false) { |
|
|
|
|
return ""; |
|
|
|
|
} |
|
|
|
|
if (!/[\&\<\>\"\'\`]/.test(text)) { |
|
|
|
|
return text; |
|
|
|
|
} |
|
|
|
|
map = { |
|
|
|
|
"<": "<", |
|
|
|
|
">": ">", |
|
|
|
|
'"': """, |
|
|
|
|
"'": "'", |
|
|
|
|
"`": "`" |
|
|
|
|
}; |
|
|
|
|
unsafe_chars = /&(?!\w+;)|[\<\>\"\'\`]/g; |
|
|
|
|
return text.replace(unsafe_chars, function(chr) { |
|
|
|
|
return map[chr] || "&"; |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
return SelectParser; |
|
|
|
|
|
|
|
|
|
})(); |
|
|
|
@ -89,15 +113,6 @@ |
|
|
|
|
return parser.parsed; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
this.SelectParser = SelectParser; |
|
|
|
|
|
|
|
|
|
}).call(this); |
|
|
|
|
|
|
|
|
|
(function() { |
|
|
|
|
var AbstractChosen, root; |
|
|
|
|
|
|
|
|
|
root = this; |
|
|
|
|
|
|
|
|
|
AbstractChosen = (function() { |
|
|
|
|
function AbstractChosen(form_field, options) { |
|
|
|
|
this.form_field = form_field; |
|
|
|
@ -111,7 +126,6 @@ |
|
|
|
|
this.setup(); |
|
|
|
|
this.set_up_html(); |
|
|
|
|
this.register_observers(); |
|
|
|
|
this.finish_setup(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
AbstractChosen.prototype.set_default_values = function() { |
|
|
|
@ -132,10 +146,13 @@ |
|
|
|
|
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.group_search = this.options.group_search != null ? this.options.group_search : true; |
|
|
|
|
this.search_contains = this.options.search_contains || false; |
|
|
|
|
this.single_backstroke_delete = this.options.single_backstroke_delete || false; |
|
|
|
|
this.single_backstroke_delete = this.options.single_backstroke_delete != null ? this.options.single_backstroke_delete : true; |
|
|
|
|
this.max_selected_options = this.options.max_selected_options || Infinity; |
|
|
|
|
return this.inherit_select_classes = this.options.inherit_select_classes || false; |
|
|
|
|
this.inherit_select_classes = this.options.inherit_select_classes || false; |
|
|
|
|
this.display_selected_options = this.options.display_selected_options != null ? this.options.display_selected_options : true; |
|
|
|
|
return this.display_disabled_options = this.options.display_disabled_options != null ? this.options.display_disabled_options : true; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
AbstractChosen.prototype.set_default_text = function() { |
|
|
|
@ -191,9 +208,9 @@ |
|
|
|
|
_ref = this.results_data; |
|
|
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) { |
|
|
|
|
data = _ref[_i]; |
|
|
|
|
if (data.group && data.search_match) { |
|
|
|
|
if (data.group) { |
|
|
|
|
content += this.result_add_group(data); |
|
|
|
|
} else if (!data.empty && data.search_match) { |
|
|
|
|
} else { |
|
|
|
|
content += this.result_add_option(data); |
|
|
|
|
} |
|
|
|
|
if (options != null ? options.first : void 0) { |
|
|
|
@ -210,7 +227,12 @@ |
|
|
|
|
AbstractChosen.prototype.result_add_option = function(option) { |
|
|
|
|
var classes, style; |
|
|
|
|
|
|
|
|
|
option.dom_id = this.container_id + "_o_" + option.array_index; |
|
|
|
|
if (!option.search_match) { |
|
|
|
|
return ''; |
|
|
|
|
} |
|
|
|
|
if (!this.include_option_in_results(option)) { |
|
|
|
|
return ''; |
|
|
|
|
} |
|
|
|
|
classes = []; |
|
|
|
|
if (!option.disabled && !(option.selected && this.is_multiple)) { |
|
|
|
|
classes.push("active-result"); |
|
|
|
@ -228,7 +250,17 @@ |
|
|
|
|
classes.push(option.classes); |
|
|
|
|
} |
|
|
|
|
style = option.style.cssText !== "" ? " style=\"" + option.style + "\"" : ""; |
|
|
|
|
return "<li id=\"" + option.dom_id + "\" class=\"" + (classes.join(' ')) + "\"" + style + ">" + option.search_text + "</li>"; |
|
|
|
|
return "<li class=\"" + (classes.join(' ')) + "\"" + style + " data-option-array-index=\"" + option.array_index + "\">" + option.search_text + "</li>"; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
AbstractChosen.prototype.result_add_group = function(group) { |
|
|
|
|
if (!(group.search_match || group.group_match)) { |
|
|
|
|
return ''; |
|
|
|
|
} |
|
|
|
|
if (!(group.active_options > 0)) { |
|
|
|
|
return ''; |
|
|
|
|
} |
|
|
|
|
return "<li class=\"group-result\">" + group.search_text + "</li>"; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
AbstractChosen.prototype.results_update_field = function() { |
|
|
|
@ -238,7 +270,10 @@ |
|
|
|
|
} |
|
|
|
|
this.result_clear_highlight(); |
|
|
|
|
this.result_single_selected = null; |
|
|
|
|
return this.results_build(); |
|
|
|
|
this.results_build(); |
|
|
|
|
if (this.results_showing) { |
|
|
|
|
return this.winnow_results(); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
AbstractChosen.prototype.results_toggle = function() { |
|
|
|
@ -258,53 +293,54 @@ |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
AbstractChosen.prototype.winnow_results = function() { |
|
|
|
|
var option, part, parts, regex, regexAnchor, results, searchText, startpos, text, zregex, _i, _j, _len, _len1, _ref; |
|
|
|
|
var escapedSearchText, option, regex, regexAnchor, results, results_group, searchText, startpos, text, zregex, _i, _len, _ref; |
|
|
|
|
|
|
|
|
|
this.no_results_clear(); |
|
|
|
|
results = 0; |
|
|
|
|
searchText = this.get_search_text(); |
|
|
|
|
escapedSearchText = searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"); |
|
|
|
|
regexAnchor = this.search_contains ? "" : "^"; |
|
|
|
|
regex = new RegExp(regexAnchor + searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i'); |
|
|
|
|
zregex = new RegExp(searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i'); |
|
|
|
|
regex = new RegExp(regexAnchor + escapedSearchText, 'i'); |
|
|
|
|
zregex = new RegExp(escapedSearchText, 'i'); |
|
|
|
|
_ref = this.results_data; |
|
|
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) { |
|
|
|
|
option = _ref[_i]; |
|
|
|
|
if (!option.empty) { |
|
|
|
|
option.search_match = false; |
|
|
|
|
results_group = null; |
|
|
|
|
if (this.include_option_in_results(option)) { |
|
|
|
|
if (option.group) { |
|
|
|
|
option.search_match = false; |
|
|
|
|
} else { |
|
|
|
|
option.search_match = false; |
|
|
|
|
if (regex.test(option.html)) { |
|
|
|
|
option.search_match = true; |
|
|
|
|
option.group_match = false; |
|
|
|
|
option.active_options = 0; |
|
|
|
|
} |
|
|
|
|
if ((option.group_array_index != null) && this.results_data[option.group_array_index]) { |
|
|
|
|
results_group = this.results_data[option.group_array_index]; |
|
|
|
|
if (results_group.active_options === 0 && results_group.search_match) { |
|
|
|
|
results += 1; |
|
|
|
|
} |
|
|
|
|
results_group.active_options += 1; |
|
|
|
|
} |
|
|
|
|
if (!(option.group && !this.group_search)) { |
|
|
|
|
option.search_text = option.group ? option.label : option.html; |
|
|
|
|
option.search_match = this.search_string_match(option.search_text, regex); |
|
|
|
|
if (option.search_match && !option.group) { |
|
|
|
|
results += 1; |
|
|
|
|
} 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, _len1 = parts.length; _j < _len1; _j++) { |
|
|
|
|
part = parts[_j]; |
|
|
|
|
if (regex.test(part)) { |
|
|
|
|
option.search_match = true; |
|
|
|
|
results += 1; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (option.search_match) { |
|
|
|
|
if (searchText.length) { |
|
|
|
|
startpos = option.html.search(zregex); |
|
|
|
|
text = option.html.substr(0, startpos + searchText.length) + '</em>' + option.html.substr(startpos + searchText.length); |
|
|
|
|
text = text.substr(0, startpos) + '<em>' + text.substr(startpos); |
|
|
|
|
} else { |
|
|
|
|
text = option.html; |
|
|
|
|
startpos = option.search_text.search(zregex); |
|
|
|
|
text = option.search_text.substr(0, startpos + searchText.length) + '</em>' + option.search_text.substr(startpos + searchText.length); |
|
|
|
|
option.search_text = text.substr(0, startpos) + '<em>' + text.substr(startpos); |
|
|
|
|
} |
|
|
|
|
option.search_text = text; |
|
|
|
|
if (option.group_array_index != null) { |
|
|
|
|
this.results_data[option.group_array_index].search_match = true; |
|
|
|
|
if (results_group != null) { |
|
|
|
|
results_group.group_match = true; |
|
|
|
|
} |
|
|
|
|
} else if ((option.group_array_index != null) && this.results_data[option.group_array_index].search_match) { |
|
|
|
|
option.search_match = true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
this.result_clear_highlight(); |
|
|
|
|
if (results < 1 && searchText.length) { |
|
|
|
|
this.update_results_content(""); |
|
|
|
|
return this.no_results(searchText); |
|
|
|
@ -314,6 +350,24 @@ |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
AbstractChosen.prototype.search_string_match = function(search_string, regex) { |
|
|
|
|
var part, parts, _i, _len; |
|
|
|
|
|
|
|
|
|
if (regex.test(search_string)) { |
|
|
|
|
return true; |
|
|
|
|
} else if (this.enable_split_word_search && (search_string.indexOf(" ") >= 0 || search_string.indexOf("[") === 0)) { |
|
|
|
|
parts = search_string.replace(/\[|\]/g, "").split(" "); |
|
|
|
|
if (parts.length) { |
|
|
|
|
for (_i = 0, _len = parts.length; _i < _len; _i++) { |
|
|
|
|
part = parts[_i]; |
|
|
|
|
if (regex.test(part)) { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
AbstractChosen.prototype.choices_count = function() { |
|
|
|
|
var option, _i, _len, _ref; |
|
|
|
|
|
|
|
|
@ -375,22 +429,6 @@ |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
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 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; |
|
|
|
|
rand = Math.floor(Math.random() * chars.length); |
|
|
|
|
return newchar = chars.substring(rand, rand + 1); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
AbstractChosen.prototype.container_width = function() { |
|
|
|
|
if (this.options.width != null) { |
|
|
|
|
return this.options.width; |
|
|
|
@ -399,11 +437,30 @@ |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
AbstractChosen.browser_is_supported = function() { |
|
|
|
|
var _ref; |
|
|
|
|
AbstractChosen.prototype.include_option_in_results = function(option) { |
|
|
|
|
if (this.is_multiple && (!this.display_selected_options && option.selected)) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
if (!this.display_disabled_options && option.disabled) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
if (option.empty) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
AbstractChosen.browser_is_supported = function() { |
|
|
|
|
if (window.navigator.appName === "Microsoft Internet Explorer") { |
|
|
|
|
return (null !== (_ref = document.documentMode) && _ref >= 8); |
|
|
|
|
return document.documentMode >= 8; |
|
|
|
|
} |
|
|
|
|
if (/iP(od|hone)/i.test(window.navigator.userAgent)) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
if (/Android/i.test(window.navigator.userAgent)) { |
|
|
|
|
if (/Mobile/i.test(window.navigator.userAgent)) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
}; |
|
|
|
@ -418,17 +475,6 @@ |
|
|
|
|
|
|
|
|
|
})(); |
|
|
|
|
|
|
|
|
|
root.AbstractChosen = AbstractChosen; |
|
|
|
|
|
|
|
|
|
}).call(this); |
|
|
|
|
|
|
|
|
|
(function() { |
|
|
|
|
var $, Chosen, root, _ref, |
|
|
|
|
__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; |
|
|
|
|
|
|
|
|
|
$ = jQuery; |
|
|
|
|
|
|
|
|
|
$.fn.extend({ |
|
|
|
@ -437,11 +483,14 @@ |
|
|
|
|
return this; |
|
|
|
|
} |
|
|
|
|
return this.each(function(input_field) { |
|
|
|
|
var $this; |
|
|
|
|
var $this, chosen; |
|
|
|
|
|
|
|
|
|
$this = $(this); |
|
|
|
|
if (!$this.hasClass("chzn-done")) { |
|
|
|
|
return $this.data('chosen', new Chosen(this, options)); |
|
|
|
|
chosen = $this.data('chosen'); |
|
|
|
|
if (options === 'destroy' && chosen) { |
|
|
|
|
chosen.destroy(); |
|
|
|
|
} else if (!chosen) { |
|
|
|
|
$this.data('chosen', new Chosen(this, options)); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
@ -458,55 +507,51 @@ |
|
|
|
|
Chosen.prototype.setup = function() { |
|
|
|
|
this.form_field_jq = $(this.form_field); |
|
|
|
|
this.current_selectedIndex = this.form_field.selectedIndex; |
|
|
|
|
return this.is_rtl = this.form_field_jq.hasClass("chzn-rtl"); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
Chosen.prototype.finish_setup = function() { |
|
|
|
|
return this.form_field_jq.addClass("chzn-done"); |
|
|
|
|
return this.is_rtl = this.form_field_jq.hasClass("chosen-rtl"); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
Chosen.prototype.set_up_html = function() { |
|
|
|
|
var container_classes, container_props; |
|
|
|
|
|
|
|
|
|
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")); |
|
|
|
|
container_classes = ["chosen-container"]; |
|
|
|
|
container_classes.push("chosen-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"); |
|
|
|
|
container_classes.push("chosen-rtl"); |
|
|
|
|
} |
|
|
|
|
container_props = { |
|
|
|
|
'id': this.container_id, |
|
|
|
|
'class': container_classes.join(' '), |
|
|
|
|
'style': "width: " + (this.container_width()) + ";", |
|
|
|
|
'title': this.form_field.title |
|
|
|
|
}; |
|
|
|
|
if (this.form_field.id.length) { |
|
|
|
|
container_props.id = this.form_field.id.replace(/[^\w]/g, '_') + "_chosen"; |
|
|
|
|
} |
|
|
|
|
this.container = $("<div />", container_props); |
|
|
|
|
if (this.is_multiple) { |
|
|
|
|
this.container.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"><ul class="chzn-results"></ul></div>'); |
|
|
|
|
this.container.html('<ul class="chosen-choices"><li class="search-field"><input type="text" value="' + this.default_text + '" class="default" autocomplete="off" style="width:25px;" /></li></ul><div class="chosen-drop"><ul class="chosen-results"></ul></div>'); |
|
|
|
|
} else { |
|
|
|
|
this.container.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"><div class="chzn-search"><input type="text" autocomplete="off" /></div><ul class="chzn-results"></ul></div>'); |
|
|
|
|
this.container.html('<a class="chosen-single chosen-default" tabindex="-1"><span>' + this.default_text + '</span><div><b></b></div></a><div class="chosen-drop"><div class="chosen-search"><input type="text" autocomplete="off" /></div><ul class="chosen-results"></ul></div>'); |
|
|
|
|
} |
|
|
|
|
this.form_field_jq.hide().after(this.container); |
|
|
|
|
this.dropdown = this.container.find('div.chzn-drop').first(); |
|
|
|
|
this.dropdown = this.container.find('div.chosen-drop').first(); |
|
|
|
|
this.search_field = this.container.find('input').first(); |
|
|
|
|
this.search_results = this.container.find('ul.chzn-results').first(); |
|
|
|
|
this.search_results = this.container.find('ul.chosen-results').first(); |
|
|
|
|
this.search_field_scale(); |
|
|
|
|
this.search_no_results = this.container.find('li.no-results').first(); |
|
|
|
|
if (this.is_multiple) { |
|
|
|
|
this.search_choices = this.container.find('ul.chzn-choices').first(); |
|
|
|
|
this.search_choices = this.container.find('ul.chosen-choices').first(); |
|
|
|
|
this.search_container = this.container.find('li.search-field').first(); |
|
|
|
|
} else { |
|
|
|
|
this.search_container = this.container.find('div.chzn-search').first(); |
|
|
|
|
this.selected_item = this.container.find('.chzn-single').first(); |
|
|
|
|
this.search_container = this.container.find('div.chosen-search').first(); |
|
|
|
|
this.selected_item = this.container.find('.chosen-single').first(); |
|
|
|
|
} |
|
|
|
|
this.results_build(); |
|
|
|
|
this.set_tab_index(); |
|
|
|
|
this.set_label_behavior(); |
|
|
|
|
return this.form_field_jq.trigger("liszt:ready", { |
|
|
|
|
return this.form_field_jq.trigger("chosen:ready", { |
|
|
|
|
chosen: this |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
@ -514,76 +559,86 @@ |
|
|
|
|
Chosen.prototype.register_observers = function() { |
|
|
|
|
var _this = this; |
|
|
|
|
|
|
|
|
|
this.container.mousedown(function(evt) { |
|
|
|
|
this.container.bind('mousedown.chosen', function(evt) { |
|
|
|
|
_this.container_mousedown(evt); |
|
|
|
|
}); |
|
|
|
|
this.container.mouseup(function(evt) { |
|
|
|
|
this.container.bind('mouseup.chosen', function(evt) { |
|
|
|
|
_this.container_mouseup(evt); |
|
|
|
|
}); |
|
|
|
|
this.container.mouseenter(function(evt) { |
|
|
|
|
this.container.bind('mouseenter.chosen', function(evt) { |
|
|
|
|
_this.mouse_enter(evt); |
|
|
|
|
}); |
|
|
|
|
this.container.mouseleave(function(evt) { |
|
|
|
|
this.container.bind('mouseleave.chosen', function(evt) { |
|
|
|
|
_this.mouse_leave(evt); |
|
|
|
|
}); |
|
|
|
|
this.search_results.mouseup(function(evt) { |
|
|
|
|
this.search_results.bind('mouseup.chosen', function(evt) { |
|
|
|
|
_this.search_results_mouseup(evt); |
|
|
|
|
}); |
|
|
|
|
this.search_results.mouseover(function(evt) { |
|
|
|
|
this.search_results.bind('mouseover.chosen', function(evt) { |
|
|
|
|
_this.search_results_mouseover(evt); |
|
|
|
|
}); |
|
|
|
|
this.search_results.mouseout(function(evt) { |
|
|
|
|
this.search_results.bind('mouseout.chosen', function(evt) { |
|
|
|
|
_this.search_results_mouseout(evt); |
|
|
|
|
}); |
|
|
|
|
this.search_results.bind('mousewheel DOMMouseScroll', function(evt) { |
|
|
|
|
this.search_results.bind('mousewheel.chosen DOMMouseScroll.chosen', function(evt) { |
|
|
|
|
_this.search_results_mousewheel(evt); |
|
|
|
|
}); |
|
|
|
|
this.form_field_jq.bind("liszt:updated", function(evt) { |
|
|
|
|
this.form_field_jq.bind("chosen:updated.chosen", function(evt) { |
|
|
|
|
_this.results_update_field(evt); |
|
|
|
|
}); |
|
|
|
|
this.form_field_jq.bind("liszt:activate", function(evt) { |
|
|
|
|
this.form_field_jq.bind("chosen:activate.chosen", function(evt) { |
|
|
|
|
_this.activate_field(evt); |
|
|
|
|
}); |
|
|
|
|
this.form_field_jq.bind("liszt:open", function(evt) { |
|
|
|
|
this.form_field_jq.bind("chosen:open.chosen", function(evt) { |
|
|
|
|
_this.container_mousedown(evt); |
|
|
|
|
}); |
|
|
|
|
this.search_field.blur(function(evt) { |
|
|
|
|
this.search_field.bind('blur.chosen', function(evt) { |
|
|
|
|
_this.input_blur(evt); |
|
|
|
|
}); |
|
|
|
|
this.search_field.keyup(function(evt) { |
|
|
|
|
this.search_field.bind('keyup.chosen', function(evt) { |
|
|
|
|
_this.keyup_checker(evt); |
|
|
|
|
}); |
|
|
|
|
this.search_field.keydown(function(evt) { |
|
|
|
|
this.search_field.bind('keydown.chosen', function(evt) { |
|
|
|
|
_this.keydown_checker(evt); |
|
|
|
|
}); |
|
|
|
|
this.search_field.focus(function(evt) { |
|
|
|
|
this.search_field.bind('focus.chosen', function(evt) { |
|
|
|
|
_this.input_focus(evt); |
|
|
|
|
}); |
|
|
|
|
if (this.is_multiple) { |
|
|
|
|
return this.search_choices.click(function(evt) { |
|
|
|
|
return this.search_choices.bind('click.chosen', function(evt) { |
|
|
|
|
_this.choices_click(evt); |
|
|
|
|
}); |
|
|
|
|
} else { |
|
|
|
|
return this.container.click(function(evt) { |
|
|
|
|
return this.container.bind('click.chosen', function(evt) { |
|
|
|
|
evt.preventDefault(); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
Chosen.prototype.destroy = function() { |
|
|
|
|
$(document).unbind("click.chosen", this.click_test_action); |
|
|
|
|
if (this.search_field[0].tabIndex) { |
|
|
|
|
this.form_field_jq[0].tabIndex = this.search_field[0].tabIndex; |
|
|
|
|
} |
|
|
|
|
this.container.remove(); |
|
|
|
|
this.form_field_jq.removeData('chosen'); |
|
|
|
|
return this.form_field_jq.show(); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
Chosen.prototype.search_field_disabled = function() { |
|
|
|
|
this.is_disabled = this.form_field_jq[0].disabled; |
|
|
|
|
if (this.is_disabled) { |
|
|
|
|
this.container.addClass('chzn-disabled'); |
|
|
|
|
this.container.addClass('chosen-disabled'); |
|
|
|
|
this.search_field[0].disabled = true; |
|
|
|
|
if (!this.is_multiple) { |
|
|
|
|
this.selected_item.unbind("focus", this.activate_action); |
|
|
|
|
this.selected_item.unbind("focus.chosen", this.activate_action); |
|
|
|
|
} |
|
|
|
|
return this.close_field(); |
|
|
|
|
} else { |
|
|
|
|
this.container.removeClass('chzn-disabled'); |
|
|
|
|
this.container.removeClass('chosen-disabled'); |
|
|
|
|
this.search_field[0].disabled = false; |
|
|
|
|
if (!this.is_multiple) { |
|
|
|
|
return this.selected_item.bind("focus", this.activate_action); |
|
|
|
|
return this.selected_item.bind("focus.chosen", this.activate_action); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
@ -598,9 +653,9 @@ |
|
|
|
|
if (this.is_multiple) { |
|
|
|
|
this.search_field.val(""); |
|
|
|
|
} |
|
|
|
|
$(document).click(this.click_test_action); |
|
|
|
|
$(document).bind('click.chosen', 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)) { |
|
|
|
|
} else if (!this.is_multiple && evt && (($(evt.target)[0] === this.selected_item[0]) || $(evt.target).parents("a.chosen-single").length)) { |
|
|
|
|
evt.preventDefault(); |
|
|
|
|
this.results_toggle(); |
|
|
|
|
} |
|
|
|
@ -629,30 +684,30 @@ |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
Chosen.prototype.blur_test = function(evt) { |
|
|
|
|
if (!this.active_field && this.container.hasClass("chzn-container-active")) { |
|
|
|
|
if (!this.active_field && this.container.hasClass("chosen-container-active")) { |
|
|
|
|
return this.close_field(); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
Chosen.prototype.close_field = function() { |
|
|
|
|
$(document).unbind("click", this.click_test_action); |
|
|
|
|
$(document).unbind("click.chosen", this.click_test_action); |
|
|
|
|
this.active_field = false; |
|
|
|
|
this.results_hide(); |
|
|
|
|
this.container.removeClass("chzn-container-active"); |
|
|
|
|
this.container.removeClass("chosen-container-active"); |
|
|
|
|
this.clear_backstroke(); |
|
|
|
|
this.show_search_field_default(); |
|
|
|
|
return this.search_field_scale(); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
Chosen.prototype.activate_field = function() { |
|
|
|
|
this.container.addClass("chzn-container-active"); |
|
|
|
|
this.container.addClass("chosen-container-active"); |
|
|
|
|
this.active_field = true; |
|
|
|
|
this.search_field.val(this.search_field.val()); |
|
|
|
|
return this.search_field.focus(); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
Chosen.prototype.test_active_click = function(evt) { |
|
|
|
|
if ($(evt.target).parents('#' + this.container_id).length) { |
|
|
|
|
if (this.container.is($(evt.target).closest('.chosen-container'))) { |
|
|
|
|
return this.active_field = true; |
|
|
|
|
} else { |
|
|
|
|
return this.close_field(); |
|
|
|
@ -662,17 +717,17 @@ |
|
|
|
|
Chosen.prototype.results_build = function() { |
|
|
|
|
this.parsing = true; |
|
|
|
|
this.selected_option_count = null; |
|
|
|
|
this.results_data = root.SelectParser.select_to_array(this.form_field); |
|
|
|
|
this.results_data = SelectParser.select_to_array(this.form_field); |
|
|
|
|
if (this.is_multiple) { |
|
|
|
|
this.search_choices.find("li.search-choice").remove(); |
|
|
|
|
} else if (!this.is_multiple) { |
|
|
|
|
this.single_set_selected_text(); |
|
|
|
|
if (this.disable_search || this.form_field.options.length <= this.disable_search_threshold) { |
|
|
|
|
this.search_field[0].readOnly = true; |
|
|
|
|
this.container.addClass("chzn-container-single-nosearch"); |
|
|
|
|
this.container.addClass("chosen-container-single-nosearch"); |
|
|
|
|
} else { |
|
|
|
|
this.search_field[0].readOnly = false; |
|
|
|
|
this.container.removeClass("chzn-container-single-nosearch"); |
|
|
|
|
this.container.removeClass("chosen-container-single-nosearch"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
this.update_results_content(this.results_option_build({ |
|
|
|
@ -684,11 +739,6 @@ |
|
|
|
|
return this.parsing = false; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
Chosen.prototype.result_add_group = function(group) { |
|
|
|
|
group.dom_id = this.container_id + "_g_" + group.array_index; |
|
|
|
|
return '<li id="' + group.dom_id + '" class="group-result">' + $("<div />").text(group.label).html() + '</li>'; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
Chosen.prototype.result_do_highlight = function(el) { |
|
|
|
|
var high_bottom, high_top, maxHeight, visible_bottom, visible_top; |
|
|
|
|
|
|
|
|
@ -718,13 +768,13 @@ |
|
|
|
|
|
|
|
|
|
Chosen.prototype.results_show = function() { |
|
|
|
|
if (this.is_multiple && this.max_selected_options <= this.choices_count()) { |
|
|
|
|
this.form_field_jq.trigger("liszt:maxselected", { |
|
|
|
|
this.form_field_jq.trigger("chosen:maxselected", { |
|
|
|
|
chosen: this |
|
|
|
|
}); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
this.container.addClass("chzn-with-drop"); |
|
|
|
|
this.form_field_jq.trigger("liszt:showing_dropdown", { |
|
|
|
|
this.container.addClass("chosen-with-drop"); |
|
|
|
|
this.form_field_jq.trigger("chosen:showing_dropdown", { |
|
|
|
|
chosen: this |
|
|
|
|
}); |
|
|
|
|
this.results_showing = true; |
|
|
|
@ -740,8 +790,8 @@ |
|
|
|
|
Chosen.prototype.results_hide = function() { |
|
|
|
|
if (this.results_showing) { |
|
|
|
|
this.result_clear_highlight(); |
|
|
|
|
this.container.removeClass("chzn-with-drop"); |
|
|
|
|
this.form_field_jq.trigger("liszt:hiding_dropdown", { |
|
|
|
|
this.container.removeClass("chosen-with-drop"); |
|
|
|
|
this.form_field_jq.trigger("chosen:hiding_dropdown", { |
|
|
|
|
chosen: this |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
@ -751,10 +801,10 @@ |
|
|
|
|
Chosen.prototype.set_tab_index = function(el) { |
|
|
|
|
var ti; |
|
|
|
|
|
|
|
|
|
if (this.form_field_jq.attr("tabindex")) { |
|
|
|
|
ti = this.form_field_jq.attr("tabindex"); |
|
|
|
|
this.form_field_jq.attr("tabindex", -1); |
|
|
|
|
return this.search_field.attr("tabindex", ti); |
|
|
|
|
if (this.form_field.tabIndex) { |
|
|
|
|
ti = this.form_field.tabIndex; |
|
|
|
|
this.form_field.tabIndex = -1; |
|
|
|
|
return this.search_field[0].tabIndex = ti; |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
@ -766,7 +816,7 @@ |
|
|
|
|
this.form_field_label = $("label[for='" + this.form_field.id + "']"); |
|
|
|
|
} |
|
|
|
|
if (this.form_field_label.length > 0) { |
|
|
|
|
return this.form_field_label.click(function(evt) { |
|
|
|
|
return this.form_field_label.bind('click.chosen', function(evt) { |
|
|
|
|
if (_this.is_multiple) { |
|
|
|
|
return _this.container_mousedown(evt); |
|
|
|
|
} else { |
|
|
|
@ -823,11 +873,10 @@ |
|
|
|
|
choice.addClass('search-choice-disabled'); |
|
|
|
|
} else { |
|
|
|
|
close_link = $('<a />', { |
|
|
|
|
href: '#', |
|
|
|
|
"class": 'search-choice-close', |
|
|
|
|
rel: item.array_index |
|
|
|
|
'data-option-array-index': item.array_index |
|
|
|
|
}); |
|
|
|
|
close_link.click(function(evt) { |
|
|
|
|
close_link.bind('click.chosen', function(evt) { |
|
|
|
|
return _this.choice_destroy_link_click(evt); |
|
|
|
|
}); |
|
|
|
|
choice.append(close_link); |
|
|
|
@ -844,7 +893,7 @@ |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
Chosen.prototype.choice_destroy = function(link) { |
|
|
|
|
if (this.result_deselect(link.attr("rel"))) { |
|
|
|
|
if (this.result_deselect(link[0].getAttribute("data-option-array-index"))) { |
|
|
|
|
this.show_search_field_default(); |
|
|
|
|
if (this.is_multiple && this.choices_count() > 0 && this.search_field.val().length < 1) { |
|
|
|
|
this.results_hide(); |
|
|
|
@ -872,14 +921,13 @@ |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
Chosen.prototype.result_select = function(evt) { |
|
|
|
|
var high, high_id, item, position; |
|
|
|
|
var high, item, selected_index; |
|
|
|
|
|
|
|
|
|
if (this.result_highlight) { |
|
|
|
|
high = this.result_highlight; |
|
|
|
|
high_id = high.attr("id"); |
|
|
|
|
this.result_clear_highlight(); |
|
|
|
|
if (this.is_multiple && this.max_selected_options <= this.choices_count()) { |
|
|
|
|
this.form_field_jq.trigger("liszt:maxselected", { |
|
|
|
|
this.form_field_jq.trigger("chosen:maxselected", { |
|
|
|
|
chosen: this |
|
|
|
|
}); |
|
|
|
|
return false; |
|
|
|
@ -887,12 +935,15 @@ |
|
|
|
|
if (this.is_multiple) { |
|
|
|
|
high.removeClass("active-result"); |
|
|
|
|
} else { |
|
|
|
|
this.search_results.find(".result-selected").removeClass("result-selected"); |
|
|
|
|
if (this.result_single_selected) { |
|
|
|
|
this.result_single_selected.removeClass("result-selected"); |
|
|
|
|
selected_index = this.result_single_selected[0].getAttribute('data-option-array-index'); |
|
|
|
|
this.results_data[selected_index].selected = false; |
|
|
|
|
} |
|
|
|
|
this.result_single_selected = high; |
|
|
|
|
} |
|
|
|
|
high.addClass("result-selected"); |
|
|
|
|
position = high_id.substr(high_id.lastIndexOf("_") + 1); |
|
|
|
|
item = this.results_data[position]; |
|
|
|
|
item = this.results_data[high[0].getAttribute("data-option-array-index")]; |
|
|
|
|
item.selected = true; |
|
|
|
|
this.form_field.options[item.options_index].selected = true; |
|
|
|
|
this.selected_option_count = null; |
|
|
|
@ -920,24 +971,22 @@ |
|
|
|
|
text = this.default_text; |
|
|
|
|
} |
|
|
|
|
if (text === this.default_text) { |
|
|
|
|
this.selected_item.addClass("chzn-default"); |
|
|
|
|
this.selected_item.addClass("chosen-default"); |
|
|
|
|
} else { |
|
|
|
|
this.single_deselect_control_build(); |
|
|
|
|
this.selected_item.removeClass("chzn-default"); |
|
|
|
|
this.selected_item.removeClass("chosen-default"); |
|
|
|
|
} |
|
|
|
|
return this.selected_item.find("span").text(text); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
Chosen.prototype.result_deselect = function(pos) { |
|
|
|
|
var result, result_data; |
|
|
|
|
var result_data; |
|
|
|
|
|
|
|
|
|
result_data = this.results_data[pos]; |
|
|
|
|
if (!this.form_field.options[result_data.options_index].disabled) { |
|
|
|
|
result_data.selected = false; |
|
|
|
|
this.form_field.options[result_data.options_index].selected = false; |
|
|
|
|
this.selected_option_count = null; |
|
|
|
|
result = $("#" + this.container_id + "_o_" + pos); |
|
|
|
|
result.removeClass("result-selected").addClass("active-result").show(); |
|
|
|
|
this.result_clear_highlight(); |
|
|
|
|
if (this.results_showing) { |
|
|
|
|
this.winnow_results(); |
|
|
|
@ -959,7 +1008,7 @@ |
|
|
|
|
if (!this.selected_item.find("abbr").length) { |
|
|
|
|
this.selected_item.find("span").first().after("<abbr class=\"search-choice-close\"></abbr>"); |
|
|
|
|
} |
|
|
|
|
return this.selected_item.addClass("chzn-single-with-deselect"); |
|
|
|
|
return this.selected_item.addClass("chosen-single-with-deselect"); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
Chosen.prototype.get_search_text = function() { |
|
|
|
@ -1082,7 +1131,7 @@ |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
Chosen.prototype.search_field_scale = function() { |
|
|
|
|
var div, h, style, style_block, styles, w, _i, _len; |
|
|
|
|
var div, f_width, h, style, style_block, styles, w, _i, _len; |
|
|
|
|
|
|
|
|
|
if (this.is_multiple) { |
|
|
|
|
h = 0; |
|
|
|
@ -1100,11 +1149,9 @@ |
|
|
|
|
$('body').append(div); |
|
|
|
|
w = div.width() + 25; |
|
|
|
|
div.remove(); |
|
|
|
|
if (!this.f_width) { |
|
|
|
|
this.f_width = this.container.outerWidth(); |
|
|
|
|
} |
|
|
|
|
if (w > this.f_width - 10) { |
|
|
|
|
w = this.f_width - 10; |
|
|
|
|
f_width = this.container.outerWidth(); |
|
|
|
|
if (w > f_width - 10) { |
|
|
|
|
w = f_width - 10; |
|
|
|
|
} |
|
|
|
|
return this.search_field.css({ |
|
|
|
|
'width': w + 'px' |
|
|
|
@ -1112,20 +1159,8 @@ |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
Chosen.prototype.generate_random_id = function() { |
|
|
|
|
var string; |
|
|
|
|
|
|
|
|
|
string = "sel" + this.generate_random_char() + this.generate_random_char() + this.generate_random_char(); |
|
|
|
|
while ($("#" + string).length > 0) { |
|
|
|
|
string += this.generate_random_char(); |
|
|
|
|
} |
|
|
|
|
return string; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
return Chosen; |
|
|
|
|
|
|
|
|
|
})(AbstractChosen); |
|
|
|
|
|
|
|
|
|
root.Chosen = Chosen; |
|
|
|
|
|
|
|
|
|
}).call(this); |
|
|
|
|