1
0
mirror of synced 2025-02-09 16:49:24 +03:00

Less aggresive keyboard deletes and carret stays

This commit is contained in:
Niels Kühnel 2013-05-03 11:51:41 +02:00
parent 877c1d90c5
commit 870b1b7165
2 changed files with 13 additions and 24 deletions

View File

@ -1,4 +1,4 @@
/* /*
Version: @@ver@@ Timestamp: @@timestamp@@ Version: @@ver@@ Timestamp: @@timestamp@@
*/ */
.select2-container { .select2-container {
@ -497,7 +497,6 @@ disabled look for disabled choices in the results dropdown
margin: 0; margin: 0;
padding: 0; padding: 0;
white-space: nowrap; white-space: nowrap;
position: relative;
} }
.select2-container-multi .select2-choices .select2-search-field input { .select2-container-multi .select2-choices .select2-search-field input {
@ -515,16 +514,6 @@ disabled look for disabled choices in the results dropdown
background: transparent !important; background: transparent !important;
} }
.select2-container-multi .select2-choices .select2-search-field .carret-hider {
position: absolute;
background-color: white;
top: 0;
left: 0;
width: 6px;
height: 100%;
display: none;
}
.select2-container-multi .select2-choices .select2-search-field input.select2-active { .select2-container-multi .select2-choices .select2-search-field input.select2-active {
background: #fff url('select2-spinner.gif') no-repeat 100% !important; background: #fff url('select2-spinner.gif') no-repeat 100% !important;
} }

View File

@ -1,4 +1,4 @@
/* /*
Copyright 2012 Igor Vaynberg Copyright 2012 Igor Vaynberg
Version: @@ver@@ Timestamp: @@timestamp@@ Version: @@ver@@ Timestamp: @@timestamp@@
@ -1237,7 +1237,7 @@ the specific language governing permissions and limitations under the Apache Lic
}, },
// abstract // abstract
close: function (keepSearchText) { close: function () {
if (!this.opened()) return; if (!this.opened()) return;
var cid = this.containerId, var cid = this.containerId,
@ -1256,9 +1256,8 @@ the specific language governing permissions and limitations under the Apache Lic
this.container.removeClass("select2-dropdown-open"); this.container.removeClass("select2-dropdown-open");
this.results.empty(); this.results.empty();
if (!keepSearchText) {
this.clearSearch(); this.clearSearch();
}
this.search.removeClass("select2-active"); this.search.removeClass("select2-active");
this.opts.element.trigger($.Event("close")); this.opts.element.trigger($.Event("close"));
}, },
@ -2150,7 +2149,6 @@ the specific language governing permissions and limitations under the Apache Lic
" <ul class='select2-choices'>", " <ul class='select2-choices'>",
//"<li class='select2-search-choice'><span>California</span><a href="javascript:void(0)" class="select2-search-choice-close"></a></li>" , //"<li class='select2-search-choice'><span>California</span><a href="javascript:void(0)" class="select2-search-choice-close"></a></li>" ,
" <li class='select2-search-field'>" , " <li class='select2-search-field'>" ,
" <div class='carret-hider'></div>",
" <input type='text' autocomplete='off' class='select2-input'>" , " <input type='text' autocomplete='off' class='select2-input'>" ,
" </li>" , " </li>" ,
"</ul>" , "</ul>" ,
@ -2207,8 +2205,6 @@ the specific language governing permissions and limitations under the Apache Lic
selectChoice: function (choice) { selectChoice: function (choice) {
this.carretHider.css("display", "none");
var selected = this.container.find(".select2-search-choice-focus"); var selected = this.container.find(".select2-search-choice-focus");
if (selected.length && choice && choice[0] == selected[0]) { if (selected.length && choice && choice[0] == selected[0]) {
@ -2218,10 +2214,9 @@ the specific language governing permissions and limitations under the Apache Lic
} }
selected.removeClass("select2-search-choice-focus"); selected.removeClass("select2-search-choice-focus");
if (choice && choice.length) { if (choice && choice.length) {
this.close(true); this.close();
choice.addClass("select2-search-choice-focus"); choice.addClass("select2-search-choice-focus");
this.opts.element.trigger("choice-selected", choice); this.opts.element.trigger("choice-selected", choice);
this.carretHider.css("display", "block");
} }
} }
}, },
@ -2233,7 +2228,6 @@ the specific language governing permissions and limitations under the Apache Lic
this.searchContainer = this.container.find(".select2-search-field"); this.searchContainer = this.container.find(".select2-search-field");
this.selection = selection = this.container.find(selector); this.selection = selection = this.container.find(selector);
this.carretHider = $(".carret-hider", this.container);
var _this = this; var _this = this;
this.selection.on("mousedown", ".select2-search-choice", function (e) { this.selection.on("mousedown", ".select2-search-choice", function (e) {
@ -2261,9 +2255,11 @@ the specific language governing permissions and limitations under the Apache Lic
this.search.attr("tabindex", this.elementTabIndex); this.search.attr("tabindex", this.elementTabIndex);
this.keydowns = 0;
this.search.bind("keydown", this.bind(function (e) { this.search.bind("keydown", this.bind(function (e) {
if (!this.enabled) return; if (!this.enabled) return;
++this.keydowns;
var selected = selection.find(".select2-search-choice-focus"); var selected = selection.find(".select2-search-choice-focus");
var prev = selected.prev(".select2-search-choice:not(.select2-locked)"); var prev = selected.prev(".select2-search-choice:not(.select2-locked)");
var next = selected.next(".select2-search-choice:not(.select2-locked)"); var next = selected.next(".select2-search-choice:not(.select2-locked)");
@ -2296,7 +2292,7 @@ the specific language governing permissions and limitations under the Apache Lic
this.open(); this.open();
} }
return; return;
} else if ((e.which === KEY.BACKSPACE } else if (((e.which === KEY.BACKSPACE && this.keydowns == 1)
|| e.which == KEY.LEFT) && (pos.offset == 0 && !pos.length)) { || e.which == KEY.LEFT) && (pos.offset == 0 && !pos.length)) {
this.selectChoice(selection.find(".select2-search-choice:not(.select2-locked)").last()); this.selectChoice(selection.find(".select2-search-choice:not(.select2-locked)").last());
@ -2352,7 +2348,11 @@ the specific language governing permissions and limitations under the Apache Lic
})); }));
this.search.bind("keyup", this.bind(this.resizeSearch)); this.search.bind("keyup", this.bind(function (e) {
this.keydowns = 0;
this.resizeSearch();
})
);
this.search.bind("blur", this.bind(function(e) { this.search.bind("blur", this.bind(function(e) {
this.container.removeClass("select2-container-active"); this.container.removeClass("select2-container-active");