LT-250: Fixing non-active state issue for toolbar

This commit is contained in:
Bruno Alves de Faria 2016-06-29 17:39:40 -03:00 committed by Erik Ziegler
parent 35711b057d
commit 022c534895
4 changed files with 23 additions and 12 deletions

View File

@ -115,7 +115,6 @@ Template.toolbarSection.events({
var elements = $('.imageViewerViewport'); var elements = $('.imageViewerViewport');
var activeTool = toolManager.getActiveTool(); var activeTool = toolManager.getActiveTool();
$('.toolbarSectionButton').removeClass('active');
if (tool === activeTool) { if (tool === activeTool) {
var defaultTool = toolManager.getDefaultTool(); var defaultTool = toolManager.getDefaultTool();
console.log('Setting active tool to: ' + defaultTool); console.log('Setting active tool to: ' + defaultTool);

View File

@ -1,12 +1,12 @@
<template name="toolbarSectionButton"> <template name="toolbarSectionButton">
<div id="{{id}}" class="toolbarSectionButton rp-x-1 {{classes}}" title="{{title}}"> <div id="{{this.id}}" class="toolbarSectionButton rp-x-1 {{this.classes}} {{activeClass}}" title="{{this.title}}">
<div class="svgContainer"> <div class="svgContainer">
<svg> <svg>
<use xlink:href={{svgLink}}></use> <use xlink:href={{this.svgLink}}></use>
</svg> </svg>
</div> </div>
<div class="buttonLabel"> <div class="buttonLabel">
{{title}} {{this.title}}
</div> </div>
</div> </div>
</template> </template>

View File

@ -0,0 +1,13 @@
Template.toolbarSectionButton.helpers({
activeClass() {
const instance = Template.instance();
// Check if the current tool is the active one
if (instance.data.id === Session.get('ToolManagerActiveTool')) {
// Return the active class
return 'active';
}
return;
}
});

View File

@ -1,5 +1,5 @@
var activeTool = "wwwc"; var activeTool = 'wwwc';
var defaultTool = "wwwc"; var defaultTool = 'wwwc';
var tools = {}; var tools = {};
@ -132,6 +132,7 @@ toolManager = {
} else { } else {
tools[toolType].mouse[action](element); tools[toolType].mouse[action](element);
} }
tools[toolType].touch[action](element); tools[toolType].touch[action](element);
}); });
}); });
@ -196,22 +197,20 @@ toolManager = {
elements = $('.imageViewerViewport'); elements = $('.imageViewerViewport');
} }
$('#toolbar .btn-group button').removeClass('active');
var toolButton = document.getElementById(tool);
if (toolButton) {
toolButton.classList.add('active');
}
// Otherwise, set the active tool for all viewport elements // Otherwise, set the active tool for all viewport elements
$(elements).each(function(index, element) { $(elements).each(function(index, element) {
toolManager.setActiveToolForElement(tool, element); toolManager.setActiveToolForElement(tool, element);
}); });
activeTool = tool; activeTool = tool;
// Store the active tool in the session in order to enable reactivity
Session.set('ToolManagerActiveTool', tool);
}, },
getActiveTool: function() { getActiveTool: function() {
if (!activeTool) { if (!activeTool) {
activeTool = defaultTool; activeTool = defaultTool;
} }
return activeTool; return activeTool;
}, },
setDefaultTool: function(tool) { setDefaultTool: function(tool) {