Make group selection optional.
This commit is contained in:
parent
d3eb80470c
commit
2f196b118c
7 changed files with 47 additions and 39 deletions
|
@ -127,6 +127,7 @@ 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.choices = 0;
|
this.choices = 0;
|
||||||
|
@ -624,15 +625,17 @@ 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 child, children, group, option, _i, _len;
|
||||||
group = $(evt.target).hasClass("group-result") ? $(evt.target) : $(evt.target).parents(".group-result").first();
|
if (this.enable_group_select) {
|
||||||
if (group.length) {
|
group = $(evt.target).hasClass("group-result") ? $(evt.target) : $(evt.target).parents(".group-result").first();
|
||||||
children = group.nextUntil(".group-result", ".active-result");
|
if (group.length) {
|
||||||
for (_i = 0, _len = children.length; _i < _len; _i++) {
|
children = group.nextUntil(".group-result", ".active-result");
|
||||||
child = children[_i];
|
for (_i = 0, _len = children.length; _i < _len; _i++) {
|
||||||
this.result_highlight = $(child);
|
child = children[_i];
|
||||||
this.result_select({
|
this.result_highlight = $(child);
|
||||||
metaKey: null
|
this.result_select({
|
||||||
});
|
metaKey: null
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
option = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
|
option = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
|
||||||
|
|
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
|
@ -127,6 +127,7 @@ 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.choices = 0;
|
this.choices = 0;
|
||||||
|
@ -618,18 +619,20 @@ 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 child, group, option, possible_children, _i, _len;
|
||||||
group = evt.target.hasClassName("group-result") ? evt.target : evt.target.up(".group-result");
|
if (this.enable_group_select) {
|
||||||
if (group) {
|
group = evt.target.hasClassName("group-result") ? evt.target : evt.target.up(".group-result");
|
||||||
possible_children = group.nextSiblings();
|
if (group) {
|
||||||
for (_i = 0, _len = possible_children.length; _i < _len; _i++) {
|
possible_children = group.nextSiblings();
|
||||||
child = possible_children[_i];
|
for (_i = 0, _len = possible_children.length; _i < _len; _i++) {
|
||||||
if (child.hasClassName("active-result")) {
|
child = possible_children[_i];
|
||||||
this.result_highlight = $(child);
|
if (child.hasClassName("active-result")) {
|
||||||
this.result_select({
|
this.result_highlight = $(child);
|
||||||
metaKey: null
|
this.result_select({
|
||||||
});
|
metaKey: null
|
||||||
} else if (child.hasClassName("group-result")) {
|
});
|
||||||
return false;
|
} else if (child.hasClassName("group-result")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
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
|
@ -270,12 +270,13 @@ class Chosen extends AbstractChosen
|
||||||
@search_field.removeClass "default"
|
@search_field.removeClass "default"
|
||||||
|
|
||||||
search_results_mouseup: (evt) ->
|
search_results_mouseup: (evt) ->
|
||||||
group = if $(evt.target).hasClass "group-result" then $(evt.target) else $(evt.target).parents(".group-result").first()
|
if @enable_group_select
|
||||||
if group.length
|
group = if $(evt.target).hasClass "group-result" then $(evt.target) else $(evt.target).parents(".group-result").first()
|
||||||
children = group.nextUntil(".group-result", ".active-result")
|
if group.length
|
||||||
for child in children
|
children = group.nextUntil(".group-result", ".active-result")
|
||||||
@result_highlight = $(child)
|
for child in children
|
||||||
this.result_select({metaKey: null})
|
@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()
|
option = if $(evt.target).hasClass "active-result" then $(evt.target) else $(evt.target).parents(".active-result").first()
|
||||||
if option.length
|
if option.length
|
||||||
|
|
|
@ -261,16 +261,16 @@ class Chosen extends AbstractChosen
|
||||||
@search_field.removeClassName "default"
|
@search_field.removeClassName "default"
|
||||||
|
|
||||||
search_results_mouseup: (evt) ->
|
search_results_mouseup: (evt) ->
|
||||||
|
if @enable_group_select
|
||||||
group = if evt.target.hasClassName("group-result") then evt.target else evt.target.up(".group-result")
|
group = if evt.target.hasClassName("group-result") then evt.target else evt.target.up(".group-result")
|
||||||
if group
|
if group
|
||||||
possible_children = group.nextSiblings()
|
possible_children = group.nextSiblings()
|
||||||
for child in possible_children
|
for child in possible_children
|
||||||
if child.hasClassName("active-result")
|
if child.hasClassName("active-result")
|
||||||
@result_highlight = $(child)
|
@result_highlight = $(child)
|
||||||
this.result_select({metaKey: null})
|
this.result_select({metaKey: null})
|
||||||
else if child.hasClassName("group-result")
|
else if child.hasClassName("group-result")
|
||||||
return false
|
return false
|
||||||
|
|
||||||
option = if evt.target.hasClassName("active-result") then evt.target else evt.target.up(".active-result")
|
option = if evt.target.hasClassName("active-result") then evt.target else evt.target.up(".active-result")
|
||||||
if option
|
if option
|
||||||
|
|
|
@ -27,6 +27,7 @@ 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
|
||||||
@choices = 0
|
@choices = 0
|
||||||
|
|
Loading…
Reference in a new issue