Make group selection optional.

search_improvements
Patrick Filler 2012-02-28 10:52:03 -05:00
parent d3eb80470c
commit 2f196b118c
7 changed files with 47 additions and 39 deletions

View File

@ -127,6 +127,7 @@ Copyright (c) 2011 by Harvest
this.results_showing = false;
this.result_highlighted = 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.disable_search_threshold = this.options.disable_search_threshold || 0;
this.choices = 0;
@ -624,15 +625,17 @@ Copyright (c) 2011 by Harvest
Chosen.prototype.search_results_mouseup = function(evt) {
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
});
if (this.enable_group_select) {
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();

File diff suppressed because one or more lines are too long

View File

@ -127,6 +127,7 @@ Copyright (c) 2011 by Harvest
this.results_showing = false;
this.result_highlighted = 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.disable_search_threshold = this.options.disable_search_threshold || 0;
this.choices = 0;
@ -618,18 +619,20 @@ Copyright (c) 2011 by Harvest
Chosen.prototype.search_results_mouseup = function(evt) {
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;
if (this.enable_group_select) {
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;
}
}
}
}

File diff suppressed because one or more lines are too long

View File

@ -270,12 +270,13 @@ class Chosen extends AbstractChosen
@search_field.removeClass "default"
search_results_mouseup: (evt) ->
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})
if @enable_group_select
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

View File

@ -261,16 +261,16 @@ class Chosen extends AbstractChosen
@search_field.removeClassName "default"
search_results_mouseup: (evt) ->
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
if @enable_group_select
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

View File

@ -27,6 +27,7 @@ class AbstractChosen
@results_showing = false
@result_highlighted = 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
@disable_search_threshold = @options.disable_search_threshold || 0
@choices = 0