-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.words.js
More file actions
134 lines (101 loc) · 3.86 KB
/
common.words.js
File metadata and controls
134 lines (101 loc) · 3.86 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
var RCW = {};
Array.prototype.shuffle = Array.prototype.shuffle || function() {
// Durstenfeld variation of Fisher–Yates shuffle
for (var i = this.length - 1, j = 0, t = 0; i >= 0; i--) {
j = Math.floor(Math.random() * i);
t = this[i];
this[i] = this[j];
this[j] = t;
}
return this;
};
(function(RCW) {
"use strict";
var _FORWARD = 1;
var _BACKWARD = -1;
var _MIN_PAUSE = 500;
var _idx = 0;
var _inmotion = false;
var _elm;
var _ts;
var _toggle;
var _random = false;
var _countElm;
var words = [
"the", "a", "do", "to", "of", "said", "says", "are", "were", "was", "is", "his", "as", "has", "I", "you", "they",
"be", "he", "me", "we", "she", "no", "go", "so", "by", "my", "here", "there", "where", "love", "come", "some",
"one", "once", "ask", "friend", "school", "put", "push", "pull", "full", "house", "our", "door", "floor", "poor",
"because", "your", "today", "even", "behind", "child", "chlidren", "wild", "climb", "most", "only", "both", "old",
"cold", "gold", "hold", "told", "every", "everybody", "everyone", "great", "break", "steak", "beautiful", "after",
"fast", "last", "past", "father", "mother", "class", "grass", "pass", "plant", "path", "bath", "hour", "prove",
"improve", "sure", "sugar", "eye", "could", "would", "should", "work", "whole", "any"
];
var _shuffled = words.slice();
var fullscreen = function(element) {
if(element.requestFullscreen) {
element.requestFullscreen();
} else if(element.mozRequestFullScreen) {
element.mozRequestFullScreen();
} else if(element.webkitRequestFullscreen) {
element.webkitRequestFullscreen();
} else if(element.msRequestFullscreen) {
element.msRequestFullscreen();
}
};
var updateCount = function(count) {
_countElm.innerText = count;
};
var transition = function(direction) {
if (_inmotion === true || Date.now() - _ts < _MIN_PAUSE) {
return;
}
if (direction === undefined) {
direction = _FORWARD;
}
_inmotion = true;
var len = _random ? _shuffled.length : words.length;
_idx = (_idx + direction) % len;
if (_idx < 0) _idx += len;
_elm.innerHTML = _random ? _shuffled[_idx] : words[_idx];
_ts = Date.now();
updateCount(_idx + 1);
_inmotion = false;
};
var start = function() {
//fullscreen(document.documentElement);
_elm = document.getElementById("word");
_countElm = document.getElementById("count");
_elm.innerHTML = words[_idx];
_ts = Date.now();
var wordtime = new Hammer(_elm);
//wordtime.get('swipe').set({ direction: Hammer.DIRECTION_LEFT });
wordtime.get('swipe').set({ direction: Hammer.DIRECTION_HORIZONTAL });
wordtime.on('swipe', function(ev) {
if (ev.direction === Hammer.DIRECTION_RIGHT) {
transition(_BACKWARD);
} else {
transition(_FORWARD);
}
});
wordtime.on('tap', function(ev) {
transition(_FORWARD);
});
_toggle = document.getElementById("toggle");
var modetime = new Hammer(_toggle);
modetime.on('tap', function() {
_random = !_random;
if (_random) {
_toggle.src = "res/images/shuffle.png";
_shuffled = words.slice().shuffle();
_elm.innerHTML = _shuffled[_idx];
} else {
_toggle.src = "res/images/repeat.png";
_elm.innerHTML = words[_idx];
}
_idx = 0;
updateCount(_idx + 1);
});
};
RCW.words = words;
RCW.start = start;
})(RCW);