1
0
mirror of synced 2025-02-04 06:09:23 +03:00

added open event

This commit is contained in:
Igor Vaynberg 2012-07-05 11:07:31 +03:00
parent f272ac9f80
commit 6a5719db80

View File

@ -737,9 +737,27 @@
this.dropdown.css(css); this.dropdown.css(css);
}, },
// abstract
shouldOpen: function() {
var event;
if (this.opened()) return false;
event = jQuery.Event("open");
this.opts.element.trigger(event);
return !event.isDefaultPrevented();
},
/**
* Opens the dropdown
*
* @return {Boolean} whether or not dropdown was opened. This method will return false if, for example,
* the dropdown is already open, or if the 'open' event listener on the element called preventDefault().
*/
// abstract // abstract
open: function () { open: function () {
if (this.opened()) return;
if (!this.shouldOpen()) return false;
this.container.addClass("select2-dropdown-open").addClass("select2-container-active"); this.container.addClass("select2-dropdown-open").addClass("select2-container-active");
if(this.dropdown[0] !== this.body.children().last()[0]) { if(this.dropdown[0] !== this.body.children().last()[0]) {
@ -755,6 +773,8 @@
this.dropdown.show(); this.dropdown.show();
this.ensureHighlightVisible(); this.ensureHighlightVisible();
this.focusSearch(); this.focusSearch();
return true;
}, },
// abstract // abstract
@ -1060,15 +1080,6 @@
"</div>"].join("")); "</div>"].join(""));
}, },
// single
open: function () {
if (this.opened()) return;
this.parent.open.apply(this, arguments);
},
// single // single
close: function () { close: function () {
if (!this.opened()) return; if (!this.opened()) return;
@ -1544,11 +1555,11 @@
// multi // multi
open: function () { open: function () {
if (this.opened()) return; if (this.parent.open.apply(this, arguments) === false) return false;
this.parent.open.apply(this, arguments);
this.clearPlaceholder(); this.clearPlaceholder();
this.resizeSearch(); this.resizeSearch();
this.focusSearch(); this.focusSearch();
return true;
}, },
// multi // multi