-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprank.js
62 lines (49 loc) · 1.44 KB
/
prank.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
var sound = new Howl({
urls: ['crack.mp3'],
onload: function(){
// makes sure the sound is loaded. then shows the html content
$('.container').removeClass('hidden');
}
});
$(document).ready(function(){
// Current index
var currentLabelIndex = 0;
var labels = [$('#label1'),$('#label2'),$('#label3')];
var tresholds = [1,1,0.8];
// Init Force Touch class
var forceTouch = new ForceTouch();
var button = document.getElementById('button')
forceTouch.startListen(button);
var updateLabel= function(forceValue){
// Show current force touch on the label
render(forceValue , labels[currentLabelIndex]);
if(forceValue >= tresholds[currentLabelIndex]){
if(currentLabelIndex + 1 == labels.length){
crack();
} else {
labels[currentLabelIndex].addClass('done');
labels[currentLabelIndex].removeClass('current');
forceTouch.callback = switchLable;
}
return;
}
}
var switchLable = function(forceValue){
if(forceValue == 0){
currentLabelIndex++;
forceTouch.callback = updateLabel;
labels[currentLabelIndex].addClass('current');
}
}
var render = function(value , label){
value = (value > 1)?1:value;
label.html(value.toFixed(2));
}
// Start listening for label
forceTouch.callback = updateLabel;
function crack(){
forceTouch.callback = function(){return;};
sound.play();
$('#crack').css('display','block');
}
});