diff --git a/dev/App/Abstract.js b/dev/App/Abstract.js index 553a1d5b5..d9e85e3b2 100644 --- a/dev/App/Abstract.js +++ b/dev/App/Abstract.js @@ -7,7 +7,7 @@ import { bMobileDevice } from 'Common/Globals'; -import { pString, detectDropdownVisibility } from 'Common/Utils'; +import { pString } from 'Common/Utils'; import { KeyState } from 'Common/Enums'; import { root, rootAdmin, rootUser, populateAuthSuffix } from 'Common/Links'; @@ -48,9 +48,7 @@ class AbstractApp extends AbstractBoot { $doc.addEventListener('keypress', fn); $doc.addEventListener('click', fn); - key('esc, enter', KeyState.All, () => { - detectDropdownVisibility(); - }); + key('esc, enter', KeyState.All, () => rl.Dropdowns.detectVisibility()); } remote() { diff --git a/dev/Common/Utils.js b/dev/Common/Utils.js index ef5d892d8..b1f893270 100644 --- a/dev/Common/Utils.js +++ b/dev/Common/Utils.js @@ -1,4 +1,3 @@ -import { dropdownVisibility, data as GlobalsData } from 'Common/Globals'; import { ComposeType, SaveSettingsStep, FolderType } from 'Common/Enums'; import { Mime } from 'Common/Mime'; @@ -767,10 +766,6 @@ export function selectElement(element) { sel.addRange(range); } -export const detectDropdownVisibility = (()=> - dropdownVisibility(!!GlobalsData.aBootstrapDropdowns.find(item => item.hasClass('open'))) -).debounce(50); - /** * @param {boolean=} delay = false */ diff --git a/dev/External/ko.js b/dev/External/ko.js index 4279d1415..af067af72 100644 --- a/dev/External/ko.js +++ b/dev/External/ko.js @@ -91,13 +91,7 @@ ko.bindingHandlers.tooltipErrorTip = { }; ko.bindingHandlers.registrateBootstrapDropdown = { - init: (element) => { - const Globals = require('Common/Globals'); - if (Globals && Globals.data.aBootstrapDropdowns) { - Globals.data.aBootstrapDropdowns.push($(element)); - element.addEventListener('click', () => require('Common/Utils').detectDropdownVisibility()); - } - } + init: element => rl.Dropdowns.registrate(element) }; ko.bindingHandlers.openDropdownTrigger = { @@ -110,7 +104,7 @@ ko.bindingHandlers.openDropdownTrigger = { t.focus(); - require('Common/Utils').detectDropdownVisibility(); + rl.Dropdowns.detectVisibility(); fValueAccessor()(false); } } diff --git a/dev/bootstrap.js b/dev/bootstrap.js index 6d91d63d1..3f2cbf392 100644 --- a/dev/bootstrap.js +++ b/dev/bootstrap.js @@ -1,5 +1,4 @@ -import { detectDropdownVisibility } from 'Common/Utils'; -import { $html, $htmlCL, data as GlobalsData, bMobileDevice } from 'Common/Globals'; +import { $html, $htmlCL, data as GlobalsData, bMobileDevice, dropdownVisibility } from 'Common/Globals'; import * as Enums from 'Common/Enums'; import * as Plugins from 'Common/Plugins'; import { i18n } from 'Common/Translator'; @@ -30,12 +29,10 @@ export default (App) => { } } }); - addEventListener('unload', () => { - GlobalsData.bUnload = true; - }); + addEventListener('unload', () => GlobalsData.bUnload = true); $htmlCL.add(bMobileDevice ? 'mobile' : 'no-mobile'); - $html.on('click.dropdown.data-api', detectDropdownVisibility); + $html.on('click.dropdown.data-api', ()=>rl.Dropdowns.detectVisibility()); const rl = window.rl || {}; @@ -51,6 +48,15 @@ export default (App) => { rl.EmailModel = EmailModel; rl.Enums = Enums; + rl.Dropdowns = []; + rl.Dropdowns.registrate = function(element) { + this.push(element); + element.addEventListener('click', () => rl.Dropdowns.detectVisibility()); + }; + rl.Dropdowns.detectVisibility = (() => + dropdownVisibility(!!rl.Dropdowns.find(item => item.classList.contains('open'))) + ).debounce(50); + window.rl = rl; const start = () => {