mediawiki-extensions-Visual.../modules/es/tools/es.ClearButtonTool.js
Trevor Parscal a48d2a5787 * Added shortcut for links (ctrl/cmd + K)
* Added title attributes for tools
2011-12-09 21:16:42 +00:00

55 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, title ) {
// Inheritance
es.ButtonTool.call( this, toolbar, name, title );
// 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',
'title': 'Clear formatting'
};
/* Inheritance */
es.extendClass( es.ClearButtonTool, es.ButtonTool );