2011-12-05 21:10:19 +00:00
|
|
|
/**
|
2012-02-06 23:50:56 +00:00
|
|
|
* Creates an ve.ui.ClearButtonTool 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
|
|
|
* @extends {ve.ui.ButtonTool}
|
|
|
|
* @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.ClearButtonTool = function( toolbar, name, title ) {
|
2011-12-05 21:10:19 +00:00
|
|
|
// Inheritance
|
2012-02-06 23:50:56 +00:00
|
|
|
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 */
|
|
|
|
|
2012-06-20 01:20:28 +00:00
|
|
|
ve.ui.ClearButtonTool.prototype.getAnnotations = function(){
|
|
|
|
var surface = this.toolbar.getSurfaceView(),
|
|
|
|
model = surface.getModel();
|
|
|
|
return model.getDocument().getAnnotationsFromRange( model.getSelection(), true );
|
|
|
|
};
|
|
|
|
|
2012-02-06 23:50:56 +00:00
|
|
|
ve.ui.ClearButtonTool.prototype.onClick = function() {
|
2012-06-20 01:20:28 +00:00
|
|
|
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() );
|
2012-03-16 22:20:16 +00:00
|
|
|
surfaceView.contextView.closeInspector();
|
2011-12-04 02:59:53 +00:00
|
|
|
};
|
|
|
|
|
2012-02-06 23:50:56 +00:00
|
|
|
ve.ui.ClearButtonTool.prototype.updateState = function( annotations ) {
|
2012-06-20 01:20:28 +00:00
|
|
|
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 */
|
|
|
|
|
2012-02-06 23:50:56 +00:00
|
|
|
ve.ui.Tool.tools.clear = {
|
|
|
|
'constructor': ve.ui.ClearButtonTool,
|
2011-12-09 21:16:42 +00:00
|
|
|
'name': 'clear',
|
2012-06-20 01:20:28 +00:00
|
|
|
'title': ve.msg( 'visualeditor-clearbutton-tooltip' )
|
2011-12-04 02:59:53 +00:00
|
|
|
};
|
|
|
|
|
2011-12-05 21:10:19 +00:00
|
|
|
/* Inheritance */
|
|
|
|
|
2012-04-02 22:28:26 +00:00
|
|
|
ve.extendClass( ve.ui.ClearButtonTool, ve.ui.ButtonTool );
|