From 826437950ca9a20a69c40553b1a1fd7b493eaa98 Mon Sep 17 00:00:00 2001 From: Catrope Date: Thu, 22 Mar 2012 13:53:26 -0700 Subject: [PATCH] adding clearState function for tools and using clearState if no selection exists Originally committed in SVN as r114418 by Christian, missed the git conversion Change-Id: I56e91c170670519fa2b482a4b7f30cdcbc8ff163 --- modules/ve/ui/ve.ui.Tool.js | 4 +++ modules/ve/ui/ve.ui.Toolbar.js | 46 ++++++++++++++++++---------------- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/modules/ve/ui/ve.ui.Tool.js b/modules/ve/ui/ve.ui.Tool.js index 64d74eebc8..ff4b9bfd77 100644 --- a/modules/ve/ui/ve.ui.Tool.js +++ b/modules/ve/ui/ve.ui.Tool.js @@ -22,3 +22,7 @@ ve.ui.Tool.tools = {}; ve.ui.Tool.prototype.updateState = function() { throw 'Tool.updateState not implemented in this subclass:' + this.constructor; }; + +ve.ui.Tool.prototype.clearState = function() { + this.$.removeClass( 'es-toolbarButtonTool-down' ); +} \ No newline at end of file diff --git a/modules/ve/ui/ve.ui.Toolbar.js b/modules/ve/ui/ve.ui.Toolbar.js index 8f1dfc4417..4c8974202d 100644 --- a/modules/ve/ui/ve.ui.Toolbar.js +++ b/modules/ve/ui/ve.ui.Toolbar.js @@ -17,31 +17,35 @@ ve.ui.Toolbar = function( $container, surfaceView, config ) { this.tools = []; this.surfaceView.surfaceObserver.on( 'select', function ( selection ) { - var annotations = _this.surfaceView.getAnnotations(), - nodes = [], - model = _this.surfaceView.documentView.model; - - if ( selection.from === selection.to ) { - nodes.push( model.getNodeFromOffset( selection.from ) ); - } else { - var startNode = model.getNodeFromOffset( selection.start ), - endNode = model.getNodeFromOffset( selection.end ); - if ( startNode === endNode ) { - nodes.push( startNode ); - } else { - model.traverseLeafNodes( function( node ) { - nodes.push( node ); - if( node === endNode ) { - return false; - } - }, startNode ); - } - } - if ( selection !== null ) { + var annotations = _this.surfaceView.getAnnotations(), + nodes = [], + model = _this.surfaceView.documentView.model; + + if ( selection.from === selection.to ) { + nodes.push( model.getNodeFromOffset( selection.from ) ); + } else { + var startNode = model.getNodeFromOffset( selection.start ), + endNode = model.getNodeFromOffset( selection.end ); + if ( startNode === endNode ) { + nodes.push( startNode ); + } else { + model.traverseLeafNodes( function( node ) { + nodes.push( node ); + if( node === endNode ) { + return false; + } + }, startNode ); + } + } + for( var i = 0; i < _this.tools.length; i++ ) { _this.tools[i].updateState( annotations, nodes ); } + } else { + for( var i = 0; i < _this.tools.length; i++ ) { + _this.tools[i].clearState(); + } } });