Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ivaynberg/select2
Browse files Browse the repository at this point in the history
  • Loading branch information
ivaynberg committed Jul 24, 2012
2 parents f06aae3 + d4e95ee commit 5d496bd
Showing 1 changed file with 52 additions and 18 deletions.
70 changes: 52 additions & 18 deletions select2.js
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,8 @@
this makes sure the search field is focussed even if the current event would blur it */
window.setTimeout(this.bind(function () {
this.search.focus();
// reset the value so IE places the cursor at the end of the input box
this.search.val(this.search.val());
}), 10);
},

Expand Down Expand Up @@ -1206,7 +1208,7 @@
// single
focus: function () {
this.close();
this.search.focus();
this.container.focus();
},

// single
Expand All @@ -1217,7 +1219,7 @@
// single
cancel: function () {
this.parent.cancel.apply(this, arguments);
this.search.focus();
this.container.focus();
},

// single
Expand Down Expand Up @@ -1256,18 +1258,6 @@
killEvent(e);
return;
}
} else {
if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC) {
return;
}

this.open();

if (e.which === KEY.ENTER) {
// do not propagate the event otherwise we open, and propagate enter which closes
killEvent(e);
return;
}
}
}));

Expand All @@ -1276,7 +1266,7 @@

if (this.opened()) {
this.close();
this.search.focus();
this.container.focus();
} else if (this.enabled) {
this.open();
}
Expand All @@ -1286,14 +1276,58 @@
}));

dropdown.bind("click", this.bind(function() { this.search.focus(); }));

container.bind("focus", this.bind(function() {
// allows the container to recieve the keyup event
this.container.attr("tabindex", 1);
}));

container.bind("blur", this.bind(function() {
// remove the tabindex so the tab key works properly
this.container.attr("tabindex", -1);
}));

container.bind("keydown", this.bind(function(e) {
if (!this.enabled) return;

this.container.attr("tabindex", -1);

if (e.which === KEY.PAGE_UP || e.which === KEY.PAGE_DOWN) {
// prevent the page from scrolling
killEvent(e);
return;
}

if (!this.opened()) {
if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC) {
return;
}

this.open();

if (e.which === KEY.ENTER) {
// do not propagate the event otherwise we open, and propagate enter which closes
killEvent(e);
return;
}

var keyWritten = String.fromCharCode(e.which).toLowerCase();

if (e.shiftKey) {
keyWritten = keyWritten.toUpperCase();
}

this.search.val(keyWritten);
}
}));

selection.delegate("abbr", "click", this.bind(function (e) {
if (!this.enabled) return;
this.clear();
killEvent(e);
this.close();
this.triggerChange();
this.search.focus();
this.container.focus();
}));

selection.bind("focus", this.bind(function() { this.search.focus(); }));
Expand Down Expand Up @@ -1406,7 +1440,7 @@
this.opts.element.val(this.id(data));
this.updateSelection(data);
this.close();
this.search.focus();
this.container.focus();

if (!equal(old, this.id(data))) { this.triggerChange(); }
},
Expand Down Expand Up @@ -1700,7 +1734,7 @@
// multi
focus: function () {
this.close();
this.search.focus();
this.container.focus();
},

// multi
Expand Down

0 comments on commit 5d496bd

Please sign in to comment.