snappymail/dev/Common/Globals.js

56 lines
1.4 KiB
JavaScript
Raw Normal View History

2016-06-07 05:57:52 +08:00
import ko from 'ko';
2019-07-05 03:19:24 +08:00
import { KeyState } from 'Common/Enums';
2016-06-07 05:57:52 +08:00
export const doc = document;
export const $htmlCL = doc.documentElement.classList;
export const Settings = rl.settings;
2016-06-07 05:57:52 +08:00
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 leftPanelType = ko.observable('');
leftPanelDisabled.subscribe(value => {
value && moveAction() && moveAction(false);
$htmlCL.toggle('rl-left-panel-disabled', value);
});
leftPanelType.subscribe(sValue => {
$htmlCL.toggle('rl-left-panel-none', 'none' === sValue);
$htmlCL.toggle('rl-left-panel-short', 'short' === sValue);
});
2017-02-09 01:48:53 +08:00
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(KeyState.All);
export const keyScope = (()=>{
let keyScopeFake = KeyState.All;
dropdownVisibility.subscribe(value => {
if (value) {
keyScope(KeyState.Menu);
} else if (KeyState.Menu === shortcuts.getScope()) {
keyScope(keyScopeFake);
2016-06-07 05:57:52 +08:00
}
});
return ko.computed({
read: () => keyScopeFake,
write: value => {
if (KeyState.Menu !== value) {
keyScopeFake = value;
if (dropdownVisibility()) {
value = KeyState.Menu;
}
}
2016-06-07 05:57:52 +08:00
keyScopeReal(value);
}
});
})();
2016-06-07 05:57:52 +08:00
keyScopeReal.subscribe(value => shortcuts.setScope(value));