Permalink
Browse files

Single default class: use cached selectors and clean-up classes only …

…on singles.
  • Loading branch information...
1 parent 283f2a3 commit 753a67714d2c133e521109be1913726f8886b0f6 @pfiller pfiller committed Mar 12, 2012
View
@@ -499,7 +499,7 @@ Copyright (c) 2011 by Harvest
if (data.selected && this.is_multiple) {
this.choice_build(data);
} else if (data.selected && !this.is_multiple) {
- this.selected_item.find("span").text(data.text);
+ this.selected_item.removeClass("chzn-default").find("span").text(data.text);
if (this.allow_single_deselect) this.single_deselect_control_build();
}
}
@@ -661,7 +661,7 @@ Copyright (c) 2011 by Harvest
Chosen.prototype.results_reset = function(evt) {
this.form_field.options[0].selected = true;
this.selected_item.find("span").text(this.default_text);
- this.container.find(".chzn-single").addClass("chzn-default");
+ if (!this.is_multiple) this.selected_item.addClass("chzn-default");
this.show_search_field_default();
$(evt.target).remove();
this.form_field_jq.trigger("change");
@@ -679,9 +679,9 @@ Copyright (c) 2011 by Harvest
} else {
this.search_results.find(".result-selected").removeClass("result-selected");
this.result_single_selected = high;
+ this.selected_item.removeClass("chzn-default");
}
high.addClass("result-selected");
- this.container.find(".chzn-single").removeClass("chzn-default");
position = high_id.substr(high_id.lastIndexOf("_") + 1);
item = this.results_data[position];
item.selected = true;

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -493,7 +493,7 @@ Copyright (c) 2011 by Harvest
if (data.selected && this.is_multiple) {
this.choice_build(data);
} else if (data.selected && !this.is_multiple) {
- this.selected_item.down("span").update(data.html);
+ this.selected_item.removeClassName("chzn-default").down("span").update(data.html);
if (this.allow_single_deselect) this.single_deselect_control_build();
}
}
@@ -659,7 +659,7 @@ Copyright (c) 2011 by Harvest
Chosen.prototype.results_reset = function(evt) {
this.form_field.options[0].selected = true;
this.selected_item.down("span").update(this.default_text);
- this.container.down(".chzn-single").addClassName("chzn-default");
+ if (!this.is_multiple) this.selected_item.addClassName("chzn-default");
this.show_search_field_default();
evt.target.remove();
if (typeof Event.simulate === 'function') this.form_field.simulate("change");
@@ -675,10 +675,10 @@ Copyright (c) 2011 by Harvest
this.result_deactivate(high);
} else {
this.search_results.descendants(".result-selected").invoke("removeClassName", "result-selected");
+ this.selected_item.removeClassName("chzn-default");
this.result_single_selected = high;
}
high.addClassName("result-selected");
- this.container.down(".chzn-single").removeClassName("chzn-default");
position = high.id.substr(high.id.lastIndexOf("_") + 1);
item = this.results_data[position];
item.selected = true;

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -187,7 +187,7 @@ class Chosen extends AbstractChosen
if data.selected and @is_multiple
this.choice_build data
else if data.selected and not @is_multiple
- @selected_item.find("span").text data.text
+ @selected_item.removeClass("chzn-default").find("span").text data.text
this.single_deselect_control_build() if @allow_single_deselect
this.search_field_disabled()
@@ -315,7 +315,7 @@ class Chosen extends AbstractChosen
results_reset: (evt) ->
@form_field.options[0].selected = true
@selected_item.find("span").text @default_text
- @container.find(".chzn-single").addClass("chzn-default")
+ @selected_item.addClass("chzn-default") if not @is_multiple
this.show_search_field_default()
$(evt.target).remove();
@form_field_jq.trigger "change"
@@ -333,9 +333,9 @@ class Chosen extends AbstractChosen
else
@search_results.find(".result-selected").removeClass "result-selected"
@result_single_selected = high
+ @selected_item.removeClass("chzn-default")
high.addClass "result-selected"
- @container.find(".chzn-single").removeClass("chzn-default")
position = high_id.substr(high_id.lastIndexOf("_") + 1 )
item = @results_data[position]
@@ -179,7 +179,7 @@ class Chosen extends AbstractChosen
if data.selected and @is_multiple
this.choice_build data
else if data.selected and not @is_multiple
- @selected_item.down("span").update( data.html )
+ @selected_item.removeClassName("chzn-default").down("span").update( data.html )
this.single_deselect_control_build() if @allow_single_deselect
this.search_field_disabled()
@@ -308,7 +308,7 @@ class Chosen extends AbstractChosen
results_reset: (evt) ->
@form_field.options[0].selected = true
@selected_item.down("span").update(@default_text)
- @container.down(".chzn-single").addClassName("chzn-default")
+ @selected_item.addClassName("chzn-default") if not @is_multiple
this.show_search_field_default()
evt.target.remove()
@form_field.simulate("change") if typeof Event.simulate is 'function'
@@ -323,10 +323,10 @@ class Chosen extends AbstractChosen
this.result_deactivate high
else
@search_results.descendants(".result-selected").invoke "removeClassName", "result-selected"
+ @selected_item.removeClassName("chzn-default")
@result_single_selected = high
high.addClassName("result-selected")
- @container.down(".chzn-single").removeClassName("chzn-default")
position = high.id.substr(high.id.lastIndexOf("_") + 1 )
item = @results_data[position]

0 comments on commit 753a677

Please sign in to comment.