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

55 lines
1.3 KiB
JavaScript
Raw Normal View History

2011-12-05 21:10:19 +00:00
/**
* Creates an es.ClearButtonTool object.
*
* @class
* @constructor
* @extends {es.ButtonTool}
* @param {es.ToolbarView} toolbar
* @param {String} name
*/
es.ClearButtonTool = function( toolbar, name, title ) {
2011-12-05 21:10:19 +00:00
// Inheritance
es.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 */
2011-12-04 02:59:53 +00:00
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();
2011-12-04 02:59:53 +00:00
};
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' );
}
};
2011-12-05 21:10:19 +00:00
/* Registration */
2011-12-04 02:59:53 +00:00
es.Tool.tools.clear = {
'constructor': es.ClearButtonTool,
'name': 'clear',
'title': 'Clear formatting'
2011-12-04 02:59:53 +00:00
};
2011-12-05 21:10:19 +00:00
/* Inheritance */
es.extendClass( es.ClearButtonTool, es.ButtonTool );