Browse Source

full tabbing support for the mac. closes #132

Igor Vaynberg 13 years ago
parent
commit
16c3d31e06
2 changed files with 18 additions and 5 deletions
  1. 3 1
      select2.css
  2. 15 4
      select2.js

+ 3 - 1
select2.css

@@ -468,4 +468,6 @@ disabled look for already selected choices in the results dropdown
 }
 /* end multiselect */
 
-.select2-match { text-decoration: underline; }
+.select2-match { text-decoration: underline; }
+
+.select2-offscreen { position: absolute; left: -1000px; }

+ 15 - 4
select2.js

@@ -1022,7 +1022,7 @@
                 "class": "select2-container",
                 "style": "width: " + this.getContainerWidth()
             }).html([
-                "    <a href='javascript:void(0)' class='select2-choice'>",
+                "    <a href='javascript:void(0)' class='select2-choice'><input type='text' class='select2-offscreen select2-focusser'/>",
                 "   <span></span><abbr class='select2-search-choice-close' style='display:none;'></abbr>",
                 "   <div><b></b></div>" ,
                 "</a>",
@@ -1075,7 +1075,8 @@
                 dropdown = this.dropdown,
                 containers = $([this.container.get(0), this.dropdown.get(0)]),
                 clickingInside = false,
-                selector = ".select2-choice";
+                selector = ".select2-choice",
+                focusser=container.find("input.select2-focusser");
 
             this.selection = selection = container.find(selector);
 
@@ -1126,9 +1127,10 @@
                 }
             }));
             containers.delegate(selector, "focus", function () { if (this.enabled) { containers.addClass("select2-container-active"); dropdown.addClass("select2-drop-active"); }});
-            containers.delegate(selector, "blur", this.bind(function () {
+            containers.delegate(selector, "blur", this.bind(function (e) {
                 if (clickingInside) return;
-                if (!this.opened()) this.blur();
+                if (e.target===focusser.get(0)) return; // ignore blurs from focusser
+                if (!this.opened()) { this.blur(); }
             }));
 
             selection.delegate("abbr", "click", this.bind(function (e) {
@@ -1137,9 +1139,18 @@
                 killEvent(e);
                 this.close();
                 this.triggerChange();
+                selection.focus();
             }));
 
             this.setPlaceholder();
+
+            focusser.bind("focus", function() { selection.focus(); });
+            selection.bind("focus", this.bind(function() {
+                focusser.hide();
+                this.container.addClass("select2-container-active");
+            }));
+            selection.bind("blur", function() { focusser.show(); });
+            this.opts.element.bind("open", function() { focusser.hide(); });
         },
 
         /**