mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-09-25 11:16:51 +00:00
Seperate ClearButtonTool from AnnotationButtonTool
This commit is contained in:
parent
bc13cf2588
commit
a5fdfffc3b
|
@ -102,7 +102,8 @@ $wgResourceModules += array(
|
|||
'es/views/es.ToolbarView.js',
|
||||
'es/tools/es.Tool.js',
|
||||
'es/tools/es.ButtonTool.js',
|
||||
'es/tools/es.AnnotationButtonTool.js'
|
||||
'es/tools/es.AnnotationButtonTool.js',
|
||||
'es/tools/es.ClearButtonTool.js'
|
||||
),
|
||||
'styles' => array(
|
||||
'es/styles/es.SurfaceView.css',
|
||||
|
|
|
@ -135,6 +135,7 @@
|
|||
<script src="../modules/es/tools/es.Tool.js"></script>
|
||||
<script src="../modules/es/tools/es.ButtonTool.js"></script>
|
||||
<script src="../modules/es/tools/es.AnnotationButtonTool.js"></script>
|
||||
<script src="../modules/es/tools/es.ClearButtonTool.js"></script>
|
||||
|
||||
<!-- Demo -->
|
||||
<script src="../modules/sandbox/sandbox.js"></script>
|
||||
|
|
|
@ -4,12 +4,7 @@ es.AnnotationButtonTool = function( toolbar, name, data ) {
|
|||
};
|
||||
|
||||
es.AnnotationButtonTool.prototype.onClick = function() {
|
||||
var method;
|
||||
if ( this.name === 'clear') {
|
||||
method = 'clear';
|
||||
} else {
|
||||
method = this.$.hasClass( 'es-toolbarButtonTool-down' ) ? 'clear' : 'set';
|
||||
}
|
||||
var method = this.$.hasClass( 'es-toolbarButtonTool-down' ) ? 'clear' : 'set';
|
||||
|
||||
var tx = this.toolbar.surfaceView.model.getDocument().prepareContentAnnotation(
|
||||
this.toolbar.surfaceView.currentSelection,
|
||||
|
@ -17,6 +12,17 @@ es.AnnotationButtonTool.prototype.onClick = function() {
|
|||
this.data
|
||||
);
|
||||
this.toolbar.surfaceView.model.transact( tx );
|
||||
return false;
|
||||
};
|
||||
|
||||
es.AnnotationButtonTool.prototype.updateState = function( annotations ) {
|
||||
for ( var i = 0; i < annotations.length; i++ ) {
|
||||
if ( annotations[i].type === this.data.type ) {
|
||||
this.$.addClass( 'es-toolbarButtonTool-down' );
|
||||
return;
|
||||
}
|
||||
}
|
||||
this.$.removeClass( 'es-toolbarButtonTool-down' );
|
||||
};
|
||||
|
||||
es.Tool.tools.bold = {
|
||||
|
@ -31,10 +37,5 @@ es.Tool.tools.italic = {
|
|||
data: { 'type': 'textStyle/italic' }
|
||||
};
|
||||
|
||||
es.Tool.tools.clear = {
|
||||
constructor: es.AnnotationButtonTool,
|
||||
name: 'clear',
|
||||
data: /.*/
|
||||
};
|
||||
|
||||
es.extendClass( es.AnnotationButtonTool, es.ButtonTool );
|
29
modules/es/tools/es.ClearButtonTool.js
Normal file
29
modules/es/tools/es.ClearButtonTool.js
Normal file
|
@ -0,0 +1,29 @@
|
|||
es.ClearButtonTool = function( toolbar, name ) {
|
||||
es.ButtonTool.call( this, toolbar, name );
|
||||
this.$.addClass( 'es-toolbarButtonTool-disabled' );
|
||||
};
|
||||
|
||||
es.ClearButtonTool.prototype.onClick = function() {
|
||||
var tx = this.toolbar.surfaceView.model.getDocument().prepareContentAnnotation(
|
||||
this.toolbar.surfaceView.currentSelection,
|
||||
'clear',
|
||||
/.*/
|
||||
);
|
||||
this.toolbar.surfaceView.model.transact( tx );
|
||||
this.toolbar.surfaceView.clearInsertionAnnotations();
|
||||
};
|
||||
|
||||
es.ClearButtonTool.prototype.updateState = function( annotations ) {
|
||||
if ( annotations.length === 0 ) {
|
||||
this.$.addClass( 'es-toolbarButtonTool-disabled' );
|
||||
} else {
|
||||
this.$.removeClass( 'es-toolbarButtonTool-disabled' );
|
||||
}
|
||||
};
|
||||
|
||||
es.Tool.tools.clear = {
|
||||
constructor: es.ClearButtonTool,
|
||||
name: 'clear'
|
||||
};
|
||||
|
||||
es.extendClass( es.ClearButtonTool, es.ButtonTool );
|
|
@ -142,6 +142,7 @@ es.SurfaceView.prototype.getInsertionAnnotations = function() {
|
|||
|
||||
es.SurfaceView.prototype.addInsertionAnnotation = function( annotation ) {
|
||||
this.insertionAnnotations.push( annotation );
|
||||
this.emitUpdate();
|
||||
};
|
||||
|
||||
es.SurfaceView.prototype.loadInsertionAnnotations = function( annotation ) {
|
||||
|
@ -161,10 +162,12 @@ es.SurfaceView.prototype.removeInsertionAnnotation = function( annotation ) {
|
|||
if ( index !== -1 ) {
|
||||
this.insertionAnnotations.splice( index, 1 );
|
||||
}
|
||||
this.emitUpdate();
|
||||
};
|
||||
|
||||
es.SurfaceView.prototype.clearInsertionAnnotations = function() {
|
||||
this.insertionAnnotations = [];
|
||||
this.emitUpdate();
|
||||
};
|
||||
|
||||
es.SurfaceView.prototype.getModel = function() {
|
||||
|
|
|
@ -58,10 +58,14 @@ es.ToolbarView.prototype.updateState = function() {
|
|||
annotations;
|
||||
|
||||
if( selection.from === selection.to ) {
|
||||
annotations = this.surfaceView.documentView.model.getAnnotationsFromOffset( selection.to );
|
||||
annotations = this.surfaceView.getInsertionAnnotations();
|
||||
} else {
|
||||
annotations = this.surfaceView.documentView.model.getAnnotationsFromRange( selection );
|
||||
}
|
||||
|
||||
for( var i = 0; i < this.tools.length; i++ ) {
|
||||
this.tools[i].updateState( annotations );
|
||||
}
|
||||
};
|
||||
|
||||
es.ToolbarView.prototype.setup = function() {
|
||||
|
|
Loading…
Reference in a new issue