LT-115: Closing the sub tools popup when clicking outside
This commit is contained in:
1 parent
e996367ed5
commit
94c0e1b25d
4 files changed
+58
-11
No files matched your search
+23
@@ -1,9 +1,32 @@
|
||||
import { Template } from 'meteor/templating';
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
|
||||
Template.toolbarSectionTools.events({
|
||||
'click .expandable'(event, instance) {
|
||||
const $target = $(event.currentTarget);
|
||||
const isExpanded = $target.hasClass('expanded');
|
||||
$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');
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user