diff --git a/dev/Common/Audio.js b/dev/Common/Audio.js index 26660d695..32f98d187 100644 --- a/dev/Common/Audio.js +++ b/dev/Common/Audio.js @@ -1,5 +1,5 @@ import * as Links from 'Common/Links'; -import { doc, SettingsGet } from 'Common/Globals'; +import { doc, SettingsGet, fireEvent } from 'Common/Globals'; let notificator = null, player = null, @@ -12,7 +12,7 @@ let notificator = null, player.src = url; player.play(); 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() { player && player.pause(); - dispatchEvent(new CustomEvent('audio.stop')); + fireEvent('audio.stop'); } playMp3(url, name) { diff --git a/dev/Common/Globals.js b/dev/Common/Globals.js index c6aa1d5c0..0f768db53 100644 --- a/dev/Common/Globals.js +++ b/dev/Common/Globals.js @@ -29,6 +29,8 @@ export const return el; }, + fireEvent = (name, detail) => dispatchEvent(new CustomEvent(name, {detail:detail})), + // keys keyScopeReal = ko.observable(Scope.All), keyScope = value => { diff --git a/dev/Knoin/Knoin.js b/dev/Knoin/Knoin.js index 45fa32f83..58657f517 100644 --- a/dev/Knoin/Knoin.js +++ b/dev/Knoin/Knoin.js @@ -1,6 +1,6 @@ import ko from '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'; let @@ -137,7 +137,7 @@ const vm.registerPopupKeyDown(); } - dispatchEvent(new CustomEvent('rl-view-model', {detail:vm})); + fireEvent('rl-view-model', vm); } else { console.log('Cannot find view model position: ' + position); } diff --git a/dev/Model/FolderCollection.js b/dev/Model/FolderCollection.js index 5da86b31e..5ef152cff 100644 --- a/dev/Model/FolderCollection.js +++ b/dev/Model/FolderCollection.js @@ -4,7 +4,7 @@ import { UNUSED_OPTION_VALUE } from 'Common/Consts'; import { isArray, getKeyByValue, forEachObjectEntry, b64EncodeJSONSafe } from 'Common/Utils'; import { ClientSideKeyName, FolderType, FolderMetadataKeys } from 'Common/EnumsUser'; 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'; @@ -394,7 +394,7 @@ export class FolderModel extends AbstractModel { messageCountUnread: unread => { if (FolderType.Inbox === folder.type()) { - dispatchEvent(new CustomEvent('mailbox.inbox-unread-count', {detail:unread})); + fireEvent('mailbox.inbox-unread-count', unread); } } }); diff --git a/dev/Stores/User/Notification.js b/dev/Stores/User/Notification.js index 4b2b3f713..94083905c 100644 --- a/dev/Stores/User/Notification.js +++ b/dev/Stores/User/Notification.js @@ -1,6 +1,7 @@ import { SMAudio } from 'Common/Audio'; import * as Links from 'Common/Links'; import { addObservablesTo } from 'Common/Utils'; +import { fireEvent } from 'Common/Globals'; /** * Might not work due to the new ServiceWorkerRegistration.showNotification @@ -12,7 +13,7 @@ const HTML5Notification = window.Notification, dispatchMessage = data => { focus(); if (data.Folder && data.Uid) { - dispatchEvent(new CustomEvent('mailbox.message.show', {detail:data})); + fireEvent('mailbox.message.show', data); } else if (data.Url) { rl.route.setHash(data.Url); } diff --git a/dev/Stores/User/Settings.js b/dev/Stores/User/Settings.js index 32fbd846d..ef9f76442 100644 --- a/dev/Stores/User/Settings.js +++ b/dev/Stores/User/Settings.js @@ -3,7 +3,7 @@ import { koComputable } from 'External/ko'; import { Layout, EditorDefaultType } from 'Common/EnumsUser'; import { pInt, addObservablesTo } from 'Common/Utils'; -import { $htmlCL, SettingsGet } from 'Common/Globals'; +import { $htmlCL, SettingsGet, fireEvent } from 'Common/Globals'; import { ThemeStore } from 'Stores/Theme'; 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-side-preview-pane', Layout.SidePreview === 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); ThemeStore.isMobile.subscribe(toggleLayout); diff --git a/dev/View/User/MailBox/MessageList.js b/dev/View/User/MailBox/MessageList.js index 202d82013..269ba98e0 100644 --- a/dev/View/User/MailBox/MessageList.js +++ b/dev/View/User/MailBox/MessageList.js @@ -13,7 +13,7 @@ import { 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 { FileInfo } from 'Common/File'; @@ -683,7 +683,7 @@ export class MailMessageList extends AbstractViewRight { shortcuts.add('enter,open', '', Scope.MessageList, () => { if (MessageUserStore.message() && this.useAutoSelect()) { - dispatchEvent(new CustomEvent('mailbox.message-view.toggle-full-screen')); + fireEvent('mailbox.message-view.toggle-full-screen'); return false; } }); diff --git a/dev/View/User/MailBox/MessageView.js b/dev/View/User/MailBox/MessageView.js index 89af812c5..5450d6cce 100644 --- a/dev/View/User/MailBox/MessageView.js +++ b/dev/View/User/MailBox/MessageView.js @@ -23,7 +23,8 @@ import { Settings, SettingsCapa, getFullscreenElement, - exitFullscreen + exitFullscreen, + fireEvent } from 'Common/Globals'; import { arrayLength, inFocus } from 'Common/Utils'; @@ -245,15 +246,15 @@ export class MailMessageView extends AbstractViewRight { } goUpCommand() { - dispatchEvent(new CustomEvent('mailbox.message-list.selector.go-up', - {detail:SettingsUserStore.usePreviewPane() || !!currentMessage()} // bForceSelect - )); + fireEvent('mailbox.message-list.selector.go-up', + SettingsUserStore.usePreviewPane() || !!currentMessage() // bForceSelect + ); } goDownCommand() { - dispatchEvent(new CustomEvent('mailbox.message-list.selector.go-down', - {detail:SettingsUserStore.usePreviewPane() || !!currentMessage()} // bForceSelect - )); + fireEvent('mailbox.message-list.selector.go-down', + SettingsUserStore.usePreviewPane() || !!currentMessage() // bForceSelect + ); } toggleFullScreen() { diff --git a/dev/View/User/SystemDropDown.js b/dev/View/User/SystemDropDown.js index a3e07471e..d0e471735 100644 --- a/dev/View/User/SystemDropDown.js +++ b/dev/View/User/SystemDropDown.js @@ -13,7 +13,7 @@ import { KeyboardShortcutsHelpPopupView } from 'View/Popup/KeyboardShortcutsHelp import { AccountPopupView } from 'View/Popup/Account'; 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'; @@ -49,7 +49,7 @@ export class SystemDropDownUserView extends AbstractViewRight { } stopPlay() { - dispatchEvent(new CustomEvent('audio.api.stop')); + fireEvent('audio.api.stop'); } accountClick(account, event) {