Skip to content

Commit

Permalink
Make sure we have only one deselect control at a time.
Browse files Browse the repository at this point in the history
  • Loading branch information
pfiller committed Oct 17, 2011
1 parent 499c35b commit fa35528
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 15 deletions.
9 changes: 7 additions & 2 deletions chosen/chosen.jquery.js
Expand Up @@ -465,7 +465,7 @@
} else if (data.selected && !this.is_multiple) {
this.selected_item.find("span").text(data.text);
if (this.allow_single_deselect) {
this.selected_item.find("span").first().after("<abbr class=\"search-choice-close\"></abbr>");
this.single_deselect_control_build();
}
}
}
Expand Down Expand Up @@ -644,7 +644,7 @@
} else {
this.selected_item.find("span").first().text(item.text);
if (this.allow_single_deselect) {
this.selected_item.find("span").first().after("<abbr class=\"search-choice-close\"></abbr>");
this.single_deselect_control_build();
}
}
if (!(evt.metaKey && this.is_multiple)) {
Expand Down Expand Up @@ -673,6 +673,11 @@
this.form_field_jq.trigger("change");
return this.search_field_scale();
};
Chosen.prototype.single_deselect_control_build = function() {
if (this.allow_single_deselect && this.selected_item.find("abbr").length < 1) {
return this.selected_item.find("span").first().after("<abbr class=\"search-choice-close\"></abbr>");
}
};
Chosen.prototype.winnow_results = function() {
var found, option, part, parts, regex, result_id, results, searchText, startTime, startpos, text, zregex, _i, _j, _len, _len2, _ref;
startTime = new Date();
Expand Down
2 changes: 1 addition & 1 deletion chosen/chosen.jquery.min.js

Large diffs are not rendered by default.

15 changes: 9 additions & 6 deletions chosen/chosen.proto.js
Expand Up @@ -458,9 +458,7 @@
} else if (data.selected && !this.is_multiple) {
this.selected_item.down("span").update(data.html);
if (this.allow_single_deselect) {
this.selected_item.down("span").insert({
after: "<abbr class=\"search-choice-close\"></abbr>"
});
this.single_deselect_control_build();
}
}
}
Expand Down Expand Up @@ -642,9 +640,7 @@
} else {
this.selected_item.down("span").update(item.html);
if (this.allow_single_deselect) {
this.selected_item.down("span").insert({
after: "<abbr class=\"search-choice-close\"></abbr>"
});
this.single_deselect_control_build();
}
}
if (!(evt.metaKey && this.is_multiple)) {
Expand Down Expand Up @@ -677,6 +673,13 @@
}
return this.search_field_scale();
};
Chosen.prototype.single_deselect_control_build = function() {
if (this.allow_single_deselect && !this.selected_item.down("abbr")) {
return this.selected_item.down("span").insert({
after: "<abbr class=\"search-choice-close\"></abbr>"
});
}
};
Chosen.prototype.winnow_results = function() {
var found, option, part, parts, regex, result_id, results, searchText, startTime, startpos, text, zregex, _i, _j, _len, _len2, _ref;
startTime = new Date();
Expand Down
2 changes: 1 addition & 1 deletion chosen/chosen.proto.min.js

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions coffee/chosen.jquery.coffee
Expand Up @@ -184,7 +184,7 @@ class Chosen extends AbstractChosen
this.choice_build data
else if data.selected and not @is_multiple
@selected_item.find("span").text data.text
@selected_item.find("span").first().after "<abbr class=\"search-choice-close\"></abbr>" if @allow_single_deselect
this.single_deselect_control_build() if @allow_single_deselect

this.search_field_disabled()
this.show_search_field_default()
Expand Down Expand Up @@ -341,8 +341,8 @@ class Chosen extends AbstractChosen
this.choice_build item
else
@selected_item.find("span").first().text item.text
@selected_item.find("span").first().after "<abbr class=\"search-choice-close\"></abbr>" if @allow_single_deselect

this.single_deselect_control_build() if @allow_single_deselect
this.results_hide() unless evt.metaKey and @is_multiple

@search_field.val ""
Expand Down Expand Up @@ -370,6 +370,9 @@ class Chosen extends AbstractChosen
@form_field_jq.trigger "change"
this.search_field_scale()

single_deselect_control_build: ->
@selected_item.find("span").first().after "<abbr class=\"search-choice-close\"></abbr>" if @allow_single_deselect and @selected_item.find("abbr").length < 1

winnow_results: ->
startTime = new Date()
this.no_results_clear()
Expand Down
7 changes: 5 additions & 2 deletions coffee/chosen.proto.coffee
Expand Up @@ -175,7 +175,7 @@ class Chosen extends AbstractChosen
this.choice_build data
else if data.selected and not @is_multiple
@selected_item.down("span").update( data.html )
@selected_item.down("span").insert { after: "<abbr class=\"search-choice-close\"></abbr>" } if @allow_single_deselect
this.single_deselect_control_build() if @allow_single_deselect

this.search_field_disabled()
this.show_search_field_default()
Expand Down Expand Up @@ -331,7 +331,7 @@ class Chosen extends AbstractChosen
this.choice_build item
else
@selected_item.down("span").update(item.html)
@selected_item.down("span").insert { after: "<abbr class=\"search-choice-close\"></abbr>" } if @allow_single_deselect
this.single_deselect_control_build() if @allow_single_deselect

this.results_hide() unless evt.metaKey and @is_multiple

Expand Down Expand Up @@ -359,6 +359,9 @@ class Chosen extends AbstractChosen

@form_field.simulate("change") if typeof Event.simulate is 'function'
this.search_field_scale()

single_deselect_control_build: ->
@selected_item.down("span").insert { after: "<abbr class=\"search-choice-close\"></abbr>" } if @allow_single_deselect and not @selected_item.down("abbr")

winnow_results: ->
startTime = new Date()
Expand Down

0 comments on commit fa35528

Please sign in to comment.