LT-115: Closing the sub tools popup when clicking outside
This commit is contained in:
parent
e996367ed5
commit
94c0e1b25d
@ -2,13 +2,14 @@
|
|||||||
{{#if this.buttonTemplateName}}
|
{{#if this.buttonTemplateName}}
|
||||||
{{>UI.dynamic template=this.buttonTemplateName data=this}}
|
{{>UI.dynamic template=this.buttonTemplateName data=this}}
|
||||||
{{else}}
|
{{else}}
|
||||||
<div id="{{this.id}}"
|
<div id="{{this.id}}" tabindex="1"
|
||||||
class="toolbarSectionButton rp-x-1 {{this.classes}} {{activeClass}} {{#if or this.disabled (disableButton)}}disabled{{/if}} {{#if this.subTools}}expandable{{/if}}"
|
class="toolbarSectionButton rp-x-1 {{this.classes}} {{activeClass}} {{#if or this.disabled (disableButton)}}disabled{{/if}} {{#if this.subTools}}expandable{{/if}}"
|
||||||
title="{{#if this.tooltipTitle}}{{this.tooltipTitle}}{{else}}{{this.title}}{{/if}}">
|
title="{{this.tooltipTitle}}">
|
||||||
|
<div class="focus-holder" tabindex="1"></div>
|
||||||
<div class="svgContainer">
|
<div class="svgContainer">
|
||||||
{{#if this.svgLink}}
|
{{#if this.svgLink}}
|
||||||
<svg>
|
<svg>
|
||||||
<use xlink:href={{this.svgLink}}></use>
|
<use xlink:href={{svgLink}}></use>
|
||||||
</svg>
|
</svg>
|
||||||
{{else}}
|
{{else}}
|
||||||
<i class={{iconClasses}}></i>
|
<i class={{iconClasses}}></i>
|
||||||
|
|||||||
@ -3,20 +3,42 @@ import { Template } from 'meteor/templating';
|
|||||||
import { Session } from 'meteor/session';
|
import { Session } from 'meteor/session';
|
||||||
import { _ } from 'meteor/underscore';
|
import { _ } from 'meteor/underscore';
|
||||||
|
|
||||||
Template.toolbarSectionButton.helpers({
|
Template.toolbarSectionButton.onCreated(() => {
|
||||||
activeClass() {
|
const instance = Template.instance();
|
||||||
|
|
||||||
|
instance.isActive = activeToolId => {
|
||||||
// TODO: Find a way to prevent the 'flash' after a click, but before this helper runs
|
// TODO: Find a way to prevent the 'flash' after a click, but before this helper runs
|
||||||
const instance = Template.instance();
|
const instance = Template.instance();
|
||||||
const subTools = instance.data.subTools;
|
const subTools = instance.data.subTools;
|
||||||
const currentId = instance.data.id;
|
const currentId = instance.data.id;
|
||||||
const activeId = Session.get('ToolManagerActiveTool');
|
const isCurrentTool = currentId === activeToolId;
|
||||||
const isCurrentTool = currentId === activeId;
|
const isSubTool = subTools && _.findWhere(subTools, { id: activeToolId });
|
||||||
const isSubTool = subTools && _.findWhere(subTools, { id: activeId });
|
|
||||||
|
|
||||||
// Check if the current tool or a sub tool is the active one
|
// Check if the current tool or a sub tool is the active one
|
||||||
if (isCurrentTool || isSubTool) {
|
return isCurrentTool || isSubTool;
|
||||||
// Return the active class
|
};
|
||||||
return 'active';
|
});
|
||||||
|
|
||||||
|
Template.toolbarSectionButton.helpers({
|
||||||
|
activeClass() {
|
||||||
|
const instance = Template.instance();
|
||||||
|
const activeToolId = Session.get('ToolManagerActiveTool');
|
||||||
|
const isActive = instance.isActive(activeToolId);
|
||||||
|
return isActive ? 'active' : '';
|
||||||
|
},
|
||||||
|
|
||||||
|
svgLink() {
|
||||||
|
const instance = Template.instance();
|
||||||
|
const subTools = instance.data.subTools;
|
||||||
|
const defaultSvgLink = instance.data.svgLink;
|
||||||
|
const activeToolId = Session.get('ToolManagerActiveTool');
|
||||||
|
const currentId = instance.data.id;
|
||||||
|
|
||||||
|
if (subTools && activeToolId !== currentId && instance.isActive(activeToolId)) {
|
||||||
|
const subTool = _.findWhere(subTools, { id: activeToolId });
|
||||||
|
return subTool ? subTool.svgLink : defaultSvgLink;
|
||||||
|
} else {
|
||||||
|
return defaultSvgLink;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@ -7,6 +7,7 @@
|
|||||||
cursor: pointer
|
cursor: pointer
|
||||||
display: inline-block
|
display: inline-block
|
||||||
min-width: 30px
|
min-width: 30px
|
||||||
|
outline: none
|
||||||
position: relative
|
position: relative
|
||||||
text-align: center
|
text-align: center
|
||||||
|
|
||||||
|
|||||||
@ -1,9 +1,32 @@
|
|||||||
import { Template } from 'meteor/templating';
|
import { Template } from 'meteor/templating';
|
||||||
|
import { Meteor } from 'meteor/meteor';
|
||||||
|
|
||||||
Template.toolbarSectionTools.events({
|
Template.toolbarSectionTools.events({
|
||||||
'click .expandable'(event, instance) {
|
'click .expandable'(event, instance) {
|
||||||
const $target = $(event.currentTarget);
|
const $target = $(event.currentTarget);
|
||||||
const isExpanded = $target.hasClass('expanded');
|
const isExpanded = $target.hasClass('expanded');
|
||||||
$target.toggleClass('expanded', !isExpanded);
|
$target.toggleClass('expanded', !isExpanded);
|
||||||
|
},
|
||||||
|
|
||||||
|
'focusout .expandable'(event, instance) {
|
||||||
|
const target = event.target;
|
||||||
|
const currentTarget = event.currentTarget;
|
||||||
|
|
||||||
|
// Postpone the execution to be able to get the focused element
|
||||||
|
Meteor.defer(() => {
|
||||||
|
const $focused = $(':focus');
|
||||||
|
const $expandable = $(currentTarget).closest('.expandable');
|
||||||
|
const focusInside = $expandable.find(':focus').length;
|
||||||
|
|
||||||
|
// Check if the expandable lost the focus
|
||||||
|
if (!$focused.length || !focusInside) {
|
||||||
|
// Stop here if focus is going from subtool to expandable tool
|
||||||
|
if (currentTarget !== target && $focused[0] === currentTarget) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$expandable.removeClass('expanded');
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user