2012-05-21 19:37:30 +00:00
|
|
|
/**
|
|
|
|
* Creates an ve.ui.ClearButtonTool object.
|
2012-06-12 18:43:56 +00:00
|
|
|
*
|
2012-05-21 19:37:30 +00:00
|
|
|
* @class
|
|
|
|
* @constructor
|
|
|
|
* @extends {ve.ui.ButtonTool}
|
|
|
|
* @param {ve.ui.Toolbar} toolbar
|
|
|
|
* @param {String} name
|
|
|
|
*/
|
|
|
|
ve.ui.ClearButtonTool = function( toolbar, name, title ) {
|
|
|
|
// Inheritance
|
|
|
|
ve.ui.ButtonTool.call( this, toolbar, name, title );
|
|
|
|
|
|
|
|
// Properties
|
|
|
|
this.$.addClass( 'es-toolbarButtonTool-disabled' );
|
|
|
|
this.pattern = /(textStyle\/|link\/).*/;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
2012-06-13 21:31:33 +00:00
|
|
|
ve.ui.ClearButtonTool.prototype.getAnnotations = function(){
|
2012-06-14 22:04:07 +00:00
|
|
|
var surface = this.toolbar.getSurfaceView(),
|
|
|
|
model = surface.getModel();
|
|
|
|
return model.getDocument().getAnnotationsFromRange( model.getSelection(), true );
|
2012-06-11 23:29:09 +00:00
|
|
|
};
|
|
|
|
|
2012-05-21 19:37:30 +00:00
|
|
|
ve.ui.ClearButtonTool.prototype.onClick = function() {
|
2012-06-06 18:27:23 +00:00
|
|
|
var surfaceView = this.toolbar.getSurfaceView(),
|
2012-06-13 21:31:33 +00:00
|
|
|
model = surfaceView.getModel(),
|
|
|
|
annotations = this.getAnnotations();
|
|
|
|
for ( var hash in annotations ) {
|
|
|
|
model.annotate( 'clear', annotations[hash] );
|
|
|
|
}
|
2012-06-11 23:29:09 +00:00
|
|
|
surfaceView.showSelection( model.getSelection() );
|
2012-06-11 21:50:52 +00:00
|
|
|
surfaceView.contextView.closeInspector();
|
2012-05-21 19:37:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
ve.ui.ClearButtonTool.prototype.updateState = function( annotations ) {
|
2012-06-14 22:04:07 +00:00
|
|
|
var allAnnotations = this.getAnnotations();
|
2012-06-12 18:43:56 +00:00
|
|
|
|
2012-06-14 22:04:07 +00:00
|
|
|
if ( ve.isEmptyObject( allAnnotations ) ) {
|
2012-05-21 19:37:30 +00:00
|
|
|
this.$.addClass( 'es-toolbarButtonTool-disabled' );
|
|
|
|
} else {
|
|
|
|
this.$.removeClass( 'es-toolbarButtonTool-disabled' );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.ui.Tool.tools.clear = {
|
|
|
|
'constructor': ve.ui.ClearButtonTool,
|
|
|
|
'name': 'clear',
|
2012-06-19 08:30:30 +00:00
|
|
|
'title': mw.msg( 'visualeditor-clearbutton-tooltip' )
|
2012-05-21 19:37:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
ve.extendClass( ve.ui.ClearButtonTool, ve.ui.ButtonTool );
|