Highlight selected option in a single select on initial load.

Closes Gh-103
This commit is contained in:
Patrick Filler 2011-08-01 16:14:13 -04:00
parent c41e05e824
commit 0812bc3d64
6 changed files with 32 additions and 17 deletions

View file

@ -1,7 +1,7 @@
// Chosen, a Select Box Enhancer for jQuery and Protoype
// by Patrick Filler for Harvest, http://getharvest.com
//
// Version 0.9
// Version 0.9.1
// Full source at https://github.com/harvesthq/chosen
// Copyright (c) 2011 Harvest http://getharvest.com
@ -530,10 +530,11 @@
return _results;
};
Chosen.prototype.winnow_results_set_highlight = function() {
var do_high;
var do_high, selected_results;
if (!this.result_highlight) {
do_high = this.search_results.find(".active-result").first();
if (do_high) {
selected_results = !this.is_multiple ? this.search_results.find(".result-selected") : [];
do_high = selected_results.length ? selected_results.first() : this.search_results.find(".active-result").first();
if (do_high != null) {
return this.result_do_highlight(do_high);
}
}

File diff suppressed because one or more lines are too long

View file

@ -1,7 +1,7 @@
// Chosen, a Select Box Enhancer for jQuery and Protoype
// by Patrick Filler for Harvest, http://getharvest.com
//
// Version 0.9
// Version 0.9.1
// Full source at https://github.com/harvesthq/chosen
// Copyright (c) 2011 Harvest http://getharvest.com
@ -23,6 +23,7 @@
this.default_text_default = this.form_field.multiple ? "Select Some Options" : "Select an Option";
this.set_up_html();
this.register_observers();
this.form_field.addClassName("chzn-done");
}
Chosen.prototype.set_default_values = function() {
this.click_test_action = __bind(function(evt) {
@ -526,8 +527,13 @@
Chosen.prototype.winnow_results_set_highlight = function() {
var do_high;
if (!this.result_highlight) {
do_high = this.search_results.down(".active-result");
if (do_high) {
if (!this.is_multiple) {
do_high = this.search_results.down(".result-selected");
}
if (!(do_high != null)) {
do_high = this.search_results.down(".active-result");
}
if (do_high != null) {
return this.result_do_highlight(do_high);
}
}

File diff suppressed because one or more lines are too long

View file

@ -457,9 +457,11 @@ class Chosen
winnow_results_set_highlight: ->
if not @result_highlight
do_high = @search_results.find(".active-result").first()
if(do_high)
this.result_do_highlight do_high
selected_results = if not @is_multiple then @search_results.find(".result-selected") else []
do_high = if selected_results.length then selected_results.first() else @search_results.find(".active-result").first()
this.result_do_highlight do_high if do_high?
no_results: (terms) ->
no_results_html = $('<li class="no-results">No results match "<span></span>"</li>')

View file

@ -17,6 +17,7 @@ class Chosen
this.set_up_html()
this.register_observers()
@form_field.addClassName "chzn-done"
set_default_values: ->
@ -450,9 +451,14 @@ class Chosen
winnow_results_set_highlight: ->
if not @result_highlight
do_high = @search_results.down(".active-result")
if(do_high)
this.result_do_highlight do_high
if not @is_multiple
do_high = @search_results.down(".result-selected")
if not do_high?
do_high = @search_results.down(".active-result")
this.result_do_highlight do_high if do_high?
no_results: (terms) ->
@search_results.insert @no_results_temp.evaluate( terms: terms )