|
|
|
@ -2,9 +2,9 @@ |
|
|
|
|
Chosen, a Select Box Enhancer for jQuery and Prototype |
|
|
|
|
by Patrick Filler for Harvest, http://getharvest.com
|
|
|
|
|
|
|
|
|
|
Version 1.1.0 |
|
|
|
|
Version 1.4.0 |
|
|
|
|
Full source at https://github.com/harvesthq/chosen
|
|
|
|
|
Copyright (c) 2011 Harvest http://getharvest.com
|
|
|
|
|
Copyright (c) 2011-2015 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. |
|
|
|
@ -36,8 +36,10 @@ This file is generated by `grunt build`, do not edit it by hand. |
|
|
|
|
array_index: group_position, |
|
|
|
|
group: true, |
|
|
|
|
label: this.escapeExpression(group.label), |
|
|
|
|
title: group.title ? group.title : void 0, |
|
|
|
|
children: 0, |
|
|
|
|
disabled: group.disabled |
|
|
|
|
disabled: group.disabled, |
|
|
|
|
classes: group.className |
|
|
|
|
}); |
|
|
|
|
_ref = group.childNodes; |
|
|
|
|
_results = []; |
|
|
|
@ -60,9 +62,11 @@ This file is generated by `grunt build`, do not edit it by hand. |
|
|
|
|
value: option.value, |
|
|
|
|
text: option.text, |
|
|
|
|
html: option.innerHTML, |
|
|
|
|
title: option.title ? option.title : void 0, |
|
|
|
|
selected: option.selected, |
|
|
|
|
disabled: group_disabled === true ? group_disabled : option.disabled, |
|
|
|
|
group_array_index: group_position, |
|
|
|
|
group_label: group_position != null ? this.parsed[group_position].label : null, |
|
|
|
|
classes: option.className, |
|
|
|
|
style: option.style.cssText |
|
|
|
|
}); |
|
|
|
@ -126,6 +130,7 @@ This file is generated by `grunt build`, do not edit it by hand. |
|
|
|
|
this.setup(); |
|
|
|
|
this.set_up_html(); |
|
|
|
|
this.register_observers(); |
|
|
|
|
this.on_ready(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
AbstractChosen.prototype.set_default_values = function() { |
|
|
|
@ -150,7 +155,8 @@ This file is generated by `grunt build`, do not edit it by hand. |
|
|
|
|
this.max_selected_options = this.options.max_selected_options || Infinity; |
|
|
|
|
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; |
|
|
|
|
this.display_disabled_options = this.options.display_disabled_options != null ? this.options.display_disabled_options : true; |
|
|
|
|
return this.include_group_label_in_selected = this.options.include_group_label_in_selected || false; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
AbstractChosen.prototype.set_default_text = function() { |
|
|
|
@ -164,6 +170,14 @@ This file is generated by `grunt build`, do not edit it by hand. |
|
|
|
|
return this.results_none_found = this.form_field.getAttribute("data-no_results_text") || this.options.no_results_text || AbstractChosen.default_no_result_text; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
AbstractChosen.prototype.choice_label = function(item) { |
|
|
|
|
if (this.include_group_label_in_selected && (item.group_label != null)) { |
|
|
|
|
return "<b class='group-name'>" + item.group_label + "</b>" + item.html; |
|
|
|
|
} else { |
|
|
|
|
return item.html; |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
AbstractChosen.prototype.mouse_enter = function() { |
|
|
|
|
return this.mouse_on_container = true; |
|
|
|
|
}; |
|
|
|
@ -212,7 +226,7 @@ This file is generated by `grunt build`, do not edit it by hand. |
|
|
|
|
if (data.selected && this.is_multiple) { |
|
|
|
|
this.choice_build(data); |
|
|
|
|
} else if (data.selected && !this.is_multiple) { |
|
|
|
|
this.single_set_selected_text(data.text); |
|
|
|
|
this.single_set_selected_text(data.html); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -248,20 +262,31 @@ This file is generated by `grunt build`, do not edit it by hand. |
|
|
|
|
option_el.style.cssText = option.style; |
|
|
|
|
option_el.setAttribute("data-option-array-index", option.array_index); |
|
|
|
|
option_el.innerHTML = option.search_text; |
|
|
|
|
if (option.title) { |
|
|
|
|
option_el.title = option.title; |
|
|
|
|
} |
|
|
|
|
return this.outerHTML(option_el); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
AbstractChosen.prototype.result_add_group = function(group) { |
|
|
|
|
var group_el; |
|
|
|
|
var classes, group_el; |
|
|
|
|
if (!(group.search_match || group.group_match)) { |
|
|
|
|
return ''; |
|
|
|
|
} |
|
|
|
|
if (!(group.active_options > 0)) { |
|
|
|
|
return ''; |
|
|
|
|
} |
|
|
|
|
classes = []; |
|
|
|
|
classes.push("group-result"); |
|
|
|
|
if (group.classes) { |
|
|
|
|
classes.push(group.classes); |
|
|
|
|
} |
|
|
|
|
group_el = document.createElement("li"); |
|
|
|
|
group_el.className = "group-result"; |
|
|
|
|
group_el.className = classes.join(" "); |
|
|
|
|
group_el.innerHTML = group.search_text; |
|
|
|
|
if (group.title) { |
|
|
|
|
group_el.title = group.title; |
|
|
|
|
} |
|
|
|
|
return this.outerHTML(group_el); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
@ -309,14 +334,13 @@ This file is generated by `grunt build`, do not edit it by hand. |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
AbstractChosen.prototype.winnow_results = function() { |
|
|
|
|
var escapedSearchText, option, regex, regexAnchor, results, results_group, searchText, startpos, text, zregex, _i, _len, _ref; |
|
|
|
|
var escapedSearchText, option, regex, 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 + escapedSearchText, 'i'); |
|
|
|
|
zregex = new RegExp(escapedSearchText, 'i'); |
|
|
|
|
regex = this.get_search_regex(escapedSearchText); |
|
|
|
|
_ref = this.results_data; |
|
|
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) { |
|
|
|
|
option = _ref[_i]; |
|
|
|
@ -365,6 +389,12 @@ This file is generated by `grunt build`, do not edit it by hand. |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
AbstractChosen.prototype.get_search_regex = function(escaped_search_string) { |
|
|
|
|
var regex_anchor; |
|
|
|
|
regex_anchor = this.search_contains ? "" : "^"; |
|
|
|
|
return new RegExp(regex_anchor + escaped_search_string, 'i'); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
AbstractChosen.prototype.search_string_match = function(search_string, regex) { |
|
|
|
|
var part, parts, _i, _len; |
|
|
|
|
if (regex.test(search_string)) { |
|
|
|
@ -531,9 +561,9 @@ This file is generated by `grunt build`, do not edit it by hand. |
|
|
|
|
var $this, chosen; |
|
|
|
|
$this = $(this); |
|
|
|
|
chosen = $this.data('chosen'); |
|
|
|
|
if (options === 'destroy' && chosen) { |
|
|
|
|
if (options === 'destroy' && chosen instanceof Chosen) { |
|
|
|
|
chosen.destroy(); |
|
|
|
|
} else if (!chosen) { |
|
|
|
|
} else if (!(chosen instanceof Chosen)) { |
|
|
|
|
$this.data('chosen', new Chosen(this, options)); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
@ -593,7 +623,10 @@ This file is generated by `grunt build`, do not edit it by hand. |
|
|
|
|
} |
|
|
|
|
this.results_build(); |
|
|
|
|
this.set_tab_index(); |
|
|
|
|
this.set_label_behavior(); |
|
|
|
|
return this.set_label_behavior(); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
Chosen.prototype.on_ready = function() { |
|
|
|
|
return this.form_field_jq.trigger("chosen:ready", { |
|
|
|
|
chosen: this |
|
|
|
|
}); |
|
|
|
@ -601,6 +634,12 @@ This file is generated by `grunt build`, do not edit it by hand. |
|
|
|
|
|
|
|
|
|
Chosen.prototype.register_observers = function() { |
|
|
|
|
var _this = this; |
|
|
|
|
this.container.bind('touchstart.chosen', function(evt) { |
|
|
|
|
_this.container_mousedown(evt); |
|
|
|
|
}); |
|
|
|
|
this.container.bind('touchend.chosen', function(evt) { |
|
|
|
|
_this.container_mouseup(evt); |
|
|
|
|
}); |
|
|
|
|
this.container.bind('mousedown.chosen', function(evt) { |
|
|
|
|
_this.container_mousedown(evt); |
|
|
|
|
}); |
|
|
|
@ -733,7 +772,7 @@ This file is generated by `grunt build`, do not edit it by hand. |
|
|
|
|
Chosen.prototype.search_results_mousewheel = function(evt) { |
|
|
|
|
var delta; |
|
|
|
|
if (evt.originalEvent) { |
|
|
|
|
delta = -evt.originalEvent.wheelDelta || evt.originalEvent.detail; |
|
|
|
|
delta = evt.originalEvent.deltaY || -evt.originalEvent.wheelDelta || evt.originalEvent.detail; |
|
|
|
|
} |
|
|
|
|
if (delta != null) { |
|
|
|
|
evt.preventDefault(); |
|
|
|
@ -925,7 +964,7 @@ This file is generated by `grunt build`, do not edit it by hand. |
|
|
|
|
_this = this; |
|
|
|
|
choice = $('<li />', { |
|
|
|
|
"class": "search-choice" |
|
|
|
|
}).html("<span>" + item.html + "</span>"); |
|
|
|
|
}).html("<span>" + (this.choice_label(item)) + "</span>"); |
|
|
|
|
if (item.disabled) { |
|
|
|
|
choice.addClass('search-choice-disabled'); |
|
|
|
|
} else { |
|
|
|
@ -1000,7 +1039,7 @@ This file is generated by `grunt build`, do not edit it by hand. |
|
|
|
|
if (this.is_multiple) { |
|
|
|
|
this.choice_build(item); |
|
|
|
|
} else { |
|
|
|
|
this.single_set_selected_text(item.text); |
|
|
|
|
this.single_set_selected_text(this.choice_label(item)); |
|
|
|
|
} |
|
|
|
|
if (!((evt.metaKey || evt.ctrlKey) && this.is_multiple)) { |
|
|
|
|
this.results_hide(); |
|
|
|
@ -1012,6 +1051,7 @@ This file is generated by `grunt build`, do not edit it by hand. |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
this.current_selectedIndex = this.form_field.selectedIndex; |
|
|
|
|
evt.preventDefault(); |
|
|
|
|
return this.search_field_scale(); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
@ -1026,7 +1066,7 @@ This file is generated by `grunt build`, do not edit it by hand. |
|
|
|
|
this.single_deselect_control_build(); |
|
|
|
|
this.selected_item.removeClass("chosen-default"); |
|
|
|
|
} |
|
|
|
|
return this.selected_item.find("span").text(text); |
|
|
|
|
return this.selected_item.find("span").html(text); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
Chosen.prototype.result_deselect = function(pos) { |
|
|
|
@ -1163,7 +1203,14 @@ This file is generated by `grunt build`, do not edit it by hand. |
|
|
|
|
this.mouse_on_container = false; |
|
|
|
|
break; |
|
|
|
|
case 13: |
|
|
|
|
evt.preventDefault(); |
|
|
|
|
if (this.results_showing) { |
|
|
|
|
evt.preventDefault(); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case 32: |
|
|
|
|
if (this.disable_search) { |
|
|
|
|
evt.preventDefault(); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case 38: |
|
|
|
|
evt.preventDefault(); |
|
|
|
|