2012-07-19 00:11:26 +00:00
|
|
|
/**
|
|
|
|
* VisualEditor user interface ButtonTool class.
|
2012-07-19 21:25:16 +00:00
|
|
|
*
|
2012-07-19 00:11:26 +00:00
|
|
|
* @copyright 2011-2012 VisualEditor Team and others; see AUTHORS.txt
|
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
2011-12-05 21:10:19 +00:00
|
|
|
/**
|
2012-02-06 23:50:56 +00:00
|
|
|
* Creates an ve.ui.ButtonTool object.
|
2012-06-20 01:20:28 +00:00
|
|
|
*
|
2011-12-05 21:10:19 +00:00
|
|
|
* @class
|
|
|
|
* @constructor
|
2012-02-06 23:50:56 +00:00
|
|
|
* @param {ve.ui.Toolbar} toolbar
|
2011-12-05 21:10:19 +00:00
|
|
|
* @param {String} name
|
|
|
|
*/
|
2012-02-06 23:50:56 +00:00
|
|
|
ve.ui.ButtonTool = function( toolbar, name, title ) {
|
2011-12-05 21:10:19 +00:00
|
|
|
// Inheritance
|
2012-02-06 23:50:56 +00:00
|
|
|
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 ) {
|
2011-12-06 00:10:30 +00:00
|
|
|
if ( e.which === 1 ) {
|
2011-12-04 02:59:53 +00:00
|
|
|
e.preventDefault();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'mouseup': function ( e ) {
|
2011-12-06 00:10:30 +00:00
|
|
|
if ( e.which === 1 ) {
|
2011-12-04 02:59:53 +00:00
|
|
|
_this.onClick( e );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
2011-12-05 21:10:19 +00:00
|
|
|
/* Methods */
|
|
|
|
|
2012-02-06 23:50:56 +00:00
|
|
|
ve.ui.ButtonTool.prototype.onClick = function() {
|
2011-12-04 02:59:53 +00:00
|
|
|
throw 'ButtonTool.onClick not implemented in this subclass:' + this.constructor;
|
|
|
|
};
|
|
|
|
|
2012-02-06 23:50:56 +00:00
|
|
|
ve.ui.ButtonTool.prototype.updateEnabled = function() {
|
2011-12-31 01:44:34 +00:00
|
|
|
if ( this.enabled ) {
|
|
|
|
this.$.removeClass( 'es-toolbarButtonTool-disabled' );
|
|
|
|
} else {
|
|
|
|
this.$.addClass( 'es-toolbarButtonTool-disabled' );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-12-05 21:10:19 +00:00
|
|
|
/* Inheritance */
|
|
|
|
|
2012-02-06 23:50:56 +00:00
|
|
|
ve.extendClass( ve.ui.ButtonTool, ve.ui.Tool );
|