snappymail/dev/Common/Globals.js

99 lines
2.1 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
2020-08-27 21:45:47 +08:00
export const $html = document.documentElement;
export const $htmlCL = $html.classList;
2016-06-07 05:57:52 +08:00
/**
* @type {?}
*/
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
/**
* @type {boolean}
*/
export const useKeyboardShortcuts = ko.observable(true);
/**
* @type {boolean}
*/
export const bMobileDevice = (/android|iphone|ipod|ipad|blackberry|mobile/i).test(
2020-09-15 15:29:25 +08:00
(navigator.userAgent && navigator.userAgent.toLowerCase()) || ''
);
2016-06-07 05:57:52 +08:00
2016-10-19 01:52:43 +08:00
export const VIEW_MODELS = {
2016-06-07 05:57:52 +08:00
settings: [],
'settings-removed': [],
'settings-disabled': []
};
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('');
export const leftPanelWidth = ko.observable(0);
2017-02-09 01:48:53 +08:00
leftPanelDisabled.subscribe((value) => {
if (value && moveAction()) {
moveAction(false);
}
});
moveAction.subscribe((value) => {
if (value && leftPanelDisabled()) {
leftPanelDisabled(false);
}
});
2016-06-07 05:57:52 +08:00
// keys
export const keyScopeReal = ko.observable(KeyState.All);
export const keyScopeFake = ko.observable(KeyState.All);
export const keyScope = ko.computed({
2016-07-02 06:49:59 +08:00
read: () => keyScopeFake(),
write: (value) => {
2019-07-05 03:19:24 +08:00
if (KeyState.Menu !== value) {
if (KeyState.Compose === value) {
2016-06-07 05:57:52 +08:00
// disableKeyFilter
key.filter = () => useKeyboardShortcuts();
2019-07-05 03:19:24 +08:00
} else {
2016-06-07 05:57:52 +08:00
// restoreKeyFilter
key.filter = (event) => {
2019-07-05 03:19:24 +08:00
if (useKeyboardShortcuts()) {
2020-09-15 15:29:25 +08:00
const el = event.target,
nodeName = el ? el.nodeName : '';
2016-06-07 05:57:52 +08:00
2019-07-05 03:19:24 +08:00
return !(
2020-09-15 15:29:25 +08:00
'INPUT' === nodeName ||
'SELECT' === nodeName ||
'TEXTAREA' === nodeName ||
(el && el.contentEditable)
2016-06-07 05:57:52 +08:00
);
}
return false;
};
}
keyScopeFake(value);
2019-07-05 03:19:24 +08:00
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) => {
// console.log('keyScope=' + sValue); // DEBUG
key.setScope(value);
2016-06-07 05:57:52 +08:00
});
dropdownVisibility.subscribe((value) => {
2019-07-05 03:19:24 +08:00
if (value) {
2016-06-07 05:57:52 +08:00
keyScope(KeyState.Menu);
2019-07-05 03:19:24 +08:00
} else if (KeyState.Menu === key.getScope()) {
2016-06-07 05:57:52 +08:00
keyScope(keyScopeFake());
}
});