2011-12-02 21:25:19 +00:00
|
|
|
es.DropdownTool = function( toolbar, name, items ) {
|
|
|
|
// Inheritance
|
2011-12-01 23:24:21 +00:00
|
|
|
es.Tool.call( this, toolbar, name );
|
|
|
|
|
2011-12-02 21:25:19 +00:00
|
|
|
// Early exit when extending via es.extendClass
|
2011-12-01 23:24:21 +00:00
|
|
|
if ( !name ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-02 21:25:19 +00:00
|
|
|
// Properties
|
2011-12-01 23:24:21 +00:00
|
|
|
var _this = this;
|
2011-12-02 21:25:19 +00:00
|
|
|
this.menuView = new es.MenuView( items, function( item ) {
|
|
|
|
_this.onSelect( item );
|
|
|
|
_this.$.text( item.label );
|
|
|
|
} );
|
2011-12-01 23:24:21 +00:00
|
|
|
|
2011-12-02 21:25:19 +00:00
|
|
|
$( document ).add( this.toolbar.surfaceView.$ ).mousedown( function( e ) {
|
|
|
|
if ( e.button === 0 ) {
|
|
|
|
_this.menuView.hide();
|
2011-12-01 23:24:21 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2011-12-02 21:25:19 +00:00
|
|
|
// DOM Changes
|
|
|
|
this.$.addClass( 'es-toolbarDropdownTool' ).addClass( 'es-toolbarDropdownTool-' + name );
|
2011-12-01 23:24:21 +00:00
|
|
|
};
|
|
|
|
|
2011-12-02 21:25:19 +00:00
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
es.DropdownTool.prototype.onSelect = function( item ) {
|
|
|
|
throw 'DropdownTool.onSelect not implemented in this subclass:' + this.constructor;
|
2011-12-01 23:24:21 +00:00
|
|
|
};
|
|
|
|
|
2011-12-02 21:25:19 +00:00
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
es.extendClass( es.DropdownTool, es.Tool );
|