-
Notifications
You must be signed in to change notification settings - Fork 0
/
flasher.js
65 lines (61 loc) · 1.75 KB
/
flasher.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
(function(win) {
var target = win.document
var body = win.document.body
var flasherEl = target.createElement('div')
flasherEl.setAttribute('id', 'flasher')
body.appendChild(flasherEl)
var flasher = {}
var funcs = {}
flasher.funcs = funcs
var settings = {}
flasher.settings = settings
var flashRate = 60
Object.defineProperty(settings,
'msFlashRate', {
get: function() {
return flashRate
},
set: function(newV) {
flashRate = newV
flasher.stop()
flasher.start()
}
})
funcs.nextCol = function(col) {
switch (col) {
case 'red':
return 'green'
case 'green':
return 'blue'
case 'blue':
return 'red'
}
}
funcs.setWH = function(el) {
el.style.width = "100%"
el.style.height = "100%"
el.style.margin = "0"
}
var curColor = "red"
funcs.start = function(func) {
var flashingIntv = win.setInterval(func, settings.msFlashRate)
return function() {
win.clearTimeout(flashingIntv)
};
}
funcs.changeColor = function() {
curColor = funcs.nextCol(curColor)
flasherEl.style.backgroundColor = curColor
}
// will get overriden when started.
flasher.stop = function() {}
flasher.start = function() {
flasher.stop = flasher.funcs.start(flasher.funcs.changeColor)
}
var ar = ([target.documentElement, body, flasherEl])
ar.map(funcs.setWH)
win.flasher = flasher
settings.msFlashRate = 17;
win.console.log('FLASHER help, type: "flasher"')
win.console.log(flasher)
})(window)