Browse Source

prevent scrollback left on opening. fixes #467

Igor Vaynberg 12 năm trước cách đây
mục cha
commit
43e6b86f75
2 tập tin đã thay đổi với 14 bổ sung18 xóa
  1. 6 12
      select2.css
  2. 8 6
      select2.js

+ 6 - 12
select2.css

@@ -223,12 +223,6 @@ Version: @@ver@@ Timestamp: @@timestamp@@
     white-space: nowrap;
 }
 
-.select2-search-hidden {
-    display: block;
-    position: absolute;
-    left: -10000px;
-}
-
 .select2-search input {
     width: 100%;
     height: auto !important;
@@ -619,16 +613,16 @@ disabled look for disabled choices in the results dropdown
 }
 
 .select2-offscreen {
-    border: 0;
     clip: rect(0 0 0 0);
-    height: 1;
+    width: 1px;
+    height: 1px;
+    border: 0;
     margin: 0;
-    overflow: hidden;
     padding: 0;
+    overflow: hidden;
     position: absolute;
-    width: 1;
-    display:block;
-    left: -10000px;
+    outline: none;
+    left: 0px;
 }
 
 .select2-display-none {

+ 8 - 6
select2.js

@@ -1775,7 +1775,7 @@ the specific language governing permissions and limitations under the Apache Lic
                 container = this.container,
                 dropdown = this.dropdown;
 
-            this.showSearch(this.opts.minimumResultsForSearch >= 0);
+            this.showSearch(false);
 
             this.selection = selection = container.find(".select2-choice");
 
@@ -2038,12 +2038,13 @@ the specific language governing permissions and limitations under the Apache Lic
                 this.highlight(selected);
             }
 
-            // hide the search box if this is the first we got the results and there are a few of them
+            // show the search box if this is the first we got the results and there are enough of them for search
 
             if (initial === true) {
                 var min=this.opts.minimumResultsForSearch;
-                showSearchInput  = min < 0 ? false : countResults(data.results) >= min;
-                this.showSearch(showSearchInput);
+                if (min>=0) {
+                    this.showSearch(countResults(data.results)>=min);
+                }
             }
 
         },
@@ -2052,9 +2053,10 @@ the specific language governing permissions and limitations under the Apache Lic
         showSearch: function(showSearchInput) {
             this.showSearchInput = showSearchInput;
 
-            this.dropdown.find(".select2-search")[showSearchInput ? "removeClass" : "addClass"]("select2-search-hidden");
+            this.dropdown.find(".select2-search").toggleClass("select2-search-hidden", !showSearchInput);
+            this.dropdown.find(".select2-search").toggleClass("select2-offscreen", !showSearchInput);
             //add "select2-with-searchbox" to the container if search box is shown
-            $(this.dropdown, this.container)[showSearchInput ? "addClass" : "removeClass"]("select2-with-searchbox");
+            $(this.dropdown, this.container).toggleClass("select2-with-searchbox", showSearchInput);
         },
 
         // single