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

51 lines
1.2 KiB
JavaScript
Raw Normal View History

2011-12-05 21:10:19 +00:00
/**
* Creates an ve.ui.ClearButtonTool object.
2011-12-05 21:10:19 +00:00
*
* @class
* @constructor
* @extends {ve.ui.ButtonTool}
* @param {ve.ui.Toolbar} toolbar
2011-12-05 21:10:19 +00:00
* @param {String} name
*/
ve.ui.ClearButtonTool = function( toolbar, name, title ) {
2011-12-05 21:10:19 +00:00
// Inheritance
ve.ui.ButtonTool.call( this, toolbar, name, title );
2011-12-05 21:10:19 +00:00
// Properties
2011-12-04 02:59:53 +00:00
this.$.addClass( 'es-toolbarButtonTool-disabled' );
this.pattern = /(textStyle\/|link\/).*/;
};
2011-12-05 21:10:19 +00:00
/* Methods */
ve.ui.ClearButtonTool.prototype.onClick = function() {
var surfaceView = this.toolbar.getSurfaceView();
surfaceView.annotate( 'clear', this.pattern );
surfaceView.clearInsertionAnnotations();
surfaceView.contextView.closeInspector();
2011-12-04 02:59:53 +00:00
};
ve.ui.ClearButtonTool.prototype.updateState = function( annotations ) {
var matchingAnnotations = ve.dm.DocumentNode.getMatchingAnnotations(
2011-12-04 02:59:53 +00:00
annotations.all, this.pattern
);
if ( matchingAnnotations.length === 0 ) {
this.$.addClass( 'es-toolbarButtonTool-disabled' );
} else {
this.$.removeClass( 'es-toolbarButtonTool-disabled' );
}
};
2011-12-05 21:10:19 +00:00
/* Registration */
ve.ui.Tool.tools.clear = {
'constructor': ve.ui.ClearButtonTool,
'name': 'clear',
'title': 'Clear formatting'
2011-12-04 02:59:53 +00:00
};
2011-12-05 21:10:19 +00:00
/* Inheritance */
ve.extendClass( ve.ui.ClearButtonTool, ve.ui.ButtonTool );