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,6 +625,7 @@ Copyright (c) 2011 by Harvest
Chosen.prototype.search_results_mouseup = function(evt) {
var child, children, group, option, _i, _len;
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");
@ -635,6 +637,7 @@ Copyright (c) 2011 by Harvest
});
}
}
}
option = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
if (option.length) {
this.result_highlight = option;

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,6 +619,7 @@ Copyright (c) 2011 by Harvest
Chosen.prototype.search_results_mouseup = function(evt) {
var child, group, option, possible_children, _i, _len;
if (this.enable_group_select) {
group = evt.target.hasClassName("group-result") ? evt.target : evt.target.up(".group-result");
if (group) {
possible_children = group.nextSiblings();
@ -633,6 +635,7 @@ Copyright (c) 2011 by Harvest
}
}
}
}
option = evt.target.hasClassName("active-result") ? evt.target : evt.target.up(".active-result");
if (option) {
this.result_highlight = option;

File diff suppressed because one or more lines are too long

View File

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

View File

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

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