Index: trunk/extensions/VisualEditor/modules/es/views/es.ToolbarView.js |
— | — | @@ -1,17 +1,22 @@ |
2 | 2 | // ToolbarView |
3 | 3 | es.ToolbarView = function( $container, surfaceView, config ) { |
| 4 | + // Inheritance TODO: Do we still need it? |
4 | 5 | es.EventEmitter.call( this ); |
5 | 6 | |
6 | 7 | // References for use in closures |
7 | 8 | var _this = this, |
8 | 9 | $window = $( window ); |
9 | 10 | |
| 11 | + // Properties |
10 | 12 | this.surfaceView = surfaceView; |
11 | | - this.$spacer = $('<div></div>'); |
12 | 13 | this.$ = $container; |
13 | 14 | this.$groups = $( '<div class="es-toolbarGroups"></div>' ).prependTo( this.$ ); |
| 15 | + this.$spacer = $('<div></div>'); |
14 | 16 | this.$.after( this.$spacer ); |
| 17 | + this.tools = []; |
15 | 18 | |
| 19 | + |
| 20 | + // Events |
16 | 21 | /* |
17 | 22 | * This code is responsible for switching toolbar into floating mode when scrolling (with |
18 | 23 | * keyboard or mouse). |
— | — | @@ -35,19 +40,28 @@ |
36 | 41 | } |
37 | 42 | } |
38 | 43 | } ); |
| 44 | + this.surfaceView.model.on( 'select', function() { |
| 45 | + _this.updateState(); |
| 46 | + } ); |
| 47 | + this.surfaceView.on( 'update', function() { |
| 48 | + _this.updateState(); |
| 49 | + } ); |
39 | 50 | |
40 | 51 | this.config = config || [ |
41 | 52 | { 'name': 'textStyle', 'items' : [ 'bold', 'italic', 'formatting', 'clear' ] }, |
42 | 53 | ]; |
| 54 | + this.setup(); |
| 55 | +}; |
43 | 56 | |
44 | | - this.setup() |
45 | | - |
46 | | - this.surfaceView.model.on( 'select', function( selection ) { |
47 | | - _this.emit( 'update' ); |
48 | | - } ); |
49 | | - this.surfaceView.on( 'update', function() { |
50 | | - _this.emit( 'update' ); |
51 | | - } ); |
| 57 | +es.ToolbarView.prototype.updateState = function() { |
| 58 | + var selection = this.surfaceView.currentSelection, |
| 59 | + annotations; |
| 60 | + |
| 61 | + if( selection.from === selection.to ) { |
| 62 | + annotations = this.surfaceView.documentView.model.getAnnotationsFromOffset( selection.to ); |
| 63 | + } else { |
| 64 | + annotations = this.surfaceView.documentView.model.getAnnotationsFromRange( selection ); |
| 65 | + } |
52 | 66 | }; |
53 | 67 | |
54 | 68 | es.ToolbarView.prototype.setup = function() { |
— | — | @@ -67,6 +81,7 @@ |
68 | 82 | var tool = new toolDefintion.constructor( |
69 | 83 | this, toolDefintion.name, toolDefintion.data |
70 | 84 | ); |
| 85 | + this.tools.push( tool ); |
71 | 86 | $group.append( tool.$ ); |
72 | 87 | } |
73 | 88 | } |