2016-06-07 05:57:52 +08:00
|
|
|
import ko from 'ko';
|
2021-03-16 23:06:16 +08:00
|
|
|
import { Scope } from 'Common/Enums';
|
2016-06-07 05:57:52 +08:00
|
|
|
|
2021-08-20 21:40:07 +08:00
|
|
|
let keyScopeFake = Scope.All;
|
2021-01-27 07:26:31 +08:00
|
|
|
|
2021-08-20 21:40:07 +08:00
|
|
|
export const
|
2021-01-27 07:26:31 +08:00
|
|
|
|
2021-08-20 21:40:07 +08:00
|
|
|
doc = document,
|
2016-06-07 05:57:52 +08:00
|
|
|
|
2021-08-20 21:40:07 +08:00
|
|
|
$htmlCL = doc.documentElement.classList,
|
2021-02-15 22:20:22 +08:00
|
|
|
|
2021-08-20 21:40:07 +08:00
|
|
|
elementById = id => doc.getElementById(id),
|
2016-06-07 05:57:52 +08:00
|
|
|
|
2021-11-06 00:24:45 +08:00
|
|
|
exitFullscreen = () => getFullscreenElement() && (doc.exitFullscreen || doc.webkitExitFullscreen).call(doc),
|
2021-09-01 17:01:13 +08:00
|
|
|
getFullscreenElement = () => doc.fullscreenElement || doc.webkitFullscreenElement,
|
|
|
|
|
2021-08-20 21:40:07 +08:00
|
|
|
Settings = rl.settings,
|
|
|
|
SettingsGet = Settings.get,
|
2022-02-08 20:48:11 +08:00
|
|
|
SettingsCapa = Settings.capa,
|
2016-06-07 05:57:52 +08:00
|
|
|
|
2021-08-20 21:40:07 +08:00
|
|
|
dropdownVisibility = ko.observable(false).extend({ rateLimit: 0 }),
|
2021-02-04 06:36:36 +08:00
|
|
|
|
2021-08-20 21:40:07 +08:00
|
|
|
moveAction = ko.observable(false),
|
|
|
|
leftPanelDisabled = ko.observable(false),
|
2021-01-27 07:26:31 +08:00
|
|
|
|
2021-08-20 21:40:07 +08:00
|
|
|
createElement = (name, attr) => {
|
|
|
|
let el = doc.createElement(name);
|
|
|
|
attr && Object.entries(attr).forEach(([k,v]) => el.setAttribute(k,v));
|
|
|
|
return el;
|
|
|
|
},
|
2017-02-09 01:48:53 +08:00
|
|
|
|
2022-02-11 19:21:16 +08:00
|
|
|
fireEvent = (name, detail) => dispatchEvent(new CustomEvent(name, {detail:detail})),
|
|
|
|
|
2021-08-20 21:40:07 +08:00
|
|
|
// keys
|
|
|
|
keyScopeReal = ko.observable(Scope.All),
|
|
|
|
keyScope = value => {
|
2021-07-21 20:14:31 +08:00
|
|
|
if (value) {
|
2021-03-16 23:06:16 +08:00
|
|
|
if (Scope.Menu !== value) {
|
2021-01-27 07:26:31 +08:00
|
|
|
keyScopeFake = value;
|
|
|
|
if (dropdownVisibility()) {
|
2021-03-16 23:06:16 +08:00
|
|
|
value = Scope.Menu;
|
2021-01-27 07:26:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
keyScopeReal(value);
|
2021-07-21 20:14:31 +08:00
|
|
|
shortcuts.setScope(value);
|
|
|
|
} else {
|
|
|
|
return keyScopeFake;
|
2021-01-27 07:26:31 +08:00
|
|
|
}
|
2021-07-21 20:14:31 +08:00
|
|
|
};
|
2021-08-20 21:40:07 +08:00
|
|
|
|
|
|
|
dropdownVisibility.subscribe(value => {
|
|
|
|
if (value) {
|
|
|
|
keyScope(Scope.Menu);
|
|
|
|
} else if (Scope.Menu === shortcuts.getScope()) {
|
|
|
|
keyScope(keyScopeFake);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-11-06 19:27:37 +08:00
|
|
|
leftPanelDisabled.toggle = () => leftPanelDisabled(!leftPanelDisabled());
|
2021-08-20 21:40:07 +08:00
|
|
|
leftPanelDisabled.subscribe(value => {
|
|
|
|
value && moveAction() && moveAction(false);
|
|
|
|
$htmlCL.toggle('rl-left-panel-disabled', value);
|
|
|
|
});
|
|
|
|
|
|
|
|
moveAction.subscribe(value => value && leftPanelDisabled() && leftPanelDisabled(false));
|