Make Bold and Italic toolbar buttons works (when clicked)

This commit is contained in:
Inez Korczynski 2011-11-30 07:42:10 +00:00
parent af39b6dc47
commit 4d3e38756f
4 changed files with 24 additions and 6 deletions

View file

@ -2,7 +2,7 @@ es.BoldButtonTool = function( toolbar ) {
es.ButtonTool.call( this, toolbar, 'bold' );
};
es.BoldButtonTool.prototype.updateState = function ( selection, annotations ) {
es.BoldButtonTool.prototype.updateState = function( selection, annotations ) {
for ( var i = 0; i < annotations.length; i++ ) {
if ( annotations[i].type === 'textStyle/bold' ) {
this.$.addClass( 'es-toolbarTool-down' );
@ -12,6 +12,16 @@ es.BoldButtonTool.prototype.updateState = function ( selection, annotations ) {
this.$.removeClass( 'es-toolbarTool-down' );
};
es.BoldButtonTool.prototype.onClick = function() {
var method = this.$.hasClass( 'es-toolbarTool-down' ) ? 'clear' : 'set';
var tx = this.toolbar.surfaceView.model.getDocument().prepareContentAnnotation(
this.toolbar.surfaceView.currentSelection,
method,
{ 'type': 'textStyle/bold' }
);
this.toolbar.surfaceView.model.transact( tx );
};
es.ToolbarView.tools.bold = es.BoldButtonTool;
es.extendClass( es.BoldButtonTool, es.ButtonTool );

View file

@ -13,8 +13,6 @@ es.ButtonTool = function( toolbar, name ) {
};
es.ButtonTool.prototype.onClick = function( e ) {
console.log( this.$ );
};
};
es.extendClass( es.ButtonTool, es.Tool );

View file

@ -2,7 +2,7 @@ es.ItalicButtonTool = function( toolbar ) {
es.ButtonTool.call( this, toolbar, 'italic' );
};
es.ItalicButtonTool.prototype.updateState = function ( selection, annotations ) {
es.ItalicButtonTool.prototype.updateState = function( selection, annotations ) {
for ( var i = 0; i < annotations.length; i++ ) {
if ( annotations[i].type === 'textStyle/italic' ) {
this.$.addClass( 'es-toolbarTool-down' );
@ -12,6 +12,16 @@ es.ItalicButtonTool.prototype.updateState = function ( selection, annotations )
this.$.removeClass( 'es-toolbarTool-down' );
};
es.ItalicButtonTool.prototype.onClick = function() {
var method = this.$.hasClass( 'es-toolbarTool-down' ) ? 'clear' : 'set';
var tx = this.toolbar.surfaceView.model.getDocument().prepareContentAnnotation(
this.toolbar.surfaceView.currentSelection,
method,
{ 'type': 'textStyle/italic' }
);
this.toolbar.surfaceView.model.transact( tx );
};
es.ToolbarView.tools.italic = es.ItalicButtonTool;
es.extendClass( es.ItalicButtonTool, es.ButtonTool );

View file

@ -23,5 +23,5 @@ es.Tool = function( toolbar ) {
} );
};
es.Tool.prototype.updateState = function () {
es.Tool.prototype.updateState = function() {
};