mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-03 22:47:03 +03:00
Added: addEventsListener() and addEventsListeners()
This commit is contained in:
parent
c270f0ad9a
commit
5990addfef
14 changed files with 484 additions and 464 deletions
|
|
@ -1,5 +1,5 @@
|
|||
import * as Links from 'Common/Links';
|
||||
import { doc, SettingsGet, fireEvent } from 'Common/Globals';
|
||||
import { doc, SettingsGet, fireEvent, addEventsListener } from 'Common/Globals';
|
||||
|
||||
let notificator = null,
|
||||
player = null,
|
||||
|
|
@ -73,8 +73,7 @@ export const SMAudio = new class {
|
|||
this.supportedOgg = canPlay('audio/ogg; codecs="vorbis"');
|
||||
if (player) {
|
||||
const stopFn = () => this.pause();
|
||||
player.addEventListener('ended', stopFn);
|
||||
player.addEventListener('error', stopFn);
|
||||
addEventsListener(player, ['ended','error'], stopFn);
|
||||
addEventListener('audio.api.stop', stopFn);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,16 +29,10 @@ export const Capa = {
|
|||
export const Scope = {
|
||||
All: 'all',
|
||||
None: 'none',
|
||||
Contacts: 'Contacts',
|
||||
MessageList: 'MessageList',
|
||||
FolderList: 'FolderList',
|
||||
MessageView: 'MessageView',
|
||||
Compose: 'Compose',
|
||||
Settings: 'Settings',
|
||||
Menu: 'Menu',
|
||||
OpenPgpKey: 'OpenPgpKey',
|
||||
KeyboardShortcutsHelp: 'KeyboardShortcutsHelp',
|
||||
Ask: 'Ask'
|
||||
Settings: 'Settings'
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import { Scope } from 'Common/Enums';
|
|||
let keyScopeFake = Scope.All;
|
||||
|
||||
export const
|
||||
ScopeMenu = 'Menu',
|
||||
|
||||
doc = document,
|
||||
|
||||
|
|
@ -31,14 +32,20 @@ export const
|
|||
|
||||
fireEvent = (name, detail) => dispatchEvent(new CustomEvent(name, {detail:detail})),
|
||||
|
||||
addEventsListener = (element, events, fn, options) =>
|
||||
events.forEach(event => element.addEventListener(event, fn, options)),
|
||||
|
||||
addEventsListeners = (element, events) =>
|
||||
Object.entries(events).forEach(([event, fn]) => element.addEventListener(event, fn)),
|
||||
|
||||
// keys
|
||||
keyScopeReal = ko.observable(Scope.All),
|
||||
keyScope = value => {
|
||||
if (value) {
|
||||
if (Scope.Menu !== value) {
|
||||
if (ScopeMenu !== value) {
|
||||
keyScopeFake = value;
|
||||
if (dropdownVisibility()) {
|
||||
value = Scope.Menu;
|
||||
value = ScopeMenu;
|
||||
}
|
||||
}
|
||||
keyScopeReal(value);
|
||||
|
|
@ -50,8 +57,8 @@ export const
|
|||
|
||||
dropdownVisibility.subscribe(value => {
|
||||
if (value) {
|
||||
keyScope(Scope.Menu);
|
||||
} else if (Scope.Menu === shortcuts.getScope()) {
|
||||
keyScope(ScopeMenu);
|
||||
} else if (ScopeMenu === shortcuts.getScope()) {
|
||||
keyScope(keyScopeFake);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import ko from 'ko';
|
||||
import { addEventsListeners } from 'Common/Globals';
|
||||
import { isArray } from 'Common/Utils';
|
||||
import { koComputable } from 'External/ko';
|
||||
|
||||
|
|
@ -239,27 +240,28 @@ export class Selector {
|
|||
return el ? ko.dataFor(el) : null;
|
||||
};
|
||||
|
||||
contentScrollable.addEventListener('click', event => {
|
||||
let el = event.target.closestWithin(this.sItemSelector, contentScrollable);
|
||||
el && this.actionClick(ko.dataFor(el), event);
|
||||
addEventsListeners(contentScrollable, {
|
||||
click: event => {
|
||||
let el = event.target.closestWithin(this.sItemSelector, contentScrollable);
|
||||
el && this.actionClick(ko.dataFor(el), event);
|
||||
|
||||
const item = getItem(this.sItemCheckedSelector);
|
||||
if (item) {
|
||||
if (event.shiftKey) {
|
||||
this.actionClick(item, event);
|
||||
} else {
|
||||
this.focusedItem(item);
|
||||
item.checked(!item.checked());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
contentScrollable.addEventListener('auxclick', event => {
|
||||
if (1 == event.button) {
|
||||
const item = getItem(this.sItemSelector);
|
||||
const item = getItem(this.sItemCheckedSelector);
|
||||
if (item) {
|
||||
this.focusedItem(item);
|
||||
(this.oCallbacks.MiddleClick || (()=>0))(item);
|
||||
if (event.shiftKey) {
|
||||
this.actionClick(item, event);
|
||||
} else {
|
||||
this.focusedItem(item);
|
||||
item.checked(!item.checked());
|
||||
}
|
||||
}
|
||||
},
|
||||
auxclick: event => {
|
||||
if (1 == event.button) {
|
||||
const item = getItem(this.sItemSelector);
|
||||
if (item) {
|
||||
this.focusedItem(item);
|
||||
(this.oCallbacks.MiddleClick || (()=>0))(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue