-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
141 lines (122 loc) · 4.82 KB
/
script.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
(function(){
var hasFrame = window.parent != window,
scripts = document.getElementsByTagName('script'),
current = scripts[scripts.length-1],
config = current.getAttribute('data-config'),
head = document.getElementsByTagName("head")[0],
dest = location.href,
destHost = dest.substr(0, dest.indexOf('/', 10)),
isOutside = !hasFrame,
addEvent = function(elm, evType, fn){
if(elm.addEventListener)
elm.addEventListener(evType, fn);
else if(elm.attachEvent)
elm.attachEvent('on' + evType, fn);
else
elm['on' + evType] = fn;
},
isIE = (function(){
var undef, v = 3, div = document.createElement('div'), all = div.getElementsByTagName('i');
while(div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->', all[0]);
return v > 4 ? v : undef;
})(),
isMobile = navigator.userAgent.match(/iPad|iPhone|Android|Blackberry/i),
isIPad = navigator.userAgent.match(/iPad/i);
var inside = function(){
var filter = function(host){
host = host.replace(/blogspot.[a-z.]*/i, 'blogspot.com');
host = host.replace(/^(http(s)?:\/\/)?(www.)?/i, '');
return host;
};
addEvent(document.body, 'click', function(e){
var tar = e.target;
while(!tar.tagName.match(/^(a|area)$/i) && tar != document.body)
tar = tar.parentNode;
if(tar.tagName.match(/^(a|area)$/i) && !tar.href.match(/.(jpg|png)$/i) && !tar.href.match(/^javascript:/)){
if(filter(tar.href).indexOf(filter(location.host)) == -1){
if(tar.href.match(/^http(s)?/)){
window.open(tar.href, '_blank');
window.focus();
e.preventDefault();
}
}
}
});
};
if(!isMobile){
inside();
}
})();
function calculateTotalValue(length) {
var minutes = Math.floor(length / 60),
seconds_int = length - minutes * 60,
seconds_str = seconds_int.toString(),
seconds = seconds_str.substr(0, 2),
time = minutes + ':' + seconds
return time;
}
function calculateCurrentValue(currentTime) {
var current_hour = parseInt(currentTime / 3600) % 24,
current_minute = parseInt(currentTime / 60) % 60,
current_seconds_long = currentTime % 60,
current_seconds = current_seconds_long.toFixed(),
current_time = (current_minute < 10 ? "0" + current_minute : current_minute) + ":" + (current_seconds < 10 ? "0" + current_seconds : current_seconds);
return current_time;
}
function initProgressBar() {
var player = document.getElementById('player');
var length = player.duration
var current_time = player.currentTime;
// calculate total length of value
var totalLength = calculateTotalValue(length)
jQuery(".end-time").html(totalLength);
// calculate current value time
var currentTime = calculateCurrentValue(current_time);
jQuery(".start-time").html(currentTime);
var progressbar = document.getElementById('seekObj');
progressbar.value = (player.currentTime / player.duration);
progressbar.addEventListener("click", seek);
if (player.currentTime == player.duration) {
$('#play-btn').removeClass('pause');
}
function seek(evt) {
var percent = evt.offsetX / this.offsetWidth;
player.currentTime = percent * player.duration;
progressbar.value = percent / 100;
}
};
function initPlayers(num) {
// pass num in if there are multiple audio players e.g 'player' + i
for (var i = 0; i < num; i++) {
(function() {
// Variables
// ----------------------------------------------------------
// audio embed object
var playerContainer = document.getElementById('player-container'),
player = document.getElementById('player'),
isPlaying = false,
playBtn = document.getElementById('play-btn');
// Controls Listeners
// ----------------------------------------------------------
if (playBtn != null) {
playBtn.addEventListener('click', function() {
togglePlay()
});
}
// Controls & Sounds Methods
// ----------------------------------------------------------
function togglePlay() {
if (player.paused === false) {
player.pause();
isPlaying = false;
$('#play-btn').removeClass('pause');
} else {
player.play();
$('#play-btn').addClass('pause');
isPlaying = true;
}
}
}());
}
}
initPlayers(jQuery('#player-container').length);