From 31a708028d2cc3fd4829ab81c3dd598df8d1f25e Mon Sep 17 00:00:00 2001 From: Patrick Filler Date: Thu, 22 Sep 2011 15:43:46 -0500 Subject: [PATCH] Update chosen to latest version and use latest version of jQuery --- chosen/chosen.css | 9 +++++++ chosen/chosen.jquery.js | 60 ++++++++++++++++++++++++++--------------- index.html | 2 +- 3 files changed, 49 insertions(+), 22 deletions(-) diff --git a/chosen/chosen.css b/chosen/chosen.css index f68af1b..6d7dc39 100644 --- a/chosen/chosen.css +++ b/chosen/chosen.css @@ -303,6 +303,15 @@ } /* @end */ +/* @group Disabled Support */ +.chzn-disabled { + cursor: default; + opacity:0.5 !important; +} +.chzn-disabled .chzn-single { + cursor: default; +} + /* @group Right to Left */ .chzn-rtl { direction:rtl;text-align: right; } .chzn-rtl .chzn-single { padding-left: 0; padding-right: 8px; } diff --git a/chosen/chosen.jquery.js b/chosen/chosen.jquery.js index 06c86f1..0802d49 100644 --- a/chosen/chosen.jquery.js +++ b/chosen/chosen.jquery.js @@ -44,6 +44,9 @@ this.click_test_action = __bind(function(evt) { return this.test_active_click(evt); }, this); + this.activate_action = __bind(function(evt) { + return this.activate_field(evt); + }, this); this.active_field = false; this.mouse_on_container = false; this.results_showing = false; @@ -60,7 +63,7 @@ this.default_text = this.form_field_jq.data('placeholder') ? this.form_field_jq.data('placeholder') : this.default_text_default; container_div = $("
", { id: this.container_id, - "class": "chzn-container " + (this.is_rtl ? 'chzn-rtl' : ''), + "class": "chzn-container" + (this.is_rtl ? ' chzn-rtl' : ''), style: 'width: ' + this.f_width + 'px;' }); if (this.is_multiple) { @@ -134,30 +137,44 @@ return this.search_field.focus(__bind(function(evt) { return this.input_focus(evt); }, this)); + } + }; + Chosen.prototype.search_field_disabled = function() { + this.is_disabled = this.form_field_jq.attr('disabled'); + if (this.is_disabled) { + this.container.addClass('chzn-disabled'); + this.search_field.attr('disabled', true); + if (!this.is_multiple) { + return this.selected_item.unbind("focus", this.activate_action); + } } else { - return this.selected_item.focus(__bind(function(evt) { - return this.activate_field(evt); - }, this)); + this.container.removeClass('chzn-disabled'); + this.search_field.attr('disabled', false); + if (!this.is_multiple) { + return this.selected_item.bind("focus", this.activate_action); + } } }; Chosen.prototype.container_mousedown = function(evt) { - if (evt && evt.type === "mousedown") { - evt.stopPropagation(); - } - if (!this.pending_destroy_click) { - if (!this.active_field) { - if (this.is_multiple) { - this.search_field.val(""); - } - $(document).click(this.click_test_action); - 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_toggle(); + if (!this.is_disabled) { + if (evt && evt.type === "mousedown") { + evt.stopPropagation(); + } + if (!this.pending_destroy_click) { + if (!this.active_field) { + if (this.is_multiple) { + this.search_field.val(""); + } + $(document).click(this.click_test_action); + 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_toggle(); + } + return this.activate_field(); + } else { + return this.pending_destroy_click = false; } - return this.activate_field(); - } else { - return this.pending_destroy_click = false; } }; Chosen.prototype.mouse_enter = function() { @@ -243,6 +260,7 @@ } } } + this.search_field_disabled(); this.show_search_field_default(); this.search_field_scale(); this.search_results.html(content); @@ -793,4 +811,4 @@ return parser.parsed; }; this.SelectParser = SelectParser; -}).call(this); \ No newline at end of file +}).call(this); diff --git a/index.html b/index.html index 09b380f..d8d5bcb 100644 --- a/index.html +++ b/index.html @@ -1288,7 +1288,7 @@
- +