dispatchEvent(new CustomEvent(...)) to fireEvent(...)

This commit is contained in:
the-djmaze 2022-02-11 12:21:16 +01:00
parent 2d46eaa783
commit 44ee236709
9 changed files with 25 additions and 21 deletions

View file

@ -1,5 +1,5 @@
import * as Links from 'Common/Links'; import * as Links from 'Common/Links';
import { doc, SettingsGet } from 'Common/Globals'; import { doc, SettingsGet, fireEvent } from 'Common/Globals';
let notificator = null, let notificator = null,
player = null, player = null,
@ -12,7 +12,7 @@ let notificator = null,
player.src = url; player.src = url;
player.play(); player.play();
name = name.trim(); name = name.trim();
dispatchEvent(new CustomEvent('audio.start', {detail:name.replace(/\.([a-z0-9]{3})$/, '') || 'audio'})); fireEvent('audio.start', name.replace(/\.([a-z0-9]{3})$/, '') || 'audio');
} }
}, },
@ -89,7 +89,7 @@ export const SMAudio = new class {
pause() { pause() {
player && player.pause(); player && player.pause();
dispatchEvent(new CustomEvent('audio.stop')); fireEvent('audio.stop');
} }
playMp3(url, name) { playMp3(url, name) {

View file

@ -29,6 +29,8 @@ export const
return el; return el;
}, },
fireEvent = (name, detail) => dispatchEvent(new CustomEvent(name, {detail:detail})),
// keys // keys
keyScopeReal = ko.observable(Scope.All), keyScopeReal = ko.observable(Scope.All),
keyScope = value => { keyScope = value => {

View file

@ -1,6 +1,6 @@
import ko from 'ko'; import ko from 'ko';
import { koComputable } from 'External/ko'; import { koComputable } from 'External/ko';
import { doc, $htmlCL, elementById } from 'Common/Globals'; import { doc, $htmlCL, elementById, fireEvent } from 'Common/Globals';
import { isFunction, forEachObjectValue, forEachObjectEntry } from 'Common/Utils'; import { isFunction, forEachObjectValue, forEachObjectEntry } from 'Common/Utils';
let let
@ -137,7 +137,7 @@ const
vm.registerPopupKeyDown(); vm.registerPopupKeyDown();
} }
dispatchEvent(new CustomEvent('rl-view-model', {detail:vm})); fireEvent('rl-view-model', vm);
} else { } else {
console.log('Cannot find view model position: ' + position); console.log('Cannot find view model position: ' + position);
} }

View file

@ -4,7 +4,7 @@ import { UNUSED_OPTION_VALUE } from 'Common/Consts';
import { isArray, getKeyByValue, forEachObjectEntry, b64EncodeJSONSafe } from 'Common/Utils'; import { isArray, getKeyByValue, forEachObjectEntry, b64EncodeJSONSafe } from 'Common/Utils';
import { ClientSideKeyName, FolderType, FolderMetadataKeys } from 'Common/EnumsUser'; import { ClientSideKeyName, FolderType, FolderMetadataKeys } from 'Common/EnumsUser';
import { getFolderFromCacheList, setFolder, setFolderInboxName, setFolderHash } from 'Common/Cache'; import { getFolderFromCacheList, setFolder, setFolderInboxName, setFolderHash } from 'Common/Cache';
import { Settings, SettingsGet } from 'Common/Globals'; import { Settings, SettingsGet, fireEvent } from 'Common/Globals';
import * as Local from 'Storage/Client'; import * as Local from 'Storage/Client';
@ -394,7 +394,7 @@ export class FolderModel extends AbstractModel {
messageCountUnread: unread => { messageCountUnread: unread => {
if (FolderType.Inbox === folder.type()) { if (FolderType.Inbox === folder.type()) {
dispatchEvent(new CustomEvent('mailbox.inbox-unread-count', {detail:unread})); fireEvent('mailbox.inbox-unread-count', unread);
} }
} }
}); });

View file

