Parcourir la source

tweak to issue #85 do not highlight items based on keypresses

Igor Vaynberg il y a 13 ans
Parent
commit
47064b2483
2 fichiers modifiés avec 7 ajouts et 21 suppressions
  1. 1 1
      select2.css
  2. 6 20
      select2.js

+ 1 - 1
select2.css

@@ -144,7 +144,7 @@ Version: @@ver@@ Timestamp: @@timestamp@@
   padding-right: 4px;
 }
 
-.select2-container .select2-hide-search {
+.select2-container .select2-search-hidden {
   display: block;
   position: absolute;
   left: -10000px;

+ 6 - 20
select2.js

@@ -712,6 +712,11 @@
         updateResults: function (initial) {
             var search = this.search, results = this.results, opts = this.opts, self=this;
 
+            // if the search is currently hidden we do not alter the results
+            if (initial !== true && this.showSearchInput === false) {
+                return;
+            }
+
             search.addClass("select2-active");
 
             function render(html) {
@@ -735,25 +740,6 @@
                 var parts = [], // html parts
                     def; // default choice
 
-				// If we aren't showing the search input, do not filter items
-				// but do highlight an item matching current search
-				if(initial !== true && !this.showSearchInput){
-					if(data.results.length > 0){
-						var key = data.results[0].id,
-							self = this;
-						this.results.find("li").each(function(i, li){
-							if($(li).data("select2-data").id == key){
-								self.highlight(i);
-								return false;
-							}
-						});
-					} else {
-						// if the search doesn't match, reset so user can search again
-						search.val("");
-					}
-					return;
-				}
-
                 // create a default choice and prepend it to the list
                 if (this.opts.createSearchChoice && search.val() !== "") {
                     def = this.opts.createSearchChoice.call(null, search.val(), data.results);
@@ -1042,7 +1028,7 @@
 
             if (initial === true) {
                 showSearchInput = this.showSearchInput = data.results.length >= this.opts.minimumResultsForSearch;
-                this.search.parent()[showSearchInput ? "removeClass" : "addClass"]("select2-hide-search");
+                this.container.find(".select2-search")[showSearchInput ? "removeClass" : "addClass"]("select2-search-hidden");
 
                 //add "select2-with-searchbox" to the container if search box is shown
                 this.container[showSearchInput ? "addClass" : "removeClass"]("select2-with-searchbox");