util.js
1.35 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
// 通用方法
function getQuery(name) {
var result = window.location.search.match(new RegExp("[\?\&]" + name + "=([^\&]+)", "i"));
if (result == null || result.length < 1)
return undefined;
return decodeURIComponent(result[1]);
}
getCDNFile = function (cdnUrl) {
var link = cdnUrl.substring(cdnUrl.indexOf('/uploads/'), cdnUrl.indexOf('?'));
return link;
}
var timer = {
options: {
timer: null,
dom: null
},
init: function(dom){
this.options.dom = dom;
this.startTimer();
},
getTimer: function(){
var _dom = this.options.dom;
var t = 1,
h = 0,
m = 0,
s = 1,
ss = 1;
return function(){
if (s > 0 && s % 60 == 0) {
m += 1;
s = 0;
}
if (m > 0 && m % 60 == 0) {
h += 1;
m = 0;
}
t = (h < 10 ? '0' + h : h) + ":" + (m < 10 ? '0' + m : m) + ":" + (s < 10 ? '0' + s : s);
_dom.html(t).val(ss);
s += 1;
ss += 1;
}
},
startTimer: function(){
var _getTimer = this.getTimer();
this.options.timer = setInterval(_getTimer, 1000);
},
stopTimer: function(){
clearInterval(this.options.timer);
this.options.timer = null;
}
}