-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathapp.js
45 lines (45 loc) · 1.19 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
"use strict";
(function(){
var shuffle = function(array) {
var m = array.length, t, i;
while (m) {
i = Math.floor(Math.random() * m--);
t = array[m];
array[m] = array[i];
array[i] = t;
}
return array;
}
angular
.module("slips", [])
.controller("slipsController", function(){
this.categories = Object.keys(slips)
this.currentSlip = "Slips."
this.update = function(){
this.slips = []
for( var category in this.selected ){
if(this.selected[category]){
this.slips.push(...slips[category])
}
}
this.slips = shuffle(this.slips)
this.currentSlip = this.slips[0]
this.currentSlipIndex = 0
}
this.next = function(e){
if(!this.slips.length) return
if(e.keyCode === 37){
this.currentSlipIndex--
if(this.currentSlipIndex == -1) this.currentSlipIndex = this.slips.length - 1;
this.currentSlip = this.slips[this.currentSlipIndex]
} else {
this.currentSlipIndex++
if(this.currentSlipIndex == this.slips.length) this.currentSlipIndex = 0;
this.currentSlip = this.slips[this.currentSlipIndex]
}
}
this.toggleLight = function(){
document.body.classList.toggle("dark")
}
})
})()