1
0
mirror of synced 2025-02-10 17:19:23 +03:00

select2-focus and select2-blur events. fixes #798. closes #866

This commit is contained in:
Igor Vaynberg 2013-05-06 20:13:05 -07:00
parent 882e7996f4
commit d668ae76d0

View File

@ -1761,8 +1761,7 @@ the specific language governing permissions and limitations under the Apache Lic
var selection, var selection,
container = this.container, container = this.container,
dropdown = this.dropdown, dropdown = this.dropdown;
clickingInside = false;
this.showSearch(this.opts.minimumResultsForSearch >= 0); this.showSearch(this.opts.minimumResultsForSearch >= 0);
@ -1862,7 +1861,10 @@ the specific language governing permissions and limitations under the Apache Lic
})); }));
selection.bind("mousedown", this.bind(function (e) { selection.bind("mousedown", this.bind(function (e) {
clickingInside = true;
if (!this.container.hasClass("select2-container-active")) {
this.opts.element.trigger($.Event("select2-focus"));
}
if (this.opened()) { if (this.opened()) {
this.close(); this.close();
@ -1871,8 +1873,6 @@ the specific language governing permissions and limitations under the Apache Lic
} }
killEvent(e); killEvent(e);
clickingInside = false;
})); }));
dropdown.bind("mousedown", this.bind(function() { this.search.focus(); })); dropdown.bind("mousedown", this.bind(function() { this.search.focus(); }));
@ -1882,6 +1882,9 @@ the specific language governing permissions and limitations under the Apache Lic
})); }));
this.focusser.bind("focus", this.bind(function(){ this.focusser.bind("focus", this.bind(function(){
if (!this.container.hasClass("select2-container-active")) {
this.opts.element.trigger($.Event("select2-focus"));
}
this.container.addClass("select2-container-active"); this.container.addClass("select2-container-active");
})).bind("blur", this.bind(function() { })).bind("blur", this.bind(function() {
if (!this.opened()) { if (!this.opened()) {
@ -1890,6 +1893,9 @@ the specific language governing permissions and limitations under the Apache Lic
} }
})); }));
this.search.bind("focus", this.bind(function(){ this.search.bind("focus", this.bind(function(){
if (!this.container.hasClass("select2-container-active")) {
this.opts.element.trigger($.Event("select2-focus"));
}
this.container.addClass("select2-container-active"); this.container.addClass("select2-container-active");
})); }));
@ -2396,6 +2402,9 @@ the specific language governing permissions and limitations under the Apache Lic
} }
this.selectChoice(null); this.selectChoice(null);
this.clearPlaceholder(); this.clearPlaceholder();
if (!this.container.hasClass("select2-container-active")) {
this.opts.element.trigger($.Event("select2-focus"));
}
this.open(); this.open();
this.focusSearch(); this.focusSearch();
e.preventDefault(); e.preventDefault();
@ -2403,6 +2412,9 @@ the specific language governing permissions and limitations under the Apache Lic
this.container.delegate(selector, "focus", this.bind(function () { this.container.delegate(selector, "focus", this.bind(function () {
if (!this.isInterfaceEnabled()) return; if (!this.isInterfaceEnabled()) return;
if (!this.container.hasClass("select2-container-active")) {
this.opts.element.trigger($.Event("select2-focus"));
}
this.container.addClass("select2-container-active"); this.container.addClass("select2-container-active");
this.dropdown.addClass("select2-drop-active"); this.dropdown.addClass("select2-drop-active");
this.clearPlaceholder(); this.clearPlaceholder();