Clicking groups chooses all members of a group.

search_improvements
Patrick Filler 2012-02-27 17:19:06 -05:00
parent 3cae992311
commit d3eb80470c
6 changed files with 72 additions and 26 deletions

View File

@ -623,10 +623,21 @@ Copyright (c) 2011 by Harvest
};
Chosen.prototype.search_results_mouseup = function(evt) {
var target;
target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
if (target.length) {
this.result_highlight = target;
var child, children, group, option, _i, _len;
group = $(evt.target).hasClass("group-result") ? $(evt.target) : $(evt.target).parents(".group-result").first();
if (group.length) {
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);
}
};
@ -760,13 +771,13 @@ Copyright (c) 2011 by Harvest
option = _ref[_i];
if (!option.disabled && !option.empty) {
if (option.group) {
if (this.winnow_option_group(option)) results += 1;
this.winnow_option_group(option);
} else if (!(this.is_multiple && option.selected)) {
found = this.winnow_search_match(this.regex, option.html);
if (found) results += 1;
result_id = option.dom_id;
result = $("#" + result_id);
if (found || ((option.group_array_index != null) && this.results_data[option.group_array_index].search_match)) {
results += 1;
if (this.searchText.length && found) {
text = this.winnow_search_highlight_match(this.zregex, option.html, this.searchText.length);
} else {

File diff suppressed because one or more lines are too long

View File

@ -617,10 +617,25 @@ Copyright (c) 2011 by Harvest
};
Chosen.prototype.search_results_mouseup = function(evt) {
var target;
target = evt.target.hasClassName("active-result") ? evt.target : evt.target.up(".active-result");
if (target) {
this.result_highlight = target;
var child, group, option, possible_children, _i, _len;
group = evt.target.hasClassName("group-result") ? evt.target : evt.target.up(".group-result");
if (group) {
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);
}
};
@ -761,12 +776,12 @@ Copyright (c) 2011 by Harvest
option = _ref[_i];
if (!option.disabled && !option.empty) {
if (option.group) {
if (this.winnow_option_group(option)) results += 1;
this.winnow_option_group(option);
} else if (!(this.is_multiple && option.selected)) {
found = this.winnow_search_match(this.regex, option.html);
if (found) results += 1;
result_id = option.dom_id;
if (found || ((option.group_array_index != null) && this.results_data[option.group_array_index].search_match)) {
results += 1;
if (this.searchText.length && found) {
text = this.winnow_search_highlight_match(this.zregex, option.html, this.searchText.length);
} else {

File diff suppressed because one or more lines are too long

View File

@ -270,9 +270,16 @@ class Chosen extends AbstractChosen
@search_field.removeClass "default"
search_results_mouseup: (evt) ->
target = if $(evt.target).hasClass "active-result" then $(evt.target) else $(evt.target).parents(".active-result").first()
if target.length
@result_highlight = target
group = if $(evt.target).hasClass "group-result" then $(evt.target) else $(evt.target).parents(".group-result").first()
if group.length
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)
search_results_mouseover: (evt) ->
@ -389,15 +396,16 @@ class Chosen extends AbstractChosen
for option in @results_data
if not option.disabled and not option.empty
if option.group
results += 1 if this.winnow_option_group(option)
this.winnow_option_group(option)
else if not (@is_multiple and option.selected)
found = this.winnow_search_match(@regex, option.html)
results += 1 if found
result_id = option.dom_id
result = $("#" + result_id)
if found or (option.group_array_index? && @results_data[option.group_array_index].search_match)
results += 1
if @searchText.length and found
text = this.winnow_search_highlight_match(@zregex, option.html, @searchText.length)
else
@ -420,8 +428,8 @@ class Chosen extends AbstractChosen
$('#' + 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

View File

@ -261,9 +261,20 @@ class Chosen extends AbstractChosen
@search_field.removeClassName "default"
search_results_mouseup: (evt) ->
target = if evt.target.hasClassName("active-result") then evt.target else evt.target.up(".active-result")
if target
@result_highlight = target
group = if evt.target.hasClassName("group-result") then evt.target else evt.target.up(".group-result")
if group
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)
search_results_mouseover: (evt) ->
@ -380,14 +391,15 @@ class Chosen extends AbstractChosen
for option in @results_data
if not option.disabled and not option.empty
if option.group
results += 1 if this.winnow_option_group(option)
this.winnow_option_group(option)
else if not (@is_multiple and option.selected)
found = this.winnow_search_match(@regex, option.html)
results += 1 if found
result_id = option.dom_id
if found or (option.group_array_index? && @results_data[option.group_array_index].search_match)
results += 1
if @searchText.length and found
text = this.winnow_search_highlight_match(@zregex, option.html, @searchText.length)
else