mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-16 10:59:56 +00:00
72 lines
1.7 KiB
JavaScript
72 lines
1.7 KiB
JavaScript
/**
|
|
* Creates an es.AnnotationButtonTool object.
|
|
*
|
|
* @class
|
|
* @constructor
|
|
* @extends {es.ButtonTool}
|
|
* @param {es.ToolbarView} toolbar
|
|
* @param {String} name
|
|
* @param {Object} annotation
|
|
*/
|
|
es.AnnotationButtonTool = function( toolbar, name, data ) {
|
|
// Inheritance
|
|
es.ButtonTool.call( this, toolbar, name );
|
|
|
|
// Properties
|
|
this.annotation = data;
|
|
};
|
|
|
|
/* Methods */
|
|
|
|
es.AnnotationButtonTool.prototype.onClick = function() {
|
|
var method;
|
|
if ( this.$.hasClass( 'es-toolbarButtonTool-down' ) ) {
|
|
method = 'clear';
|
|
this.toolbar.surfaceView.removeInsertionAnnotation( this.annotation );
|
|
} else {
|
|
method = 'set';
|
|
this.toolbar.surfaceView.addInsertionAnnotation( this.annotation );
|
|
}
|
|
|
|
var tx = this.toolbar.surfaceView.model.getDocument().prepareContentAnnotation(
|
|
this.toolbar.surfaceView.currentSelection,
|
|
method,
|
|
this.annotation
|
|
);
|
|
this.toolbar.surfaceView.model.transact( tx );
|
|
};
|
|
|
|
es.AnnotationButtonTool.prototype.updateState = function( annotations ) {
|
|
for ( var i = 0; i < annotations.full.length; i++ ) {
|
|
if ( annotations.full[i].type === this.annotation.type ) {
|
|
this.$.addClass( 'es-toolbarButtonTool-down' );
|
|
return;
|
|
}
|
|
}
|
|
this.$.removeClass( 'es-toolbarButtonTool-down' );
|
|
};
|
|
|
|
/* Registration */
|
|
|
|
es.Tool.tools.bold = {
|
|
constructor: es.AnnotationButtonTool,
|
|
name: 'bold',
|
|
data: { 'type': 'textStyle/bold' }
|
|
};
|
|
|
|
es.Tool.tools.italic = {
|
|
constructor: es.AnnotationButtonTool,
|
|
name: 'italic',
|
|
data: { 'type': 'textStyle/italic' }
|
|
};
|
|
|
|
es.Tool.tools.link = {
|
|
constructor: es.AnnotationButtonTool,
|
|
name: 'link',
|
|
data: { 'type': 'link/internal', 'data': { 'title': '' } }
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
es.extendClass( es.AnnotationButtonTool, es.ButtonTool );
|