mediawiki-extensions-Visual.../modules/ve/ui/tools/ve.ui.ButtonTool.js

54 lines
1 KiB
JavaScript
Raw Normal View History

2011-12-05 21:10:19 +00:00
/**
* Creates an ve.ui.ButtonTool object.
2011-12-05 21:10:19 +00:00
*
* @class
* @constructor
* @param {ve.ui.Toolbar} toolbar
2011-12-05 21:10:19 +00:00
* @param {String} name
*/
ve.ui.ButtonTool = function( toolbar, name, title ) {
2011-12-05 21:10:19 +00:00
// Inheritance
ve.ui.Tool.call( this, toolbar, name, title );
2011-12-04 02:59:53 +00:00
if ( !name ) {
return;
}
2011-12-05 21:10:19 +00:00
// Properties
2011-12-04 02:59:53 +00:00
this.$.addClass( 'es-toolbarButtonTool' ).addClass( 'es-toolbarButtonTool-' + name );
2011-12-05 21:10:19 +00:00
// Events
2011-12-04 02:59:53 +00:00
var _this = this;
this.$.bind( {
'mousedown': function( e ) {
if ( e.which === 1 ) {
2011-12-04 02:59:53 +00:00
e.preventDefault();
return false;
}
},
'mouseup': function ( e ) {
if ( e.which === 1 ) {
2011-12-04 02:59:53 +00:00
_this.onClick( e );
}
}
} );
};
2011-12-05 21:10:19 +00:00
/* Methods */
ve.ui.ButtonTool.prototype.onClick = function() {
2011-12-04 02:59:53 +00:00
throw 'ButtonTool.onClick not implemented in this subclass:' + this.constructor;
};
ve.ui.ButtonTool.prototype.updateEnabled = function() {
if ( this.enabled ) {
this.$.removeClass( 'es-toolbarButtonTool-disabled' );
} else {
this.$.addClass( 'es-toolbarButtonTool-disabled' );
}
};
2011-12-05 21:10:19 +00:00
/* Inheritance */
ve.extendClass( ve.ui.ButtonTool, ve.ui.Tool );