From 110466a38f31c37b6edef7d27fc8398e32d8acf0 Mon Sep 17 00:00:00 2001 From: Chris Lee Date: Fri, 22 Jul 2011 17:27:08 -0700 Subject: [PATCH] Ctrl/command-click to select without closing list. Related to #23 --- chosen/chosen.jquery.js | 10 ++++++---- chosen/chosen.proto.js | 10 ++++++---- coffee/chosen.jquery.coffee | 10 ++++++---- coffee/chosen.proto.coffee | 10 ++++++---- 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/chosen/chosen.jquery.js b/chosen/chosen.jquery.js index 21e822a..54edd98 100644 --- a/chosen/chosen.jquery.js +++ b/chosen/chosen.jquery.js @@ -351,7 +351,7 @@ target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first(); if (target.length) { this.result_highlight = target; - return this.result_select(); + return this.result_select(evt); } }; Chosen.prototype.search_results_mouseover = function(evt) { @@ -396,7 +396,7 @@ this.result_deselect(link.attr("rel")); return link.parents('li').first().remove(); }; - Chosen.prototype.result_select = function() { + Chosen.prototype.result_select = function(evt) { var high, high_id, item, position; if (this.result_highlight) { high = this.result_highlight; @@ -417,7 +417,9 @@ } else { this.selected_item.find("span").first().text(item.text); } - this.results_hide(); + if (!evt.metaKey) { + this.results_hide(); + } this.search_field.val(""); this.form_field_jq.trigger("change"); return this.search_field_scale(); @@ -604,7 +606,7 @@ case 13: evt.preventDefault(); if (this.results_showing) { - return this.result_select(); + return this.result_select(evt); } break; case 27: diff --git a/chosen/chosen.proto.js b/chosen/chosen.proto.js index e3c0fbd..a6d482a 100644 --- a/chosen/chosen.proto.js +++ b/chosen/chosen.proto.js @@ -338,7 +338,7 @@ target = evt.target.hasClassName("active-result") ? evt.target : evt.target.up(".active-result"); if (target) { this.result_highlight = target; - return this.result_select(); + return this.result_select(evt); } }; Chosen.prototype.search_results_mouseover = function(evt) { @@ -389,7 +389,7 @@ this.result_deselect(link.readAttribute("rel")); return link.up('li').remove(); }; - Chosen.prototype.result_select = function() { + Chosen.prototype.result_select = function(evt) { var high, item, position; if (this.result_highlight) { high = this.result_highlight; @@ -409,7 +409,9 @@ } else { this.selected_item.down("span").update(item.text); } - this.results_hide(); + if (!evt.metaKey) { + this.results_hide(); + } this.search_field.value = ""; if (typeof Event.simulate === 'function') { this.form_field.simulate("change"); @@ -607,7 +609,7 @@ case 13: evt.preventDefault(); if (this.results_showing) { - return this.result_select(); + return this.result_select(evt); } break; case 27: diff --git a/coffee/chosen.jquery.coffee b/coffee/chosen.jquery.coffee index 0d6596a..df491a6 100644 --- a/coffee/chosen.jquery.coffee +++ b/coffee/chosen.jquery.coffee @@ -302,7 +302,7 @@ class Chosen target = if $(evt.target).hasClass "active-result" then $(evt.target) else $(evt.target).parents(".active-result").first() if target.length @result_highlight = target - this.result_select() + this.result_select(evt) search_results_mouseover: (evt) -> target = if $(evt.target).hasClass "active-result" then $(evt.target) else $(evt.target).parents(".active-result").first() @@ -338,7 +338,7 @@ class Chosen this.result_deselect (link.attr "rel") link.parents('li').first().remove() - result_select: -> + result_select: (evt) -> if @result_highlight high = @result_highlight high_id = high.attr "id" @@ -363,7 +363,9 @@ class Chosen else @selected_item.find("span").first().text item.text - this.results_hide() + if not evt.metaKey + this.results_hide() + @search_field.val "" @form_field_jq.trigger "change" @@ -519,7 +521,7 @@ class Chosen this.results_search() when 13 evt.preventDefault() - this.result_select() if this.results_showing + this.result_select(evt) if this.results_showing when 27 this.results_hide() if @results_showing when 9, 38, 40, 16 diff --git a/coffee/chosen.proto.coffee b/coffee/chosen.proto.coffee index 87a22b6..83c9739 100644 --- a/coffee/chosen.proto.coffee +++ b/coffee/chosen.proto.coffee @@ -295,7 +295,7 @@ class Chosen target = if evt.target.hasClassName("active-result") then evt.target else evt.target.up(".active-result") if target @result_highlight = target - this.result_select() + this.result_select(evt) search_results_mouseover: (evt) -> target = if evt.target.hasClassName("active-result") then evt.target else evt.target.up(".active-result") @@ -331,7 +331,7 @@ class Chosen this.result_deselect link.readAttribute("rel") link.up('li').remove() - result_select: -> + result_select: (evt) -> if @result_highlight high = @result_highlight this.result_clear_highlight() @@ -354,7 +354,9 @@ class Chosen else @selected_item.down("span").update(item.text) - this.results_hide() + if not evt.metaKey + this.results_hide() + @search_field.value = "" @form_field.simulate("change") if typeof Event.simulate is 'function' @@ -512,7 +514,7 @@ class Chosen this.results_search() when 13 evt.preventDefault() - this.result_select() if this.results_showing + this.result_select(evt) if this.results_showing when 27 this.results_hide() if @results_showing when 9, 38, 40, 16