2011-11-30 23:05:06 +00:00
|
|
|
es.AnnotationButtonTool = function( toolbar, name, data ) {
|
|
|
|
es.ButtonTool.call( this, toolbar, name );
|
|
|
|
this.data = data;
|
|
|
|
};
|
|
|
|
|
|
|
|
es.AnnotationButtonTool.prototype.onClick = function() {
|
2011-12-01 00:53:58 +00:00
|
|
|
var method;
|
|
|
|
if ( this.$.hasClass( 'es-toolbarButtonTool-down' ) ) {
|
|
|
|
method = 'clear';
|
2011-12-01 01:10:38 +00:00
|
|
|
this.toolbar.surfaceView.removeInsertionAnnotation( this.data );
|
2011-12-01 00:53:58 +00:00
|
|
|
} else {
|
|
|
|
method = 'set';
|
|
|
|
this.toolbar.surfaceView.addInsertionAnnotation( this.data );
|
|
|
|
}
|
2011-11-30 23:05:06 +00:00
|
|
|
|
|
|
|
var tx = this.toolbar.surfaceView.model.getDocument().prepareContentAnnotation(
|
|
|
|
this.toolbar.surfaceView.currentSelection,
|
|
|
|
method,
|
|
|
|
this.data
|
|
|
|
);
|
|
|
|
this.toolbar.surfaceView.model.transact( tx );
|
2011-12-01 00:37:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
es.AnnotationButtonTool.prototype.updateState = function( annotations ) {
|
2011-12-01 23:25:56 +00:00
|
|
|
for ( var i = 0; i < annotations.full.length; i++ ) {
|
|
|
|
if ( annotations.full[i].type === this.data.type ) {
|
2011-12-01 00:37:17 +00:00
|
|
|
this.$.addClass( 'es-toolbarButtonTool-down' );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.$.removeClass( 'es-toolbarButtonTool-down' );
|
2011-11-30 23:05:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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' }
|
|
|
|
};
|
|
|
|
|
2011-12-01 22:43:50 +00:00
|
|
|
es.Tool.tools.link = {
|
|
|
|
constructor: es.AnnotationButtonTool,
|
|
|
|
name: 'link',
|
|
|
|
data: { 'type': 'link/internal', 'data': { 'title': '' } }
|
|
|
|
};
|
|
|
|
|
2011-11-30 23:05:06 +00:00
|
|
|
|
|
|
|
es.extendClass( es.AnnotationButtonTool, es.ButtonTool );
|