75155c567ee0aa4921df040b62a41728065390e9.svn-base
1.75 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
56
57
58
59
var playbox = (function(){
//author:eric_wu
var _playbox = function(){
var that = this;
that.box = null;
that.player = null;
that.src = null;
that.on = false;
//
that.autoPlayFix = {
on: true,
evtName: ("ontouchstart" in window)?"touchend":"click"
}
}
_playbox.prototype = {
init: function(box_ele){
this.box = "string" === typeof(box_ele)?document.getElementById(box_ele):box_ele;
this.player = this.box.querySelectorAll("audio")[0];
this.src = this.player.src;
this.init = function(){return this;}
this.autoPlayEvt(true);
return this;
},
play: function(){
if(this.autoPlayFix.on){
this.autoPlayFix.on = false;
this.autoPlayEvt(false);
}
this.on = !this.on;
if(true == this.on){
this.player.src = this.src;
this.player.play();
}else{
this.player.pause();
this.player.src = null;
}
if("function" == typeof(this.play_fn)){
this.play_fn.call(this);
}
},
handleEvent: function(evt){
this.play();
},
autoPlayEvt: function(important){
if(important || this.autoPlayFix.on){
document.body.addEventListener(this.autoPlayFix.evtName, this, false);
}else{
document.body.removeEventListener(this.autoPlayFix.evtName, this, false);
}
}
}
//
return new _playbox();
})();
playbox.play_fn = function(){
this.box.className = this.on?"btn_music":"btn_music on";
}