/
application.js
93 lines (74 loc) · 2.22 KB
/
application.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
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
var Aumodoro = {
timer: {
seconds_elapsed: 0,
count_up: false,
pom_length_in_minutes: 25,
display_element: '.timer',
interval: undefined,
to_string: "",
minutes: 0,
seconds: 0,
start: function() {
var self = this;
clearInterval(this.interval);
this.interval = setInterval(function(){
self.seconds_elapsed = self.seconds_elapsed + 1;
if (self.seconds_elapsed >= (60*self.pom_length_in_minutes)) {
self.complete();
} else {
self.update_interface();
}
}, 1000);
// ! auto update pom record start
},
complete: function() {
clearInterval(this.interval);
this.seconds_elapsed = 0;
// ! auto update pom record end
},
update_interface: function(){
if (this.count_up) {
this.minutes = parseInt(this.seconds_elapsed / 60, 10);
this.seconds = this.seconds_elapsed % 60.0;
} else {
this.minutes = (this.pom_length_in_minutes-1) - parseInt(this.seconds_elapsed / 60, 10);
this.seconds = 60 - this.seconds_elapsed % 60.0;
}
if (this.minutes < 10) {
this.minutes = "0"+this.minutes;
}
if (this.seconds < 10) {
this.seconds = "0"+this.seconds;
}
this.to_string = this.minutes+":"+this.seconds;
$(this.display_element).html(this.to_string);
this.update_title();
},
update_title: function() {
document.title = this.to_string;
},
init: function(options) {
this.pom_length_in_minutes = options.pom_length_in_minutes || this.pom_length_in_minutes;
this.count_up = options.count_up;
this.seconds_elapsed = options.seconds_elapsed || this.seconds_elapsed;
this.display_element = options.display_element || this.display_element;
}
}
};
$(document).ready(function(){
// Notifications
$('.notice, .alert').hide().fadeIn(3000);
// Datepicker
$('.datetimepicker').datetimepicker();
// Color picker
$('.color_picker').simpleColor({
cellWidth: 9,
cellHeight: 9,
border: '1px solid #333333',
buttonClass: 'button'
});
// Timer
if($('.timer').length > 0) {
Aumodoro.timer.start();
}
});