Make sure we have only one deselect control at a time.

Fixes #286 and #296
js_style_fix
Patrick Filler 2011-10-17 12:30:54 -04:00
parent 499c35b62d
commit fa35528d15
6 changed files with 29 additions and 15 deletions

View File

@ -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();
}
}
}
@ -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)) {
@ -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();

File diff suppressed because one or more lines are too long

View File

@ -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();
}
}
}
@ -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)) {
@ -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();

File diff suppressed because one or more lines are too long

View File

@ -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()
@ -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 ""
@ -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()

View File

@ -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()
@ -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
@ -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()