-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
110 lines (96 loc) · 2.49 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
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
/*!
* Pecha Kucha v1.0
* http://weedygarden.com/
*
* Copyright 2011, Erik Runyon
* Dual licensed under the MIT or GPL Version 2 licenses.
*/
(function() {
var $counter = $('#counter'),
countInit = 20,
totalSlides = 20,
slide = 1,
count = countInit,
t,
running = true
;
var Slides = {
init: function() {
console.log('init');
Slides.addNavigation();
Slides.doCountdown();
Slides.pause();
Slides.changeSlide();
},
nextSlide: function() {
if(slide === totalSlides) {
$counter.html('Finished');
clearTimeout(t);
running = false;
} else {
$('#slide'+slide).fadeOut();
++slide;
$('#slide'+slide).fadeIn();
$('#footer ul a').removeClass();
$('#p'+slide).addClass('active');
}
},
doCountdown: function() {
if(running) {
t = setTimeout(function(){
console.log('counting down');
$counter.html(count);
--count;
if(count === 0) {
count = countInit;
Slides.nextSlide();
}
Slides.doCountdown();
}, 1000);
}
},
pause: function() {
$('#pause').click(function(e){
e.preventDefault();
Slides.togglePlay();
var $this = $(this);
($this.html() == 'Pause') ? $this.html('Play') : $this.html('Pause');
});
},
togglePlay: function() {
if(running === true) {
clearTimeout(t);
running = false;
} else {
running = true;
Slides.doCountdown();
}
},
addNavigation: function() {
var links = '';
for(i = 1; i <= totalSlides; i++) {
var active = (i === 1) ? 'active' : '';
links += "<li><a href=\"#slide"+ i +"\" id=\"p"+ i +"\" class=\""+ active +"\">"+ i +"</a></li>";
}
$('#slidenav').html(links);
},
changeSlide: function() {
$('#slidenav a').live('click', function(e){
e.preventDefault();
var $this = $(this);
// stop the timer
clearTimeout(t);
running = false;
$('#pause').html('Play');
// Hide all but the selected slide
$('.slide:visible').fadeOut();
$('#footer ul a').removeClass();
slide = $this.html();
console.log('activating slide ' + slide);
$($this.attr('href')).fadeIn();
$this.addClass('active');
});
}
};
Slides.init();
})();