mirror of
https://github.com/the-djmaze/snappymail.git
synced 2024-12-31 03:52:01 +08:00
Revamp aBootstrapDropdowns
This commit is contained in:
parent
8846c453b1
commit
31bb7267ec
4 changed files with 16 additions and 23 deletions
|
@ -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() {
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
10
dev/External/ko.js
vendored
10
dev/External/ko.js
vendored
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
18
dev/bootstrap.js
vendored
18
dev/bootstrap.js
vendored
|
@ -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 = () => {
|
||||
|
|
Loading…
Reference in a new issue