Skip to content
Permalink
Browse files

Selectmenu: added callback events

  • Loading branch information
fnagel committed Sep 24, 2011
1 parent 3528948 commit 3503c586c4b8384e3c6f1b140935cf4454c0853a
Showing with 56 additions and 49 deletions.
  1. +56 −49 ui/jquery.ui.selectmenu.js
@@ -29,13 +29,14 @@ $.widget( "ui.selectmenu", {
at: "left bottom",
collision: "none"
},
source: null,
source: null,
value: null,
// callbacks
open: null,
focus: null,
select: null,
close: null,
change: null,
// change: null,
},

_create: function() {
@@ -142,46 +143,6 @@ $.widget( "ui.selectmenu", {

},

open: function( event ) {
var self = this,
options = this.options,
currentItem = self._getSelectedItem();

// close all other selectmenus
$( '.' + self.widgetBaseClass + '-open' ).not( self.newelement ).each( function() {
$( this ).children( 'ul.ui-menu' ).data( 'element.selectelemenu' ).selectmenu( 'close' );
});

if ( options.dropdown ) {
self.newelement
.addClass( 'ui-corner-top' )
.removeClass( 'ui-corner-all' );
}

self.listWrap.addClass( self.widgetBaseClass + '-open' );
self.list.focus().menu( "focus", null, currentItem );

if ( !options.dropdown ) {
// center current item
if ( self.list.css("overflow") == "auto" ) {
self.list.scrollTop( self.list.scrollTop() + currentItem.position().top - self.list.outerHeight()/2 + currentItem.outerHeight()/2 );
}
// calculate offset
var _offset = (self.list.offset().top - currentItem.offset().top + (self.newelement.outerHeight() - currentItem.outerHeight()) / 2);
$.extend( options.position, {
my: "left top",
at: "left top",
offset: "0 " + _offset
});
}

self.listWrap.position( $.extend({
of: this.newelementWrap
}, options.position ));

this.opened = true;
},

refresh: function() {
var self = this,
options = this.options;
@@ -209,12 +170,16 @@ $.widget( "ui.selectmenu", {
.menu({
select: function( event, ui ) {
var item = ui.item.data( "item.selectmenu" );
self._setSelected( item );
self._setSelected( event, item );
item.element = $ ( self.items[ item.index ] );
self._trigger( "select", event, { item: item } );
self.close( event, true);
},
focus: function( event, ui ) {
if ( !self.opened ) self._setSelected( ui.item.data( "item.selectmenu" );
}
focus: function( event, ui ) {
var item = ui.item.data( "item.selectmenu" );
if ( !self.opened ) self._setSelected( event, item );
self._trigger( "focus", event, { item: item } );
}
})
.bind( 'mouseenter.selectelemenu', function() {
self.hover = true;
@@ -230,6 +195,47 @@ $.widget( "ui.selectmenu", {
}
},

open: function( event ) {
var self = this,
options = this.options,
currentItem = self._getSelectedItem();

// close all other selectmenus
$( '.' + self.widgetBaseClass + '-open' ).not( self.newelement ).each( function() {
$( this ).children( 'ul.ui-menu' ).data( 'element.selectelemenu' ).selectmenu( 'close' );
});

if ( options.dropdown ) {
self.newelement
.addClass( 'ui-corner-top' )
.removeClass( 'ui-corner-all' );
}

self.listWrap.addClass( self.widgetBaseClass + '-open' );
self.list.focus().menu( "focus", null, currentItem );

if ( !options.dropdown ) {
// center current item
if ( self.list.css("overflow") == "auto" ) {
self.list.scrollTop( self.list.scrollTop() + currentItem.position().top - self.list.outerHeight()/2 + currentItem.outerHeight()/2 );
}
// calculate offset
var _offset = (self.list.offset().top - currentItem.offset().top + (self.newelement.outerHeight() - currentItem.outerHeight()) / 2);
$.extend( options.position, {
my: "left top",
at: "left top",
offset: "0 " + _offset
});
}

self.listWrap.position( $.extend({
of: this.newelementWrap
}, options.position ));

this.opened = true;
self._trigger( "open", event );
},

close: function( event, focus ) {
var self = this,
options = this.options;
@@ -244,6 +250,8 @@ $.widget( "ui.selectmenu", {
this.opened = false;

if (focus) self.newelement.focus();

self._trigger( "close", event );
},

_renderMenu: function( ul, items ) {
@@ -289,7 +297,7 @@ $.widget( "ui.selectmenu", {
return this.list.find( "li" ).not( '.ui-selectmenu-optgroup' ).eq( this.element[0].selectedIndex );
},

_setSelected: function( item ) {
_setSelected: function( event, item ) {
this.newelement.children( '.ui-button-text' ).text( item.label );
this.element[0].selectedIndex = item.index;
this.options.value = item.value;
@@ -326,8 +334,7 @@ $.widget( "ui.selectmenu", {
optgroup: optgroup.attr("label") || false,
disabled: optgroup.attr( "disabled" ) || option.attr( "disabled" )
});
});
console.log( data );
});
this.options.source = data;
}
},

0 comments on commit 3503c58

Please sign in to comment.
You can’t perform that action at this time.