@ -1,6 +1,7 @@
import { SMAudio } from 'Common/Audio'; import { SMAudio } from 'Common/Audio';
import * as Links from 'Common/Links'; import * as Links from 'Common/Links';
import { addObservablesTo } from 'Common/Utils'; import { addObservablesTo } from 'Common/Utils';
import { fireEvent } from 'Common/Globals';
/** /**
* Might not work due to the new ServiceWorkerRegistration.showNotification * Might not work due to the new ServiceWorkerRegistration.showNotification
@ -12,7 +13,7 @@ const HTML5Notification = window.Notification,
dispatchMessage = data => { dispatchMessage = data => {
focus(); focus();
if (data.Folder && data.Uid) { if (data.Folder && data.Uid) {
dispatchEvent(new CustomEvent('mailbox.message.show', {detail:data})); fireEvent('mailbox.message.show', data);
} else if (data.Url) { } else if (data.Url) {
rl.route.setHash(data.Url); rl.route.setHash(data.Url);
} }

View file

@ -3,7 +3,7 @@ import { koComputable } from 'External/ko';
import { Layout, EditorDefaultType } from 'Common/EnumsUser'; import { Layout, EditorDefaultType } from 'Common/EnumsUser';
import { pInt, addObservablesTo } from 'Common/Utils'; import { pInt, addObservablesTo } from 'Common/Utils';
import { $htmlCL, SettingsGet } from 'Common/Globals'; import { $htmlCL, SettingsGet, fireEvent } from 'Common/Globals';
import { ThemeStore } from 'Stores/Theme'; import { ThemeStore } from 'Stores/Theme';
export const SettingsUserStore = new class { export const SettingsUserStore = new class {
@ -48,7 +48,7 @@ export const SettingsUserStore = new class {
$htmlCL.toggle('rl-no-preview-pane', Layout.NoPreview === value); $htmlCL.toggle('rl-no-preview-pane', Layout.NoPreview === value);
$htmlCL.toggle('rl-side-preview-pane', Layout.SidePreview === value); $htmlCL.toggle('rl-side-preview-pane', Layout.SidePreview === value);
$htmlCL.toggle('rl-bottom-preview-pane', Layout.BottomPreview === value); $htmlCL.toggle('rl-bottom-preview-pane', Layout.BottomPreview === value);
dispatchEvent(new CustomEvent('rl-layout', {detail:value})); fireEvent('rl-layout', value);
}; };
self.layout.subscribe(toggleLayout); self.layout.subscribe(toggleLayout);
ThemeStore.isMobile.subscribe(toggleLayout); ThemeStore.isMobile.subscribe(toggleLayout);

View file

@ -13,7 +13,7 @@ import {
import { UNUSED_OPTION_VALUE } from 'Common/Consts'; import { UNUSED_OPTION_VALUE } from 'Common/Consts';
import { doc, leftPanelDisabled, moveAction, Settings, SettingsCapa, SettingsGet } from 'Common/Globals'; import { doc, leftPanelDisabled, moveAction, Settings, SettingsCapa, SettingsGet, fireEvent } from 'Common/Globals';
import { computedPaginatorHelper, showMessageComposer, folderListOptionsBuilder } from 'Common/UtilsUser'; import { computedPaginatorHelper, showMessageComposer, folderListOptionsBuilder } from 'Common/UtilsUser';
import { FileInfo } from 'Common/File'; import { FileInfo } from 'Common/File';
@ -683,7 +683,7 @@ export class MailMessageList extends AbstractViewRight {
shortcuts.add('enter,open', '', Scope.MessageList, () => { shortcuts.add('enter,open', '', Scope.MessageList, () => {
if (MessageUserStore.message() && this.useAutoSelect()) { if (MessageUserStore.message() && this.useAutoSelect()) {
dispatchEvent(new CustomEvent('mailbox.message-view.toggle-full-screen')); fireEvent('mailbox.message-view.toggle-full-screen');
return false; return false;
} }
}); });

View file

@ -23,7 +23,8 @@ import {
Settings, Settings,
SettingsCapa, SettingsCapa,
getFullscreenElement, getFullscreenElement,
exitFullscreen exitFullscreen,
fireEvent
} from 'Common/Globals'; } from 'Common/Globals';
import { arrayLength, inFocus } from 'Common/Utils'; import { arrayLength, inFocus } from 'Common/Utils';
@ -245,15 +246,15 @@ export class MailMessageView extends AbstractViewRight {
} }
goUpCommand() { goUpCommand() {
dispatchEvent(new CustomEvent('mailbox.message-list.selector.go-up', fireEvent('mailbox.message-list.selector.go-up',
{detail:SettingsUserStore.usePreviewPane() || !!currentMessage()} // bForceSelect SettingsUserStore.usePreviewPane() || !!currentMessage() // bForceSelect
)); );
} }
goDownCommand() { goDownCommand() {
dispatchEvent(new CustomEvent('mailbox.message-list.selector.go-down', fireEvent('mailbox.message-list.selector.go-down',
{detail:SettingsUserStore.usePreviewPane() || !!currentMessage()} // bForceSelect SettingsUserStore.usePreviewPane() || !!currentMessage() // bForceSelect
)); );
} }
toggleFullScreen() { toggleFullScreen() {

View file

@ -13,7 +13,7 @@ import { KeyboardShortcutsHelpPopupView } from 'View/Popup/KeyboardShortcutsHelp
import { AccountPopupView } from 'View/Popup/Account'; import { AccountPopupView } from 'View/Popup/Account';
import { ContactsPopupView } from 'View/Popup/Contacts'; import { ContactsPopupView } from 'View/Popup/Contacts';
import { doc, Settings/*, SettingsGet*/, leftPanelDisabled } from 'Common/Globals'; import { doc, Settings/*, SettingsGet*/, leftPanelDisabled, fireEvent } from 'Common/Globals';
import { ThemeStore } from 'Stores/Theme'; import { ThemeStore } from 'Stores/Theme';
@ -49,7 +49,7 @@ export class SystemDropDownUserView extends AbstractViewRight {
} }
stopPlay() { stopPlay() {
dispatchEvent(new CustomEvent('audio.api.stop')); fireEvent('audio.api.stop');
} }
accountClick(account, event) { accountClick(account, event) {