-
Notifications
You must be signed in to change notification settings - Fork 4
/
img-switcher.js
53 lines (47 loc) · 1.31 KB
/
img-switcher.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
(() => {
'use strict';
const ADIDAS_URL = 'https://www.adidas.com';
const NIKE_URL = 'https://www.nike.com';
const LEFT = 'left';
const CENTER = 'center';
const RIGHT = 'right';
let adidas = document.querySelector('#adidas');
let nike = document.querySelector('#nike');
document.addEventListener('keydown', event => {
if (event.keyCode === 39 /* right */) {
if (nike.className === 'center') {
return;
}
adidas.className = 'left';
nike.className = 'center';
updateCurrentAdvertisement(NIKE_URL);
return;
}
if (event.keyCode === 37 /* left */) {
if (adidas.className === 'center') {
return;
}
nike.className = 'right';
adidas.className = 'center';
updateCurrentAdvertisement(ADIDAS_URL);
return;
}
});
let current_adv;
let updateCurrentAdvertisement = (newURL) => {
let new_adv = {
type: 'url',
url: newURL,
advertisedTxPower: -100
};
if (eddystone.advertisements.length === 0) {
eddystone.registerAdvertisement(new_adv)
.then(adv => current_adv = adv);
return;
}
current_adv.unregisterAdvertisement()
.then(() => eddystone.registerAdvertisement(new_adv))
.then(adv => current_adv = adv);
};
updateCurrentAdvertisement(ADIDAS_URL);
})();