snappymail/dev/Common/Globals.js

58 lines
1.4 KiB
JavaScript
Raw Normal View History

2016-06-07 05:57:52 +08:00
import ko from 'ko';
import { Scope } from 'Common/Enums';
2016-06-07 05:57:52 +08:00
export const doc = document;
export const $htmlCL = doc.documentElement.classList;
export const elementById = id => doc.getElementById(id);
2016-06-07 05:57:52 +08:00
export const Settings = rl.settings;
2021-03-10 18:44:48 +08:00
export const SettingsGet = rl.settings.get;
2019-07-05 03:19:24 +08:00
export const dropdownVisibility = ko.observable(false).extend({ rateLimit: 0 });
2016-06-07 05:57:52 +08:00
2017-02-09 01:48:53 +08:00
export const moveAction = ko.observable(false);
2016-06-07 05:57:52 +08:00
export const leftPanelDisabled = ko.observable(false);
export const createElement = (name, attr) => {
let el = doc.createElement(name);
attr && Object.entries(attr).forEach(([k,v]) => el.setAttribute(k,v));
return el;
};
leftPanelDisabled.subscribe(value => {
value && moveAction() && moveAction(false);
$htmlCL.toggle('rl-left-panel-disabled', value);
});
2020-09-30 20:07:03 +08:00
moveAction.subscribe(value => value && leftPanelDisabled() && leftPanelDisabled(false));
2017-02-09 01:48:53 +08:00
2016-06-07 05:57:52 +08:00
// keys
export const keyScopeReal = ko.observable(Scope.All);
export const keyScope = (()=>{
let keyScopeFake = Scope.All;
dropdownVisibility.subscribe(value => {
if (value) {
keyScope(Scope.Menu);
} else if (Scope.Menu === shortcuts.getScope()) {
keyScope(keyScopeFake);
2016-06-07 05:57:52 +08:00
}
});
return value => {
if (value) {
if (Scope.Menu !== value) {
keyScopeFake = value;
if (dropdownVisibility()) {
value = Scope.Menu;
}
}
keyScopeReal(value);
shortcuts.setScope(value);
} else {
return keyScopeFake;
}
};
})();