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

59 lines
1.5 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.getAnnotations = function(){
var surface = this.toolbar.getSurfaceView(),
model = surface.getModel();
return model.getDocument().getAnnotationsFromRange( model.getSelection(), true );
};
ve.ui.ClearButtonTool.prototype.onClick = function() {
var surfaceView = this.toolbar.getSurfaceView(),
model = surfaceView.getModel(),
annotations = this.getAnnotations();
for ( var hash in annotations ) {
model.annotate( 'clear', annotations[hash] );
}
surfaceView.showSelection( model.getSelection() );
surfaceView.contextView.closeInspector();
2011-12-04 02:59:53 +00:00
};
ve.ui.ClearButtonTool.prototype.updateState = function( annotations ) {
var allAnnotations = this.getAnnotations();
if ( ve.isEmptyObject( allAnnotations ) ) {
2011-12-04 02:59:53 +00:00
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': ve.msg( 'visualeditor-clearbutton-tooltip' )
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 );