mediawiki-extensions-Visual.../modules/es/tools/es.ClearButtonTool.js

54 lines
1.3 KiB
JavaScript

/**
* Creates an es.ClearButtonTool object.
*
* @class
* @constructor
* @extends {es.ButtonTool}
* @param {es.ToolbarView} toolbar
* @param {String} name
*/
es.ClearButtonTool = function( toolbar, name ) {
// Inheritance
es.ButtonTool.call( this, toolbar, name );
// Properties
this.$.addClass( 'es-toolbarButtonTool-disabled' );
this.pattern = /(textStyle\/|link\/).*/;
};
/* Methods */
es.ClearButtonTool.prototype.onClick = function() {
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();
};
es.ClearButtonTool.prototype.updateState = function( annotations ) {
var matchingAnnotations = es.DocumentModel.getMatchingAnnotations(
annotations.all, this.pattern
);
if ( matchingAnnotations.length === 0 ) {
this.$.addClass( 'es-toolbarButtonTool-disabled' );
} else {
this.$.removeClass( 'es-toolbarButtonTool-disabled' );
}
};
/* Registration */
es.Tool.tools.clear = {
constructor: es.ClearButtonTool,
name: 'clear'
};
/* Inheritance */
es.extendClass( es.ClearButtonTool, es.ButtonTool );