-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
115 lines (104 loc) · 3.02 KB
/
app.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
var header = new Muuri('.header .grid', {
dragEnabled: true,
layoutOnResize: true,
dragHandle: '.apple-tv-card',
dragStartPredicate: {
distance: 1,
},
dragRelease: {
useDragContainer: false,
},
dragSort: getAllGrids,
});
var grid = new Muuri('.body .grid', {
dragEnabled: true,
layoutOnResize: true,
dragHandle: '.apple-tv-card',
dragStartPredicate: {
distance: 1,
},
dragRelease: {
useDragContainer: false,
},
dragSort: getAllGrids,
});
header.on('receive', function (data) {
header.refreshItems([data.item], true);
const count = header.getItems().length;
if (count >= 6) {
header.send(count - 1, grid, 0, {
appendTo: document.querySelector('.header .grid'),
layoutSender: () => synchronize(),
layoutReceiver: () => synchronize(),
});
}
});
grid.on('receive', function (data) {
grid.refreshItems([data.item], true);
grid.layout();
synchronize();
const count = header.getItems().length;
if (count < 5) {
const itemIndex = data.toIndex ? 0 : 1;
grid.send(itemIndex, header, count, {
appendTo: document.querySelector('.header .grid'),
layoutSender: () => synchronize(),
layoutReceiver: () => synchronize(),
});
}
});
header.on('dragReleaseStart', function() {
grid.refreshItems();
grid.layout();
synchronize();
});
grid.on('dragReleaseStart', function() {
grid.refreshItems();
grid.layout();
synchronize();
});
function getAllGrids(item) {
return [header, grid];
}
function synchronize() {
setTimeout(() => {
header.synchronize();
grid.synchronize();
});
}
document.querySelectorAll('.apple-tv-card .content').forEach((hyperlink) => {
hyperlink.addEventListener('click', function (event) {
const element = event.target.closest('.muuri-item');
if (element.classList.contains('muuri-item-releasing')) {
event.preventDefault();
event.stopImmediatePropagation();
event.stopPropagation();
}
});
});
document.body.onload = () => {
let activeIconIndex = 0;
const icons = document.querySelectorAll('.content');
// add event listener to listen for arrow key presses
document.addEventListener('keydown', (event) => {
const key = event.key;
switch (key) {
case 'ArrowUp':
activeIconIndex = Math.max(activeIconIndex - 5, 0);
break;
case 'ArrowDown':
activeIconIndex = Math.min(activeIconIndex + 5, icons.length - 1);
break;
case 'ArrowLeft':
activeIconIndex = Math.max(activeIconIndex - 1, 0);
break;
case 'ArrowRight':
activeIconIndex = Math.min(activeIconIndex + 1, icons.length - 1);
break;
}
// unfocus all icons
icons.forEach(icon => icon.blur());
// focus the selected icon
icons[activeIconIndex].focus();
});
}