2011-12-05 21:10:19 +00:00
|
|
|
/**
|
2012-02-06 23:50:56 +00:00
|
|
|
* Creates an ve.ui.ClearButtonTool object.
|
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-02-06 23:50:56 +00:00
|
|
|
ve.ui.ClearButtonTool.prototype.onClick = function() {
|
2011-12-09 01:28:44 +00:00
|
|
|
var surfaceView = this.toolbar.getSurfaceView(),
|
|
|
|
surfaceModel = surfaceView.getModel(),
|
|
|
|
tx =surfaceModel.getDocument().prepareContentAnnotation(
|
|
|
|
surfaceView.currentSelection,
|
|
|
|
'clear',
|
|
|
|
this.pattern
|
|
|
|
);
|
|
|
|
surfaceModel.transact( tx );
|
|
|
|
surfaceView.clearInsertionAnnotations();
|
|
|
|
surfaceView.getContextView().closeInspector();
|
2011-12-04 02:59:53 +00:00
|
|
|
};
|
|
|
|
|
2012-02-06 23:50:56 +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 */
|
|
|
|
|
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',
|
|
|
|
'title': 'Clear formatting'
|
2011-12-04 02:59:53 +00:00
|
|
|
};
|
|
|
|
|
2011-12-05 21:10:19 +00:00
|
|
|
/* Inheritance */
|
|
|
|
|
2012-02-06 23:50:56 +00:00
|
|
|
ve.extendClass( ve.ui.ClearButtonTool, ve.ui.ButtonTool );
|