From ed9e82a8165c51754e08c414e958a53b04675fe9 Mon Sep 17 00:00:00 2001 From: Patrick Filler Date: Mon, 18 Jul 2011 18:47:40 -0400 Subject: [PATCH] Yes! A second click on the dropdown arrow _should_ collapse the dropdown box. Closes gh-1 --- chosen/chosen.jquery.js | 9 ++++++++- chosen/chosen.proto.js | 9 ++++++++- coffee/chosen.jquery.coffee | 8 +++++++- coffee/chosen.proto.coffee | 8 +++++++- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/chosen/chosen.jquery.js b/chosen/chosen.jquery.js index c7053e7..9dc179e 100644 --- a/chosen/chosen.jquery.js +++ b/chosen/chosen.jquery.js @@ -137,7 +137,7 @@ this.results_show(); } else if (!this.is_multiple && evt && ($(evt.target) === this.selected_item || $(evt.target).parents("a.chzn-single").length)) { evt.preventDefault(); - this.results_show(); + this.results_toggle(); } return this.activate_field(); } else { @@ -280,6 +280,13 @@ } return this.result_highlight = null; }; + Chosen.prototype.results_toggle = function() { + if (this.results_showing) { + return this.results_hide(); + } else { + return this.results_show(); + } + }; Chosen.prototype.results_show = function() { var dd_top; if (!this.is_multiple) { diff --git a/chosen/chosen.proto.js b/chosen/chosen.proto.js index 11e66d8..7dcc64d 100644 --- a/chosen/chosen.proto.js +++ b/chosen/chosen.proto.js @@ -134,7 +134,7 @@ document.observe("click", this.click_test_action); this.results_show(); } else if (!this.is_multiple && evt && (evt.target === this.selected_item || evt.target.up("a.chzn-single"))) { - this.results_show(); + this.results_toggle(); } return this.activate_field(); } else { @@ -275,6 +275,13 @@ } return this.result_highlight = null; }; + Chosen.prototype.results_toggle = function() { + if (this.results_showing) { + return this.results_hide(); + } else { + return this.results_show(); + } + }; Chosen.prototype.results_show = function() { var dd_top; if (!this.is_multiple) { diff --git a/coffee/chosen.jquery.coffee b/coffee/chosen.jquery.coffee index e31b794..ccbef06 100644 --- a/coffee/chosen.jquery.coffee +++ b/coffee/chosen.jquery.coffee @@ -119,7 +119,7 @@ class Chosen this.results_show() else if not @is_multiple and evt and ($(evt.target) is @selected_item || $(evt.target).parents("a.chzn-single").length) evt.preventDefault() - this.results_show() + this.results_toggle() this.activate_field() else @@ -248,6 +248,12 @@ class Chosen @result_highlight.removeClass "highlighted" if @result_highlight @result_highlight = null + results_toggle: -> + if @results_showing + this.results_hide() + else + this.results_show() + results_show: -> if not @is_multiple @selected_item.addClass "chzn-single-with-drop" diff --git a/coffee/chosen.proto.coffee b/coffee/chosen.proto.coffee index 94895bf..10b23fc 100644 --- a/coffee/chosen.proto.coffee +++ b/coffee/chosen.proto.coffee @@ -114,7 +114,7 @@ class Chosen document.observe "click", @click_test_action this.results_show() else if not @is_multiple and evt and (evt.target is @selected_item || evt.target.up("a.chzn-single")) - this.results_show() + this.results_toggle() this.activate_field() else @@ -242,6 +242,12 @@ class Chosen @result_highlight.removeClassName('highlighted') if @result_highlight @result_highlight = null + results_toggle: -> + if @results_showing + this.results_hide() + else + this.results_show() + results_show: -> if not @is_multiple @selected_item.addClassName('chzn-single-with-drop')