r104793 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r104792‎ | r104793 | r104794 >
Date:23:51, 30 November 2011
Author:inez
Status:deferred
Tags:
Comment:
Refactoring of Toolbar tools
Modified paths:
  • /trunk/extensions/VisualEditor/modules/es/views/es.ToolbarView.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/es/views/es.ToolbarView.js
@@ -1,17 +1,22 @@
22 // ToolbarView
33 es.ToolbarView = function( $container, surfaceView, config ) {
 4+ // Inheritance TODO: Do we still need it?
45 es.EventEmitter.call( this );
56
67 // References for use in closures
78 var _this = this,
89 $window = $( window );
910
 11+ // Properties
1012 this.surfaceView = surfaceView;
11 - this.$spacer = $('<div></div>');
1213 this.$ = $container;
1314 this.$groups = $( '<div class="es-toolbarGroups"></div>' ).prependTo( this.$ );
 15+ this.$spacer = $('<div></div>');
1416 this.$.after( this.$spacer );
 17+ this.tools = [];
1518
 19+
 20+ // Events
1621 /*
1722 * This code is responsible for switching toolbar into floating mode when scrolling (with
1823 * keyboard or mouse).
@@ -35,19 +40,28 @@
3641 }
3742 }
3843 } );
 44+ this.surfaceView.model.on( 'select', function() {
 45+ _this.updateState();
 46+ } );
 47+ this.surfaceView.on( 'update', function() {
 48+ _this.updateState();
 49+ } );
3950
4051 this.config = config || [
4152 { 'name': 'textStyle', 'items' : [ 'bold', 'italic', 'formatting', 'clear' ] },
4253 ];
 54+ this.setup();
 55+};
4356
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+ }
5266 };
5367
5468 es.ToolbarView.prototype.setup = function() {
@@ -67,6 +81,7 @@
6882 var tool = new toolDefintion.constructor(
6983 this, toolDefintion.name, toolDefintion.data
7084 );
 85+ this.tools.push( tool );
7186 $group.append( tool.$ );
7287 }
7388 }

Status & tagging log