Cleanup Dropdowns handling

This commit is contained in:
the-djmaze 2022-03-08 10:52:08 +01:00
parent ffcd9990eb
commit 04f4538700
5 changed files with 14 additions and 14 deletions

View file

@ -1,7 +1,7 @@
import 'External/User/ko'; import 'External/User/ko';
import { isArray, pString } from 'Common/Utils'; import { isArray, pString } from 'Common/Utils';
import { mailToHelper, setLayoutResizer } from 'Common/UtilsUser'; import { mailToHelper, setLayoutResizer, dropdownsDetectVisibility } from 'Common/UtilsUser';
import { import {
FolderType, FolderType,
@ -88,7 +88,8 @@ class AppUser extends AbstractApp {
const fn = (ev=>$htmlCL.toggle('rl-ctrl-key-pressed', ev.ctrlKey)).debounce(500); const fn = (ev=>$htmlCL.toggle('rl-ctrl-key-pressed', ev.ctrlKey)).debounce(500);
addEventsListener(doc, ['keydown','keyup'], fn); addEventsListener(doc, ['keydown','keyup'], fn);
shortcuts.add('escape,enter', '', () => rl.Dropdowns.detectVisibility()); shortcuts.add('escape,enter', '', dropdownsDetectVisibility);
addEventListener('click', dropdownsDetectVisibility);
} }
/** /**

View file

@ -18,6 +18,7 @@ export const
SettingsGet = Settings.get, SettingsGet = Settings.get,
SettingsCapa = Settings.capa, SettingsCapa = Settings.capa,
dropdowns = [],
dropdownVisibility = ko.observable(false).extend({ rateLimit: 0 }), dropdownVisibility = ko.observable(false).extend({ rateLimit: 0 }),
moveAction = ko.observable(false), moveAction = ko.observable(false),

View file

@ -1,7 +1,7 @@
import { MessageFlagsCache, addRequestedMessage } from 'Common/Cache'; import { MessageFlagsCache, addRequestedMessage } from 'Common/Cache';
import { Notification } from 'Common/Enums'; import { Notification } from 'Common/Enums';
import { MessageSetAction, ComposeType/*, FolderType*/ } from 'Common/EnumsUser'; import { MessageSetAction, ComposeType/*, FolderType*/ } from 'Common/EnumsUser';
import { doc, createElement, elementById } from 'Common/Globals'; import { doc, createElement, elementById, dropdowns, dropdownVisibility } from 'Common/Globals';
import { plainToHtml } from 'Common/Html'; import { plainToHtml } from 'Common/Html';
import { getNotification } from 'Common/Translator'; import { getNotification } from 'Common/Translator';
import { EmailModel } from 'Model/Email'; import { EmailModel } from 'Model/Email';
@ -15,6 +15,10 @@ import Remote from 'Remote/User/Fetch';
export const export const
dropdownsDetectVisibility = (() =>
dropdownVisibility(!!dropdowns.find(item => item.classList.contains('show')))
).debounce(50),
/** /**
* @param {string} link * @param {string} link
* @returns {boolean} * @returns {boolean}

View file

@ -2,8 +2,9 @@ import 'External/ko';
import ko from 'ko'; import ko from 'ko';
import { HtmlEditor } from 'Common/Html'; import { HtmlEditor } from 'Common/Html';
import { timeToNode } from 'Common/Translator'; import { timeToNode } from 'Common/Translator';
import { elementById, addEventsListeners } from 'Common/Globals'; import { elementById, addEventsListeners, dropdowns } from 'Common/Globals';
import { isArray } from 'Common/Utils'; import { isArray } from 'Common/Utils';
import { dropdownsDetectVisibility } from 'Common/UtilsUser';
import { EmailAddressesComponent } from 'Component/EmailAddresses'; import { EmailAddressesComponent } from 'Component/EmailAddresses';
import { ThemeStore } from 'Stores/Theme'; import { ThemeStore } from 'Stores/Theme';
import { moveMessagesToFolder } from 'Common/Folders'; import { moveMessagesToFolder } from 'Common/Folders';
@ -231,7 +232,7 @@ Object.assign(ko.bindingHandlers, {
registerBootstrapDropdown: { registerBootstrapDropdown: {
init: element => { init: element => {
rl.Dropdowns.register(element); dropdowns.push(element);
element.ddBtn = new BSN.Dropdown(element.querySelector('.dropdown-toggle')); element.ddBtn = new BSN.Dropdown(element.querySelector('.dropdown-toggle'));
} }
}, },
@ -243,7 +244,7 @@ Object.assign(ko.bindingHandlers, {
el.open || el.toggle(); el.open || el.toggle();
// el.focus(); // el.focus();
rl.Dropdowns.detectVisibility(); dropdownsDetectVisibility();
fValueAccessor()(false); fValueAccessor()(false);
} }
} }

9
dev/bootstrap.js vendored
View file

@ -1,4 +1,4 @@
import { dropdownVisibility, Settings } from 'Common/Globals'; import { Settings } from 'Common/Globals';
import { i18n } from 'Common/Translator'; import { i18n } from 'Common/Translator';
import { root } from 'Common/Links'; import { root } from 'Common/Links';
@ -18,13 +18,6 @@ export default App => {
} }
}; };
rl.Dropdowns = [];
rl.Dropdowns.register = function(element) { this.push(element); };
rl.Dropdowns.detectVisibility = (() =>
dropdownVisibility(!!rl.Dropdowns.find(item => item.classList.contains('show')))
).debounce(50);
addEventListener('click', ()=>rl.Dropdowns.detectVisibility());
rl.route = { rl.route = {
root: () => { root: () => {
rl.route.off(); rl.route.off();