mediawiki-extensions-Visual.../modules/ve/ui/tools/ve.ui.ClearButtonTool.js
Trevor Parscal a52d7ff65a Finally getting rid of all the es-* stuff and other cruft
* Switched a lot of classes from es-* to ve-ui-*
* Removed all the DOM structure left over from the old sandbox demo
* Got rid of transparent backgrounds
* Added menu font-size rule to stand-alone target
* Moved some rules around that were in the wrong places
* Got rid of some unused/unneeded methods in the mw target (attach and detach surface methods)
* Added active class to context icon with shallower shadow effect so it doesn't break your spacial perception when you click on it
* Renamed the iframe and iframe wrapper elements so it's easier to see where they came from
* Removed unused CSS rules
* Fixed some uses of prop( 'class', … ) to addClass

Change-Id: I54a660ca0baf0baa4463faca7a1edcf648130b6b
2012-08-28 13:59:35 -07:00

67 lines
1.7 KiB
JavaScript

/**
* VisualEditor user interface ClearButtonTool class.
*
* @copyright 2011-2012 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
/**
* Creates an ve.ui.ClearButtonTool object.
*
* @class
* @constructor
* @extends {ve.ui.ButtonTool}
* @param {ve.ui.Toolbar} toolbar
* @param {String} name
*/
ve.ui.ClearButtonTool = function ( toolbar, name, title ) {
// Inheritance
ve.ui.ButtonTool.call( this, toolbar, name, title );
// Properties
this.$.addClass( 've-ui-toolbarButtonTool-disabled' );
this.pattern = /^(textStyle|link)\//;
};
/* Methods */
ve.ui.ClearButtonTool.prototype.getAnnotations = function () {
var surface = this.toolbar.getSurfaceView(),
model = surface.getModel();
return model.getDocument().getAnnotationsFromRange( model.getSelection(), true );
};
ve.ui.ClearButtonTool.prototype.onClick = function () {
var hash,
surfaceView = this.toolbar.getSurfaceView(),
model = surfaceView.getModel(),
annotations = this.getAnnotations();
for ( hash in annotations ) {
model.annotate( 'clear', annotations[hash] );
}
surfaceView.showSelection( model.getSelection() );
surfaceView.contextView.closeInspector();
};
ve.ui.ClearButtonTool.prototype.updateState = function ( annotations ) {
var allAnnotations = this.getAnnotations();
if ( ve.isEmptyObject( allAnnotations ) ) {
this.$.addClass( 've-ui-toolbarButtonTool-disabled' );
} else {
this.$.removeClass( 've-ui-toolbarButtonTool-disabled' );
}
};
/* Registration */
ve.ui.Tool.tools.clear = {
'constructor': ve.ui.ClearButtonTool,
'name': 'clear',
'title': ve.msg( 'visualeditor-clearbutton-tooltip' )
};
/* Inheritance */
ve.extendClass( ve.ui.ClearButtonTool, ve.ui.ButtonTool );