Compare commits
No commits in common. "harvest_experimental" and "master" have entirely different histories.
harvest_ex
...
master
|
@ -387,7 +387,3 @@
|
||||||
direction: rtl;
|
direction: rtl;
|
||||||
}
|
}
|
||||||
/* @end */
|
/* @end */
|
||||||
|
|
||||||
/* @group Select all options */
|
|
||||||
.chzn-select-all { background: #f8f8f8; border-top: 1px solid #ededed; color: #346f9b; cursor:pointer; display: block; font-size: 12px; font-weight: bold; padding: 5px 6px; text-align: center; text-decoration: none; }
|
|
||||||
/* @end */
|
|
|
@ -106,6 +106,8 @@ Copyright (c) 2011 by Harvest
|
||||||
this.form_field = form_field;
|
this.form_field = form_field;
|
||||||
this.options = options != null ? options : {};
|
this.options = options != null ? options : {};
|
||||||
this.set_default_values();
|
this.set_default_values();
|
||||||
|
this.is_multiple = this.form_field.multiple;
|
||||||
|
this.default_text_default = this.is_multiple ? "Select Some Options" : "Select an Option";
|
||||||
this.setup();
|
this.setup();
|
||||||
this.set_up_html();
|
this.set_up_html();
|
||||||
this.register_observers();
|
this.register_observers();
|
||||||
|
@ -114,8 +116,6 @@ Copyright (c) 2011 by Harvest
|
||||||
|
|
||||||
AbstractChosen.prototype.set_default_values = function() {
|
AbstractChosen.prototype.set_default_values = function() {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
this.is_multiple = this.form_field.multiple;
|
|
||||||
this.default_text_default = this.is_multiple ? "Select Some Options" : "Select an Option";
|
|
||||||
this.click_test_action = function(evt) {
|
this.click_test_action = function(evt) {
|
||||||
return _this.test_active_click(evt);
|
return _this.test_active_click(evt);
|
||||||
};
|
};
|
||||||
|
@ -127,10 +127,8 @@ Copyright (c) 2011 by Harvest
|
||||||
this.results_showing = false;
|
this.results_showing = false;
|
||||||
this.result_highlighted = null;
|
this.result_highlighted = null;
|
||||||
this.result_single_selected = null;
|
this.result_single_selected = null;
|
||||||
this.enable_group_select = this.options.enable_group_select || false;
|
|
||||||
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.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_threshold = this.options.disable_search_threshold || 0;
|
||||||
this.enable_select_all = (this.options.enable_select_all != null) && this.is_multiple ? this.options.enable_select_all : false;
|
|
||||||
this.choices = 0;
|
this.choices = 0;
|
||||||
return this.results_none_found = this.options.no_results_text || "No results match";
|
return this.results_none_found = this.options.no_results_text || "No results match";
|
||||||
};
|
};
|
||||||
|
@ -199,30 +197,6 @@ Copyright (c) 2011 by Harvest
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
AbstractChosen.prototype.winnow_search_match = function(regex, optionText) {
|
|
||||||
var found, part, parts, _i, _len;
|
|
||||||
found = false;
|
|
||||||
if (regex.test(optionText)) {
|
|
||||||
found = true;
|
|
||||||
} else if (optionText.indexOf(" ") >= 0 || optionText.indexOf("[") === 0) {
|
|
||||||
parts = optionText.replace(/\[|\]/g, "").split(" ");
|
|
||||||
if (parts.length) {
|
|
||||||
for (_i = 0, _len = parts.length; _i < _len; _i++) {
|
|
||||||
part = parts[_i];
|
|
||||||
if (regex.test(part)) found = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return found;
|
|
||||||
};
|
|
||||||
|
|
||||||
AbstractChosen.prototype.winnow_search_highlight_match = function(regex, optionText, searchTextLength) {
|
|
||||||
var startpos, text;
|
|
||||||
startpos = optionText.search(regex);
|
|
||||||
text = optionText.substr(0, startpos + searchTextLength) + '</em>' + optionText.substr(startpos + searchTextLength);
|
|
||||||
return text = text.substr(0, startpos) + '<em>' + text.substr(startpos);
|
|
||||||
};
|
|
||||||
|
|
||||||
AbstractChosen.prototype.keyup_checker = function(evt) {
|
AbstractChosen.prototype.keyup_checker = function(evt) {
|
||||||
var stroke, _ref;
|
var stroke, _ref;
|
||||||
stroke = (_ref = evt.which) != null ? _ref : evt.keyCode;
|
stroke = (_ref = evt.which) != null ? _ref : evt.keyCode;
|
||||||
|
@ -230,15 +204,15 @@ Copyright (c) 2011 by Harvest
|
||||||
switch (stroke) {
|
switch (stroke) {
|
||||||
case 8:
|
case 8:
|
||||||
if (this.is_multiple && this.backstroke_length < 1 && this.choices > 0) {
|
if (this.is_multiple && this.backstroke_length < 1 && this.choices > 0) {
|
||||||
this.keydown_backstroke();
|
return this.keydown_backstroke();
|
||||||
} else if (!this.pending_backstroke) {
|
} else if (!this.pending_backstroke) {
|
||||||
this.result_clear_highlight();
|
this.result_clear_highlight();
|
||||||
this.results_search();
|
return this.results_search();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 13:
|
case 13:
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
if (this.results_showing) this.result_select(evt);
|
if (this.results_showing) return this.result_select(evt);
|
||||||
break;
|
break;
|
||||||
case 27:
|
case 27:
|
||||||
if (this.results_showing) this.results_hide();
|
if (this.results_showing) this.results_hide();
|
||||||
|
@ -251,9 +225,8 @@ Copyright (c) 2011 by Harvest
|
||||||
case 17:
|
case 17:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
this.results_search();
|
return this.results_search();
|
||||||
}
|
}
|
||||||
if (this.enable_select_all) return this.select_all_toggle();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
AbstractChosen.prototype.generate_field_id = function() {
|
AbstractChosen.prototype.generate_field_id = function() {
|
||||||
|
@ -340,7 +313,6 @@ Copyright (c) 2011 by Harvest
|
||||||
this.container = $('#' + this.container_id);
|
this.container = $('#' + this.container_id);
|
||||||
this.container.addClass("chzn-container-" + (this.is_multiple ? "multi" : "single"));
|
this.container.addClass("chzn-container-" + (this.is_multiple ? "multi" : "single"));
|
||||||
this.dropdown = this.container.find('div.chzn-drop').first();
|
this.dropdown = this.container.find('div.chzn-drop').first();
|
||||||
if (this.enable_select_all) this.select_all_setup();
|
|
||||||
dd_top = this.container.height();
|
dd_top = this.container.height();
|
||||||
dd_width = this.f_width - get_side_border_padding(this.dropdown);
|
dd_width = this.f_width - get_side_border_padding(this.dropdown);
|
||||||
this.dropdown.css({
|
this.dropdown.css({
|
||||||
|
@ -588,8 +560,7 @@ Copyright (c) 2011 by Harvest
|
||||||
this.results_showing = true;
|
this.results_showing = true;
|
||||||
this.search_field.focus();
|
this.search_field.focus();
|
||||||
this.search_field.val(this.search_field.val());
|
this.search_field.val(this.search_field.val());
|
||||||
this.winnow_results();
|
return this.winnow_results();
|
||||||
if (this.enable_select_all) return this.select_all_toggle();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Chosen.prototype.results_hide = function() {
|
Chosen.prototype.results_hide = function() {
|
||||||
|
@ -603,49 +574,6 @@ Copyright (c) 2011 by Harvest
|
||||||
return this.results_showing = false;
|
return this.results_showing = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
Chosen.prototype.select_all_setup = function() {
|
|
||||||
var select_all_temp,
|
|
||||||
_this = this;
|
|
||||||
select_all_temp = $("<a />", {
|
|
||||||
"class": "chzn-select-all"
|
|
||||||
}).html("Select all options");
|
|
||||||
this.dropdown.append(select_all_temp);
|
|
||||||
this.select_all_link = this.dropdown.find(".chzn-select-all").first();
|
|
||||||
return this.select_all_link.click(function(evt) {
|
|
||||||
return _this.select_all_options(evt);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
Chosen.prototype.select_all_options = function(evt) {
|
|
||||||
var option, options, _i, _len;
|
|
||||||
evt.preventDefault();
|
|
||||||
options = this.form_field_jq.find("option");
|
|
||||||
for (_i = 0, _len = options.length; _i < _len; _i++) {
|
|
||||||
option = options[_i];
|
|
||||||
if (!option.disabled) option.selected = true;
|
|
||||||
}
|
|
||||||
this.form_field_jq.trigger("liszt:updated");
|
|
||||||
return this.select_all_disable();
|
|
||||||
};
|
|
||||||
|
|
||||||
Chosen.prototype.select_all_disable = function() {
|
|
||||||
return this.select_all_link.hide();
|
|
||||||
};
|
|
||||||
|
|
||||||
Chosen.prototype.select_all_enable = function() {
|
|
||||||
return this.select_all_link.show();
|
|
||||||
};
|
|
||||||
|
|
||||||
Chosen.prototype.select_all_toggle = function() {
|
|
||||||
var actives;
|
|
||||||
actives = this.search_results.find("li.active-result");
|
|
||||||
if (!actives.length || this.search_field.val().length) {
|
|
||||||
return this.select_all_disable();
|
|
||||||
} else {
|
|
||||||
return this.select_all_enable();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Chosen.prototype.set_tab_index = function(el) {
|
Chosen.prototype.set_tab_index = function(el) {
|
||||||
var ti;
|
var ti;
|
||||||
if (this.form_field_jq.attr("tabindex")) {
|
if (this.form_field_jq.attr("tabindex")) {
|
||||||
|
@ -671,23 +599,10 @@ Copyright (c) 2011 by Harvest
|
||||||
};
|
};
|
||||||
|
|
||||||
Chosen.prototype.search_results_mouseup = function(evt) {
|
Chosen.prototype.search_results_mouseup = function(evt) {
|
||||||
var child, children, group, option, _i, _len;
|
var target;
|
||||||
if (this.enable_group_select) {
|
target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
|
||||||
group = $(evt.target).hasClass("group-result") ? $(evt.target) : $(evt.target).parents(".group-result").first();
|
if (target.length) {
|
||||||
if (group.length) {
|
this.result_highlight = target;
|
||||||
children = group.nextUntil(".group-result", ".active-result");
|
|
||||||
for (_i = 0, _len = children.length; _i < _len; _i++) {
|
|
||||||
child = children[_i];
|
|
||||||
this.result_highlight = $(child);
|
|
||||||
this.result_select({
|
|
||||||
metaKey: null
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
option = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
|
|
||||||
if (option.length) {
|
|
||||||
this.result_highlight = option;
|
|
||||||
return this.result_select(evt);
|
return this.result_select(evt);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -810,26 +725,42 @@ Copyright (c) 2011 by Harvest
|
||||||
};
|
};
|
||||||
|
|
||||||
Chosen.prototype.winnow_results = function() {
|
Chosen.prototype.winnow_results = function() {
|
||||||
var found, option, result, result_id, results, text, _i, _len, _ref;
|
var found, option, part, parts, regex, result, result_id, results, searchText, startpos, text, zregex, _i, _j, _len, _len2, _ref;
|
||||||
this.no_results_clear();
|
this.no_results_clear();
|
||||||
results = 0;
|
results = 0;
|
||||||
this.searchText = this.search_field.val() === this.default_text ? "" : $('<div/>').text($.trim(this.search_field.val())).html();
|
searchText = this.search_field.val() === this.default_text ? "" : $('<div/>').text($.trim(this.search_field.val())).html();
|
||||||
this.regex = new RegExp('^' + this.searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
|
regex = new RegExp('^' + searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
|
||||||
this.zregex = new RegExp(this.searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
|
zregex = new RegExp(searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
|
||||||
_ref = this.results_data;
|
_ref = this.results_data;
|
||||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||||
option = _ref[_i];
|
option = _ref[_i];
|
||||||
if (!option.disabled && !option.empty) {
|
if (!option.disabled && !option.empty) {
|
||||||
if (option.group) {
|
if (option.group) {
|
||||||
this.winnow_option_group(option);
|
$('#' + option.dom_id).css('display', 'none');
|
||||||
} else if (!(this.is_multiple && option.selected)) {
|
} else if (!(this.is_multiple && option.selected)) {
|
||||||
found = this.winnow_search_match(this.regex, option.html);
|
found = false;
|
||||||
result_id = option.dom_id;
|
result_id = option.dom_id;
|
||||||
result = $("#" + result_id);
|
result = $("#" + result_id);
|
||||||
if (found || ((option.group_array_index != null) && this.results_data[option.group_array_index].search_match)) {
|
if (regex.test(option.html)) {
|
||||||
|
found = true;
|
||||||
results += 1;
|
results += 1;
|
||||||
if (this.searchText.length && found) {
|
} else if (option.html.indexOf(" ") >= 0 || option.html.indexOf("[") === 0) {
|
||||||
text = this.winnow_search_highlight_match(this.zregex, option.html, this.searchText.length);
|
parts = option.html.replace(/\[|\]/g, "").split(" ");
|
||||||
|
if (parts.length) {
|
||||||
|
for (_j = 0, _len2 = parts.length; _j < _len2; _j++) {
|
||||||
|
part = parts[_j];
|
||||||
|
if (regex.test(part)) {
|
||||||
|
found = true;
|
||||||
|
results += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (found) {
|
||||||
|
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 {
|
} else {
|
||||||
text = option.html;
|
text = option.html;
|
||||||
}
|
}
|
||||||
|
@ -847,22 +778,13 @@ Copyright (c) 2011 by Harvest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (results < 1 && this.searchText.length) {
|
if (results < 1 && searchText.length) {
|
||||||
return this.no_results(this.searchText);
|
return this.no_results(searchText);
|
||||||
} else {
|
} else {
|
||||||
return this.winnow_results_set_highlight();
|
return this.winnow_results_set_highlight();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Chosen.prototype.winnow_option_group = function(group) {
|
|
||||||
var text;
|
|
||||||
$('#' + group.dom_id).css('display', 'none');
|
|
||||||
group.search_match = this.winnow_search_match(this.regex, group.label);
|
|
||||||
text = this.searchText.length && group.search_match ? this.winnow_search_highlight_match(this.zregex, group.label, this.searchText.length) : group.label;
|
|
||||||
$("#" + group.dom_id).html(text);
|
|
||||||
return group.search_match;
|
|
||||||
};
|
|
||||||
|
|
||||||
Chosen.prototype.winnow_results_clear = function() {
|
Chosen.prototype.winnow_results_clear = function() {
|
||||||
var li, lis, _i, _len, _results;
|
var li, lis, _i, _len, _results;
|
||||||
this.search_field.val("");
|
this.search_field.val("");
|
||||||
|
|
2
chosen/chosen.jquery.min.js
vendored
2
chosen/chosen.jquery.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -106,6 +106,8 @@ Copyright (c) 2011 by Harvest
|
||||||
this.form_field = form_field;
|
this.form_field = form_field;
|
||||||
this.options = options != null ? options : {};
|
this.options = options != null ? options : {};
|
||||||
this.set_default_values();
|
this.set_default_values();
|
||||||
|
this.is_multiple = this.form_field.multiple;
|
||||||
|
this.default_text_default = this.is_multiple ? "Select Some Options" : "Select an Option";
|
||||||
this.setup();
|
this.setup();
|
||||||
this.set_up_html();
|
this.set_up_html();
|
||||||
this.register_observers();
|
this.register_observers();
|
||||||
|
@ -114,8 +116,6 @@ Copyright (c) 2011 by Harvest
|
||||||
|
|
||||||
AbstractChosen.prototype.set_default_values = function() {
|
AbstractChosen.prototype.set_default_values = function() {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
this.is_multiple = this.form_field.multiple;
|
|
||||||
this.default_text_default = this.is_multiple ? "Select Some Options" : "Select an Option";
|
|
||||||
this.click_test_action = function(evt) {
|
this.click_test_action = function(evt) {
|
||||||
return _this.test_active_click(evt);
|
return _this.test_active_click(evt);
|
||||||
};
|
};
|
||||||
|
@ -127,10 +127,8 @@ Copyright (c) 2011 by Harvest
|
||||||
this.results_showing = false;
|
this.results_showing = false;
|
||||||
this.result_highlighted = null;
|
this.result_highlighted = null;
|
||||||
this.result_single_selected = null;
|
this.result_single_selected = null;
|
||||||
this.enable_group_select = this.options.enable_group_select || false;
|
|
||||||
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.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_threshold = this.options.disable_search_threshold || 0;
|
||||||
this.enable_select_all = (this.options.enable_select_all != null) && this.is_multiple ? this.options.enable_select_all : false;
|
|
||||||
this.choices = 0;
|
this.choices = 0;
|
||||||
return this.results_none_found = this.options.no_results_text || "No results match";
|
return this.results_none_found = this.options.no_results_text || "No results match";
|
||||||
};
|
};
|
||||||
|
@ -199,30 +197,6 @@ Copyright (c) 2011 by Harvest
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
AbstractChosen.prototype.winnow_search_match = function(regex, optionText) {
|
|
||||||
var found, part, parts, _i, _len;
|
|
||||||
found = false;
|
|
||||||
if (regex.test(optionText)) {
|
|
||||||
found = true;
|
|
||||||
} else if (optionText.indexOf(" ") >= 0 || optionText.indexOf("[") === 0) {
|
|
||||||
parts = optionText.replace(/\[|\]/g, "").split(" ");
|
|
||||||
if (parts.length) {
|
|
||||||
for (_i = 0, _len = parts.length; _i < _len; _i++) {
|
|
||||||
part = parts[_i];
|
|
||||||
if (regex.test(part)) found = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return found;
|
|
||||||
};
|
|
||||||
|
|
||||||
AbstractChosen.prototype.winnow_search_highlight_match = function(regex, optionText, searchTextLength) {
|
|
||||||
var startpos, text;
|
|
||||||
startpos = optionText.search(regex);
|
|
||||||
text = optionText.substr(0, startpos + searchTextLength) + '</em>' + optionText.substr(startpos + searchTextLength);
|
|
||||||
return text = text.substr(0, startpos) + '<em>' + text.substr(startpos);
|
|
||||||
};
|
|
||||||
|
|
||||||
AbstractChosen.prototype.keyup_checker = function(evt) {
|
AbstractChosen.prototype.keyup_checker = function(evt) {
|
||||||
var stroke, _ref;
|
var stroke, _ref;
|
||||||
stroke = (_ref = evt.which) != null ? _ref : evt.keyCode;
|
stroke = (_ref = evt.which) != null ? _ref : evt.keyCode;
|
||||||
|
@ -230,15 +204,15 @@ Copyright (c) 2011 by Harvest
|
||||||
switch (stroke) {
|
switch (stroke) {
|
||||||
case 8:
|
case 8:
|
||||||
if (this.is_multiple && this.backstroke_length < 1 && this.choices > 0) {
|
if (this.is_multiple && this.backstroke_length < 1 && this.choices > 0) {
|
||||||
this.keydown_backstroke();
|
return this.keydown_backstroke();
|
||||||
} else if (!this.pending_backstroke) {
|
} else if (!this.pending_backstroke) {
|
||||||
this.result_clear_highlight();
|
this.result_clear_highlight();
|
||||||
this.results_search();
|
return this.results_search();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 13:
|
case 13:
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
if (this.results_showing) this.result_select(evt);
|
if (this.results_showing) return this.result_select(evt);
|
||||||
break;
|
break;
|
||||||
case 27:
|
case 27:
|
||||||
if (this.results_showing) this.results_hide();
|
if (this.results_showing) this.results_hide();
|
||||||
|
@ -251,9 +225,8 @@ Copyright (c) 2011 by Harvest
|
||||||
case 17:
|
case 17:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
this.results_search();
|
return this.results_search();
|
||||||
}
|
}
|
||||||
if (this.enable_select_all) return this.select_all_toggle();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
AbstractChosen.prototype.generate_field_id = function() {
|
AbstractChosen.prototype.generate_field_id = function() {
|
||||||
|
@ -311,8 +284,7 @@ Copyright (c) 2011 by Harvest
|
||||||
this.single_temp = new Template('<a href="javascript:void(0)" class="chzn-single"><span>#{default}</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.single_temp = new Template('<a href="javascript:void(0)" class="chzn-single"><span>#{default}</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.multi_temp = new Template('<ul class="chzn-choices"><li class="search-field"><input type="text" value="#{default}" class="default" autocomplete="off" style="width:25px;" /></li></ul><div class="chzn-drop" style="left:-9000px;"><ul class="chzn-results"></ul></div>');
|
this.multi_temp = new Template('<ul class="chzn-choices"><li class="search-field"><input type="text" value="#{default}" class="default" autocomplete="off" style="width:25px;" /></li></ul><div class="chzn-drop" style="left:-9000px;"><ul class="chzn-results"></ul></div>');
|
||||||
this.choice_temp = new Template('<li class="search-choice" id="#{id}"><span>#{choice}</span><a href="javascript:void(0)" class="search-choice-close" rel="#{position}"></a></li>');
|
this.choice_temp = new Template('<li class="search-choice" id="#{id}"><span>#{choice}</span><a href="javascript:void(0)" class="search-choice-close" rel="#{position}"></a></li>');
|
||||||
this.no_results_temp = new Template('<li class="no-results">' + this.results_none_found + ' "<span>#{terms}</span>"</li>');
|
return this.no_results_temp = new Template('<li class="no-results">' + this.results_none_found + ' "<span>#{terms}</span>"</li>');
|
||||||
return this.select_all_temp = new Template('<a href="javascript:void(0)" class="chzn-select-all">#{copy}</a>');
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Chosen.prototype.set_up_html = function() {
|
Chosen.prototype.set_up_html = function() {
|
||||||
|
@ -336,7 +308,6 @@ Copyright (c) 2011 by Harvest
|
||||||
this.container = $(this.container_id);
|
this.container = $(this.container_id);
|
||||||
this.container.addClassName("chzn-container-" + (this.is_multiple ? "multi" : "single"));
|
this.container.addClassName("chzn-container-" + (this.is_multiple ? "multi" : "single"));
|
||||||
this.dropdown = this.container.down('div.chzn-drop');
|
this.dropdown = this.container.down('div.chzn-drop');
|
||||||
if (this.enable_select_all) this.select_all_setup();
|
|
||||||
dd_top = this.container.getHeight();
|
dd_top = this.container.getHeight();
|
||||||
dd_width = this.f_width - get_side_border_padding(this.dropdown);
|
dd_width = this.f_width - get_side_border_padding(this.dropdown);
|
||||||
this.dropdown.setStyle({
|
this.dropdown.setStyle({
|
||||||
|
@ -583,8 +554,7 @@ Copyright (c) 2011 by Harvest
|
||||||
this.results_showing = true;
|
this.results_showing = true;
|
||||||
this.search_field.focus();
|
this.search_field.focus();
|
||||||
this.search_field.value = this.search_field.value;
|
this.search_field.value = this.search_field.value;
|
||||||
this.winnow_results();
|
return this.winnow_results();
|
||||||
if (this.enable_select_all) return this.select_all_toggle();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Chosen.prototype.results_hide = function() {
|
Chosen.prototype.results_hide = function() {
|
||||||
|
@ -598,44 +568,6 @@ Copyright (c) 2011 by Harvest
|
||||||
return this.results_showing = false;
|
return this.results_showing = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
Chosen.prototype.select_all_setup = function() {
|
|
||||||
var _this = this;
|
|
||||||
this.dropdown.insert(this.select_all_temp.evaluate({
|
|
||||||
"copy": "Select all options"
|
|
||||||
}));
|
|
||||||
this.select_all_link = this.dropdown.down(".chzn-select-all");
|
|
||||||
return this.select_all_link.observe("click", function(evt) {
|
|
||||||
return _this.select_all_options(evt);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
Chosen.prototype.select_all_options = function(evt) {
|
|
||||||
evt.stop();
|
|
||||||
this.form_field.select("option").each(function(option) {
|
|
||||||
if (!option.disabled) return option.selected = true;
|
|
||||||
});
|
|
||||||
this.form_field.fire("liszt:updated");
|
|
||||||
return this.select_all_disable();
|
|
||||||
};
|
|
||||||
|
|
||||||
Chosen.prototype.select_all_disable = function() {
|
|
||||||
return this.select_all_link.hide();
|
|
||||||
};
|
|
||||||
|
|
||||||
Chosen.prototype.select_all_enable = function() {
|
|
||||||
return this.select_all_link.show();
|
|
||||||
};
|
|
||||||
|
|
||||||
Chosen.prototype.select_all_toggle = function() {
|
|
||||||
var actives;
|
|
||||||
actives = this.search_results.select("li.active-result");
|
|
||||||
if (!actives.length || this.search_field.value.length) {
|
|
||||||
return this.select_all_disable();
|
|
||||||
} else {
|
|
||||||
return this.select_all_enable();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Chosen.prototype.set_tab_index = function(el) {
|
Chosen.prototype.set_tab_index = function(el) {
|
||||||
var ti;
|
var ti;
|
||||||
if (this.form_field.tabIndex) {
|
if (this.form_field.tabIndex) {
|
||||||
|
@ -661,27 +593,10 @@ Copyright (c) 2011 by Harvest
|
||||||
};
|
};
|
||||||
|
|
||||||
Chosen.prototype.search_results_mouseup = function(evt) {
|
Chosen.prototype.search_results_mouseup = function(evt) {
|
||||||
var child, group, option, possible_children, _i, _len;
|
var target;
|
||||||
if (this.enable_group_select) {
|
target = evt.target.hasClassName("active-result") ? evt.target : evt.target.up(".active-result");
|
||||||
group = evt.target.hasClassName("group-result") ? evt.target : evt.target.up(".group-result");
|
if (target) {
|
||||||
if (group) {
|
this.result_highlight = target;
|
||||||
possible_children = group.nextSiblings();
|
|
||||||
for (_i = 0, _len = possible_children.length; _i < _len; _i++) {
|
|
||||||
child = possible_children[_i];
|
|
||||||
if (child.hasClassName("active-result")) {
|
|
||||||
this.result_highlight = $(child);
|
|
||||||
this.result_select({
|
|
||||||
metaKey: null
|
|
||||||
});
|
|
||||||
} else if (child.hasClassName("group-result")) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
option = evt.target.hasClassName("active-result") ? evt.target : evt.target.up(".active-result");
|
|
||||||
if (option) {
|
|
||||||
this.result_highlight = option;
|
|
||||||
return this.result_select(evt);
|
return this.result_select(evt);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -811,25 +726,41 @@ Copyright (c) 2011 by Harvest
|
||||||
};
|
};
|
||||||
|
|
||||||
Chosen.prototype.winnow_results = function() {
|
Chosen.prototype.winnow_results = function() {
|
||||||
var found, option, result_id, results, text, _i, _len, _ref;
|
var found, option, part, parts, regex, result_id, results, searchText, startpos, text, zregex, _i, _j, _len, _len2, _ref;
|
||||||
this.no_results_clear();
|
this.no_results_clear();
|
||||||
results = 0;
|
results = 0;
|
||||||
this.searchText = this.search_field.value === this.default_text ? "" : this.search_field.value.strip().escapeHTML();
|
searchText = this.search_field.value === this.default_text ? "" : this.search_field.value.strip().escapeHTML();
|
||||||
this.regex = new RegExp('^' + this.searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
|
regex = new RegExp('^' + searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
|
||||||
this.zregex = new RegExp(this.searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
|
zregex = new RegExp(searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
|
||||||
_ref = this.results_data;
|
_ref = this.results_data;
|
||||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||||
option = _ref[_i];
|
option = _ref[_i];
|
||||||
if (!option.disabled && !option.empty) {
|
if (!option.disabled && !option.empty) {
|
||||||
if (option.group) {
|
if (option.group) {
|
||||||
this.winnow_option_group(option);
|
$(option.dom_id).hide();
|
||||||
} else if (!(this.is_multiple && option.selected)) {
|
} else if (!(this.is_multiple && option.selected)) {
|
||||||
found = this.winnow_search_match(this.regex, option.html);
|
found = false;
|
||||||
result_id = option.dom_id;
|
result_id = option.dom_id;
|
||||||
if (found || ((option.group_array_index != null) && this.results_data[option.group_array_index].search_match)) {
|
if (regex.test(option.html)) {
|
||||||
|
found = true;
|
||||||
results += 1;
|
results += 1;
|
||||||
if (this.searchText.length && found) {
|
} else if (option.html.indexOf(" ") >= 0 || option.html.indexOf("[") === 0) {
|
||||||
text = this.winnow_search_highlight_match(this.zregex, option.html, this.searchText.length);
|
parts = option.html.replace(/\[|\]/g, "").split(" ");
|
||||||
|
if (parts.length) {
|
||||||
|
for (_j = 0, _len2 = parts.length; _j < _len2; _j++) {
|
||||||
|
part = parts[_j];
|
||||||
|
if (regex.test(part)) {
|
||||||
|
found = true;
|
||||||
|
results += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (found) {
|
||||||
|
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 {
|
} else {
|
||||||
text = option.html;
|
text = option.html;
|
||||||
}
|
}
|
||||||
|
@ -849,21 +780,13 @@ Copyright (c) 2011 by Harvest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (results < 1 && this.searchText.length) {
|
if (results < 1 && searchText.length) {
|
||||||
return this.no_results(this.searchText);
|
return this.no_results(searchText);
|
||||||
} else {
|
} else {
|
||||||
return this.winnow_results_set_highlight();
|
return this.winnow_results_set_highlight();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Chosen.prototype.winnow_option_group = function(group) {
|
|
||||||
var text;
|
|
||||||
$("" + group.dom_id).hide();
|
|
||||||
group.search_match = this.winnow_search_match(this.regex, group.label);
|
|
||||||
text = this.searchText.length && group.search_match ? this.winnow_search_highlight_match(this.zregex, group.label, this.searchText.length) : group.label;
|
|
||||||
return $("" + group.dom_id).update(text);
|
|
||||||
};
|
|
||||||
|
|
||||||
Chosen.prototype.winnow_results_clear = function() {
|
Chosen.prototype.winnow_results_clear = function() {
|
||||||
var li, lis, _i, _len, _results;
|
var li, lis, _i, _len, _results;
|
||||||
this.search_field.clear();
|
this.search_field.clear();
|
||||||
|
|
2
chosen/chosen.proto.min.js
vendored
2
chosen/chosen.proto.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -47,8 +47,6 @@ class Chosen extends AbstractChosen
|
||||||
@container.addClass( "chzn-container-" + (if @is_multiple then "multi" else "single") )
|
@container.addClass( "chzn-container-" + (if @is_multiple then "multi" else "single") )
|
||||||
@dropdown = @container.find('div.chzn-drop').first()
|
@dropdown = @container.find('div.chzn-drop').first()
|
||||||
|
|
||||||
this.select_all_setup() if @enable_select_all
|
|
||||||
|
|
||||||
dd_top = @container.height()
|
dd_top = @container.height()
|
||||||
dd_width = (@f_width - get_side_border_padding(@dropdown))
|
dd_width = (@f_width - get_side_border_padding(@dropdown))
|
||||||
|
|
||||||
|
@ -244,7 +242,6 @@ class Chosen extends AbstractChosen
|
||||||
@search_field.val @search_field.val()
|
@search_field.val @search_field.val()
|
||||||
|
|
||||||
this.winnow_results()
|
this.winnow_results()
|
||||||
this.select_all_toggle() if @enable_select_all
|
|
||||||
|
|
||||||
results_hide: ->
|
results_hide: ->
|
||||||
@selected_item.removeClass "chzn-single-with-drop" unless @is_multiple
|
@selected_item.removeClass "chzn-single-with-drop" unless @is_multiple
|
||||||
|
@ -252,33 +249,6 @@ class Chosen extends AbstractChosen
|
||||||
@dropdown.css {"left":"-9000px"}
|
@dropdown.css {"left":"-9000px"}
|
||||||
@results_showing = false
|
@results_showing = false
|
||||||
|
|
||||||
select_all_setup: ->
|
|
||||||
select_all_temp = $("<a />", { class: "chzn-select-all" }).html("Select all options")
|
|
||||||
@dropdown.append(select_all_temp)
|
|
||||||
@select_all_link = @dropdown.find(".chzn-select-all").first()
|
|
||||||
@select_all_link.click((evt) => this.select_all_options(evt))
|
|
||||||
|
|
||||||
select_all_options: (evt) ->
|
|
||||||
evt.preventDefault()
|
|
||||||
|
|
||||||
options = @form_field_jq.find("option")
|
|
||||||
for option in options
|
|
||||||
option.selected = true if not option.disabled
|
|
||||||
@form_field_jq.trigger("liszt:updated")
|
|
||||||
this.select_all_disable()
|
|
||||||
|
|
||||||
select_all_disable: ->
|
|
||||||
@select_all_link.hide()
|
|
||||||
|
|
||||||
select_all_enable: ->
|
|
||||||
@select_all_link.show()
|
|
||||||
|
|
||||||
select_all_toggle: ->
|
|
||||||
actives = @search_results.find("li.active-result")
|
|
||||||
if not actives.length or @search_field.val().length
|
|
||||||
this.select_all_disable()
|
|
||||||
else
|
|
||||||
this.select_all_enable()
|
|
||||||
|
|
||||||
set_tab_index: (el) ->
|
set_tab_index: (el) ->
|
||||||
if @form_field_jq.attr "tabindex"
|
if @form_field_jq.attr "tabindex"
|
||||||
|
@ -300,17 +270,9 @@ class Chosen extends AbstractChosen
|
||||||
@search_field.removeClass "default"
|
@search_field.removeClass "default"
|
||||||
|
|
||||||
search_results_mouseup: (evt) ->
|
search_results_mouseup: (evt) ->
|
||||||
if @enable_group_select
|
target = if $(evt.target).hasClass "active-result" then $(evt.target) else $(evt.target).parents(".active-result").first()
|
||||||
group = if $(evt.target).hasClass "group-result" then $(evt.target) else $(evt.target).parents(".group-result").first()
|
if target.length
|
||||||
if group.length
|
@result_highlight = target
|
||||||
children = group.nextUntil(".group-result", ".active-result")
|
|
||||||
for child in children
|
|
||||||
@result_highlight = $(child)
|
|
||||||
this.result_select({metaKey: null})
|
|
||||||
|
|
||||||
option = if $(evt.target).hasClass "active-result" then $(evt.target) else $(evt.target).parents(".active-result").first()
|
|
||||||
if option.length
|
|
||||||
@result_highlight = option
|
|
||||||
this.result_select(evt)
|
this.result_select(evt)
|
||||||
|
|
||||||
search_results_mouseover: (evt) ->
|
search_results_mouseover: (evt) ->
|
||||||
|
@ -420,25 +382,36 @@ class Chosen extends AbstractChosen
|
||||||
|
|
||||||
results = 0
|
results = 0
|
||||||
|
|
||||||
@searchText = if @search_field.val() is @default_text then "" else $('<div/>').text($.trim(@search_field.val())).html()
|
searchText = if @search_field.val() is @default_text then "" else $('<div/>').text($.trim(@search_field.val())).html()
|
||||||
@regex = new RegExp('^' + @searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i')
|
regex = new RegExp('^' + searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i')
|
||||||
@zregex = new RegExp(@searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i')
|
zregex = new RegExp(searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i')
|
||||||
|
|
||||||
for option in @results_data
|
for option in @results_data
|
||||||
if not option.disabled and not option.empty
|
if not option.disabled and not option.empty
|
||||||
if option.group
|
if option.group
|
||||||
this.winnow_option_group(option)
|
$('#' + option.dom_id).css('display', 'none')
|
||||||
else if not (@is_multiple and option.selected)
|
else if not (@is_multiple and option.selected)
|
||||||
found = this.winnow_search_match(@regex, option.html)
|
found = false
|
||||||
|
|
||||||
result_id = option.dom_id
|
result_id = option.dom_id
|
||||||
result = $("#" + result_id)
|
result = $("#" + result_id)
|
||||||
|
|
||||||
if found or (option.group_array_index? && @results_data[option.group_array_index].search_match)
|
if regex.test option.html
|
||||||
|
found = true
|
||||||
results += 1
|
results += 1
|
||||||
|
else if option.html.indexOf(" ") >= 0 or option.html.indexOf("[") == 0
|
||||||
if @searchText.length and found
|
#TODO: replace this substitution of /\[\]/ with a list of characters to skip.
|
||||||
text = this.winnow_search_highlight_match(@zregex, option.html, @searchText.length)
|
parts = option.html.replace(/\[|\]/g, "").split(" ")
|
||||||
|
if parts.length
|
||||||
|
for part in parts
|
||||||
|
if regex.test part
|
||||||
|
found = true
|
||||||
|
results += 1
|
||||||
|
|
||||||
|
if found
|
||||||
|
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
|
else
|
||||||
text = option.html
|
text = option.html
|
||||||
|
|
||||||
|
@ -450,20 +423,10 @@ class Chosen extends AbstractChosen
|
||||||
this.result_clear_highlight() if @result_highlight and result_id is @result_highlight.attr 'id'
|
this.result_clear_highlight() if @result_highlight and result_id is @result_highlight.attr 'id'
|
||||||
this.result_deactivate result
|
this.result_deactivate result
|
||||||
|
|
||||||
if results < 1 and @searchText.length
|
if results < 1 and searchText.length
|
||||||
this.no_results @searchText
|
this.no_results searchText
|
||||||
else
|
else
|
||||||
this.winnow_results_set_highlight()
|
this.winnow_results_set_highlight()
|
||||||
|
|
||||||
winnow_option_group: (group) ->
|
|
||||||
$('#' + group.dom_id).css('display', 'none')
|
|
||||||
|
|
||||||
group.search_match = this.winnow_search_match(@regex, group.label)
|
|
||||||
|
|
||||||
text = if @searchText.length and group.search_match then this.winnow_search_highlight_match(@zregex, group.label, @searchText.length) else group.label
|
|
||||||
$("##{group.dom_id}").html(text)
|
|
||||||
|
|
||||||
return group.search_match
|
|
||||||
|
|
||||||
winnow_results_clear: ->
|
winnow_results_clear: ->
|
||||||
@search_field.val ""
|
@search_field.val ""
|
||||||
|
|
|
@ -20,7 +20,6 @@ class Chosen extends AbstractChosen
|
||||||
@multi_temp = new Template('<ul class="chzn-choices"><li class="search-field"><input type="text" value="#{default}" class="default" autocomplete="off" style="width:25px;" /></li></ul><div class="chzn-drop" style="left:-9000px;"><ul class="chzn-results"></ul></div>')
|
@multi_temp = new Template('<ul class="chzn-choices"><li class="search-field"><input type="text" value="#{default}" class="default" autocomplete="off" style="width:25px;" /></li></ul><div class="chzn-drop" style="left:-9000px;"><ul class="chzn-results"></ul></div>')
|
||||||
@choice_temp = new Template('<li class="search-choice" id="#{id}"><span>#{choice}</span><a href="javascript:void(0)" class="search-choice-close" rel="#{position}"></a></li>')
|
@choice_temp = new Template('<li class="search-choice" id="#{id}"><span>#{choice}</span><a href="javascript:void(0)" class="search-choice-close" rel="#{position}"></a></li>')
|
||||||
@no_results_temp = new Template('<li class="no-results">' + @results_none_found + ' "<span>#{terms}</span>"</li>')
|
@no_results_temp = new Template('<li class="no-results">' + @results_none_found + ' "<span>#{terms}</span>"</li>')
|
||||||
@select_all_temp = new Template('<a href="javascript:void(0)" class="chzn-select-all">#{copy}</a>')
|
|
||||||
|
|
||||||
set_up_html: ->
|
set_up_html: ->
|
||||||
@container_id = @form_field.identify().replace(/(:|\.)/g, '_') + "_chzn"
|
@container_id = @form_field.identify().replace(/(:|\.)/g, '_') + "_chzn"
|
||||||
|
@ -35,13 +34,11 @@ class Chosen extends AbstractChosen
|
||||||
@default_text = if @form_field.readAttribute 'data-placeholder' then @form_field.readAttribute 'data-placeholder' else @default_text_default
|
@default_text = if @form_field.readAttribute 'data-placeholder' then @form_field.readAttribute 'data-placeholder' else @default_text_default
|
||||||
|
|
||||||
base_template = if @is_multiple then new Element('div', container_props).update( @multi_temp.evaluate({ "default": @default_text}) ) else new Element('div', container_props).update( @single_temp.evaluate({ "default":@default_text }) )
|
base_template = if @is_multiple then new Element('div', container_props).update( @multi_temp.evaluate({ "default": @default_text}) ) else new Element('div', container_props).update( @single_temp.evaluate({ "default":@default_text }) )
|
||||||
|
|
||||||
@form_field.hide().insert({ after: base_template })
|
@form_field.hide().insert({ after: base_template })
|
||||||
@container = $(@container_id)
|
@container = $(@container_id)
|
||||||
@container.addClassName( "chzn-container-" + (if @is_multiple then "multi" else "single") )
|
@container.addClassName( "chzn-container-" + (if @is_multiple then "multi" else "single") )
|
||||||
@dropdown = @container.down('div.chzn-drop')
|
@dropdown = @container.down('div.chzn-drop')
|
||||||
|
|
||||||
this.select_all_setup() if @enable_select_all
|
|
||||||
|
|
||||||
dd_top = @container.getHeight()
|
dd_top = @container.getHeight()
|
||||||
dd_width = (@f_width - get_side_border_padding(@dropdown))
|
dd_width = (@f_width - get_side_border_padding(@dropdown))
|
||||||
|
@ -236,7 +233,6 @@ class Chosen extends AbstractChosen
|
||||||
@search_field.value = @search_field.value
|
@search_field.value = @search_field.value
|
||||||
|
|
||||||
this.winnow_results()
|
this.winnow_results()
|
||||||
this.select_all_toggle() if @enable_select_all
|
|
||||||
|
|
||||||
results_hide: ->
|
results_hide: ->
|
||||||
@selected_item.removeClassName('chzn-single-with-drop') unless @is_multiple
|
@selected_item.removeClassName('chzn-single-with-drop') unless @is_multiple
|
||||||
|
@ -244,30 +240,6 @@ class Chosen extends AbstractChosen
|
||||||
@dropdown.setStyle({"left":"-9000px"})
|
@dropdown.setStyle({"left":"-9000px"})
|
||||||
@results_showing = false
|
@results_showing = false
|
||||||
|
|
||||||
select_all_setup: ->
|
|
||||||
@dropdown.insert(@select_all_temp.evaluate({ "copy": "Select all options" }))
|
|
||||||
@select_all_link = @dropdown.down(".chzn-select-all")
|
|
||||||
@select_all_link.observe("click", (evt) => this.select_all_options(evt))
|
|
||||||
|
|
||||||
select_all_options: (evt) ->
|
|
||||||
evt.stop()
|
|
||||||
@form_field.select("option").each (option) ->
|
|
||||||
option.selected = true if not option.disabled
|
|
||||||
@form_field.fire("liszt:updated")
|
|
||||||
this.select_all_disable()
|
|
||||||
|
|
||||||
select_all_disable: ->
|
|
||||||
@select_all_link.hide()
|
|
||||||
|
|
||||||
select_all_enable: ->
|
|
||||||
@select_all_link.show()
|
|
||||||
|
|
||||||
select_all_toggle: ->
|
|
||||||
actives = @search_results.select("li.active-result")
|
|
||||||
if not actives.length or @search_field.value.length
|
|
||||||
this.select_all_disable()
|
|
||||||
else
|
|
||||||
this.select_all_enable()
|
|
||||||
|
|
||||||
set_tab_index: (el) ->
|
set_tab_index: (el) ->
|
||||||
if @form_field.tabIndex
|
if @form_field.tabIndex
|
||||||
|
@ -289,20 +261,9 @@ class Chosen extends AbstractChosen
|
||||||
@search_field.removeClassName "default"
|
@search_field.removeClassName "default"
|
||||||
|
|
||||||
search_results_mouseup: (evt) ->
|
search_results_mouseup: (evt) ->
|
||||||
if @enable_group_select
|
target = if evt.target.hasClassName("active-result") then evt.target else evt.target.up(".active-result")
|
||||||
group = if evt.target.hasClassName("group-result") then evt.target else evt.target.up(".group-result")
|
if target
|
||||||
if group
|
@result_highlight = target
|
||||||
possible_children = group.nextSiblings()
|
|
||||||
for child in possible_children
|
|
||||||
if child.hasClassName("active-result")
|
|
||||||
@result_highlight = $(child)
|
|
||||||
this.result_select({metaKey: null})
|
|
||||||
else if child.hasClassName("group-result")
|
|
||||||
return false
|
|
||||||
|
|
||||||
option = if evt.target.hasClassName("active-result") then evt.target else evt.target.up(".active-result")
|
|
||||||
if option
|
|
||||||
@result_highlight = option
|
|
||||||
this.result_select(evt)
|
this.result_select(evt)
|
||||||
|
|
||||||
search_results_mouseover: (evt) ->
|
search_results_mouseover: (evt) ->
|
||||||
|
@ -412,24 +373,35 @@ class Chosen extends AbstractChosen
|
||||||
|
|
||||||
results = 0
|
results = 0
|
||||||
|
|
||||||
@searchText = if @search_field.value is @default_text then "" else @search_field.value.strip().escapeHTML()
|
searchText = if @search_field.value is @default_text then "" else @search_field.value.strip().escapeHTML()
|
||||||
@regex = new RegExp('^' + @searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i')
|
regex = new RegExp('^' + searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i')
|
||||||
@zregex = new RegExp(@searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i')
|
zregex = new RegExp(searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i')
|
||||||
|
|
||||||
for option in @results_data
|
for option in @results_data
|
||||||
if not option.disabled and not option.empty
|
if not option.disabled and not option.empty
|
||||||
if option.group
|
if option.group
|
||||||
this.winnow_option_group(option)
|
$(option.dom_id).hide()
|
||||||
else if not (@is_multiple and option.selected)
|
else if not (@is_multiple and option.selected)
|
||||||
found = this.winnow_search_match(@regex, option.html)
|
found = false
|
||||||
|
|
||||||
result_id = option.dom_id
|
result_id = option.dom_id
|
||||||
|
|
||||||
if found or (option.group_array_index? && @results_data[option.group_array_index].search_match)
|
if regex.test option.html
|
||||||
|
found = true
|
||||||
results += 1
|
results += 1
|
||||||
|
else if option.html.indexOf(" ") >= 0 or option.html.indexOf("[") == 0
|
||||||
if @searchText.length and found
|
#TODO: replace this substitution of /\[\]/ with a list of characters to skip.
|
||||||
text = this.winnow_search_highlight_match(@zregex, option.html, @searchText.length)
|
parts = option.html.replace(/\[|\]/g, "").split(" ")
|
||||||
|
if parts.length
|
||||||
|
for part in parts
|
||||||
|
if regex.test part
|
||||||
|
found = true
|
||||||
|
results += 1
|
||||||
|
|
||||||
|
if found
|
||||||
|
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
|
else
|
||||||
text = option.html
|
text = option.html
|
||||||
|
|
||||||
|
@ -442,19 +414,11 @@ class Chosen extends AbstractChosen
|
||||||
this.result_clear_highlight() if $(result_id) is @result_highlight
|
this.result_clear_highlight() if $(result_id) is @result_highlight
|
||||||
this.result_deactivate $(result_id)
|
this.result_deactivate $(result_id)
|
||||||
|
|
||||||
if results < 1 and @searchText.length
|
if results < 1 and searchText.length
|
||||||
this.no_results(@searchText)
|
this.no_results(searchText)
|
||||||
else
|
else
|
||||||
this.winnow_results_set_highlight()
|
this.winnow_results_set_highlight()
|
||||||
|
|
||||||
winnow_option_group: (group) ->
|
|
||||||
$("#{group.dom_id}").hide()
|
|
||||||
|
|
||||||
group.search_match = this.winnow_search_match(@regex, group.label)
|
|
||||||
|
|
||||||
text = if @searchText.length and group.search_match then this.winnow_search_highlight_match(@zregex, group.label, @searchText.length) else group.label
|
|
||||||
$("#{group.dom_id}").update(text)
|
|
||||||
|
|
||||||
winnow_results_clear: ->
|
winnow_results_clear: ->
|
||||||
@search_field.clear()
|
@search_field.clear()
|
||||||
lis = @search_results.select("li")
|
lis = @search_results.select("li")
|
||||||
|
|
|
@ -8,6 +8,9 @@ class AbstractChosen
|
||||||
|
|
||||||
constructor: (@form_field, @options={}) ->
|
constructor: (@form_field, @options={}) ->
|
||||||
this.set_default_values()
|
this.set_default_values()
|
||||||
|
|
||||||
|
@is_multiple = @form_field.multiple
|
||||||
|
@default_text_default = if @is_multiple then "Select Some Options" else "Select an Option"
|
||||||
|
|
||||||
this.setup()
|
this.setup()
|
||||||
|
|
||||||
|
@ -17,9 +20,6 @@ class AbstractChosen
|
||||||
this.finish_setup()
|
this.finish_setup()
|
||||||
|
|
||||||
set_default_values: ->
|
set_default_values: ->
|
||||||
@is_multiple = @form_field.multiple
|
|
||||||
@default_text_default = if @is_multiple then "Select Some Options" else "Select an Option"
|
|
||||||
|
|
||||||
@click_test_action = (evt) => this.test_active_click(evt)
|
@click_test_action = (evt) => this.test_active_click(evt)
|
||||||
@activate_action = (evt) => this.activate_field(evt)
|
@activate_action = (evt) => this.activate_field(evt)
|
||||||
@active_field = false
|
@active_field = false
|
||||||
|
@ -27,10 +27,8 @@ class AbstractChosen
|
||||||
@results_showing = false
|
@results_showing = false
|
||||||
@result_highlighted = null
|
@result_highlighted = null
|
||||||
@result_single_selected = null
|
@result_single_selected = null
|
||||||
@enable_group_select = @options.enable_group_select || false
|
|
||||||
@allow_single_deselect = if @options.allow_single_deselect? and @form_field.options[0]? and @form_field.options[0].text is "" then @options.allow_single_deselect else false
|
@allow_single_deselect = if @options.allow_single_deselect? and @form_field.options[0]? and @form_field.options[0].text is "" then @options.allow_single_deselect else false
|
||||||
@disable_search_threshold = @options.disable_search_threshold || 0
|
@disable_search_threshold = @options.disable_search_threshold || 0
|
||||||
@enable_select_all = if @options.enable_select_all? and @is_multiple then @options.enable_select_all else false
|
|
||||||
@choices = 0
|
@choices = 0
|
||||||
@results_none_found = @options.no_results_text or "No results match"
|
@results_none_found = @options.no_results_text or "No results match"
|
||||||
|
|
||||||
|
@ -77,24 +75,6 @@ class AbstractChosen
|
||||||
else
|
else
|
||||||
this.results_show()
|
this.results_show()
|
||||||
|
|
||||||
winnow_search_match: (regex, optionText) ->
|
|
||||||
found = false
|
|
||||||
if regex.test optionText
|
|
||||||
found = true
|
|
||||||
else if optionText.indexOf(" ") >= 0 or optionText.indexOf("[") == 0
|
|
||||||
#TODO: replace this substitution of /\[\]/ with a list of characters to skip.
|
|
||||||
parts = optionText.replace(/\[|\]/g, "").split(" ")
|
|
||||||
if parts.length
|
|
||||||
for part in parts
|
|
||||||
if regex.test part
|
|
||||||
found = true
|
|
||||||
return found
|
|
||||||
|
|
||||||
winnow_search_highlight_match: (regex, optionText, searchTextLength) ->
|
|
||||||
startpos = optionText.search regex
|
|
||||||
text = optionText.substr(0, startpos + searchTextLength) + '</em>' + optionText.substr(startpos + searchTextLength)
|
|
||||||
text = text.substr(0, startpos) + '<em>' + text.substr(startpos)
|
|
||||||
|
|
||||||
keyup_checker: (evt) ->
|
keyup_checker: (evt) ->
|
||||||
stroke = evt.which ? evt.keyCode
|
stroke = evt.which ? evt.keyCode
|
||||||
this.search_field_scale()
|
this.search_field_scale()
|
||||||
|
@ -115,8 +95,6 @@ class AbstractChosen
|
||||||
when 9, 38, 40, 16, 91, 17
|
when 9, 38, 40, 16, 91, 17
|
||||||
# don't do anything on these keys
|
# don't do anything on these keys
|
||||||
else this.results_search()
|
else this.results_search()
|
||||||
|
|
||||||
this.select_all_toggle() if @enable_select_all
|
|
||||||
|
|
||||||
generate_field_id: ->
|
generate_field_id: ->
|
||||||
new_id = this.generate_random_id()
|
new_id = this.generate_random_id()
|
||||||
|
|
Loading…
Reference in a new issue