es.ToolbarView = function( $container, surfaceView ) { // Reference for use in closures var _this = this; this.$ = $container; this.surfaceView = surfaceView; this.tools = [ { type: 'text', items: [ { type: 'bold', execute: function( toolbarView, tool ) { var tx; if ( tool.$.hasClass( 'es-toolbarTool-down' ) ) { tx = toolbarView.surfaceView.model.getDocument().prepareContentAnnotation( toolbarView.currentSelection, 'clear', { 'type': 'textStyle/bold' } ); } else { tx = toolbarView.surfaceView.model.getDocument().prepareContentAnnotation( toolbarView.currentSelection, 'set', { 'type': 'textStyle/bold' } ); } toolbarView.surfaceView.model.transact( tx ); }, active: function( annotations ) { for ( var i = 0; i < annotations.length; i++ ) { if ( annotations[i].type === 'textStyle/bold' ) { return true; } } return false; } }, { type: 'italic', execute: function( toolbarView, tool ) { var tx; if ( tool.$.hasClass( 'es-toolbarTool-down' ) ) { tx = toolbarView.surfaceView.model.getDocument().prepareContentAnnotation( toolbarView.currentSelection, 'clear', { 'type': 'textStyle/italic' } ); } else { tx = toolbarView.surfaceView.model.getDocument().prepareContentAnnotation( toolbarView.currentSelection, 'set', { 'type': 'textStyle/italic' } ); } toolbarView.surfaceView.model.transact( tx ); }, active: function( annotations ) { for ( var i = 0; i < annotations.length; i++ ) { if ( annotations[i].type === 'textStyle/italic' ) { return true; } } return false; } } ] }, '/', { type: 'list', items: [ { type: 'bullet', execute: function( ) { }, active: function( ) { } }, { type: 'number', execute: function( ) { }, active: function( ) { } } ] } ]; this.render(); this.currentSelection = new es.Range(); this.currentAnnotations = []; this.surfaceView.model.on( 'select', function( selection ) { _this.onSelect( selection ); } ); }; es.ToolbarView.prototype.render = function() { var _this = this; for ( var i = this.tools.length - 1; i >= 0; i-- ) { if ( !es.isPlainObject( this.tools[i] ) ) { if ( this.tools[i] === '/' ) { this.$.prepend( '