This repository has been archived by the owner on Nov 3, 2021. It is now read-only.
/
contextmenu.js
79 lines (61 loc) · 1.91 KB
/
contextmenu.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
'use strict';
var ContextMenuDialog = (function() {
var initialized = false;
var dialog, wallpaperButton, collectionsButton, cancelButton;
function initialize() {
if (initialized) {
return;
}
dialog = document.getElementById('contextmenu-dialog');
wallpaperButton =
document.getElementById('contextmenu-dialog-wallpaper-button');
collectionsButton =
document.getElementById('contextmenu-dialog-collections-button');
cancelButton =
document.getElementById('contextmenu-dialog-cancel-button');
initialized = true;
}
function chooseWallpaper() {
LazyLoader.load(['shared/js/omadrm/fl.js', 'js/wallpaper.js'],
function wallpaperLoaded() {
hide(Wallpaper.contextmenu);
}
);
}
function addCollection() {
hide(function() {
window.dispatchEvent(new CustomEvent('suggestcollections'));
});
}
function show() {
initialize();
wallpaperButton.addEventListener('click', chooseWallpaper);
collectionsButton.addEventListener('click', addCollection);
cancelButton.addEventListener('click', hide);
dialog.style.display = 'block';
setTimeout(function animate() {
dialog.classList.add('visible');
window.dispatchEvent(new CustomEvent('contextmenushowed'));
}, 10);
}
function hide(cb) {
initialize();
wallpaperButton.removeEventListener('click', chooseWallpaper);
collectionsButton.removeEventListener('click', addCollection);
cancelButton.removeEventListener('click', hide);
dialog.addEventListener('transitionend', function hidden() {
dialog.removeEventListener('transitionend', hidden);
dialog.style.display = 'none';
if (typeof cb === 'function') {
cb();
}
});
dialog.classList.remove('visible');
window.dispatchEvent(new CustomEvent('contextmenuhidden'));
}
return {
hide: hide,
show: show,
init: initialize
};
}());