-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDanmaku.js
133 lines (106 loc) · 3.58 KB
/
Danmaku.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
function Danmaku(stageObject, toolObject, getPlayhead) {
this.stage = stageObject.find('#commentCanvas');
this.toolbar = toolObject;
this.cm = new CommentManager(this.stage[0]);
this.tmr = 0;
this.start = 0;
this.getPlayhead = getPlayhead;
this.playhead = 0;
this.colorpicker = new ColorPicker(this, this.toolbar.find(".color_select"));
this.run = function () {
this.playhead = this.getPlayhead();
this.cm.time(this.playhead);
};
this.init();
}
Danmaku.prototype.init = function () {
this.cm.init();
//filter
//this.cm.filter.setRuntimeFilter(fefx.center_dim);
//cm.filter.setRuntimeFilter(fefx.center_speedup);
this.colorpicker.init();
};
Danmaku.prototype.isshow = function () {
return (this.stage.css('display') != 'none');
};
Danmaku.prototype.show = function () {
this.stage.css('display', 'block');
this.toolbar.find('#danmaku-hide').val('隐藏弹幕');
}
Danmaku.prototype.hide = function () {
this.stage.css('display', 'none');
this.toolbar.find('#danmaku-hide').val('显示弹幕');
};
Danmaku.prototype.dohide = function () {
this.isshow() ? this.hide() : this.show();
};
Danmaku.prototype.postdata = function (cmsenddata) {
$.ajax({
type: 'POST',
url: '/comment.php?mod=danmaku&do=add&ssid=' + this.ssid,
dataType: 'json',
data: cmsenddata,
success: function (msg) {
if (msg == '0') {
danmaku.posttips(true);
} else {
danmaku.posttips(false);
}
},
error: function () {
danmaku.posttips(false);
}
});
};
Danmaku.prototype.posttips = function (succeed) {
if (succeed) {
this.toolbar.find("#danmaku-tips").css('color', '#7BCA1C').fadeIn().text('发送弹幕成功').delay(2000).fadeOut();
} else {
this.toolbar.find("#danmaku-tips").css('color', 'red').fadeIn().text('发送弹幕失败').delay(2000).fadeOut();
}
};
Danmaku.prototype.post = function () {
var text = this.toolbar.find("#id_danmaku").val();
if (text != '') {
this.toolbar.find("#id_danmaku").val('');
var stime = this.playhead;
var size = Number(this.toolbar.find("#danmaku-fontsize").val());
var color = this.toolbar.find(".color_select").css("background-color");
var mode = Number(this.toolbar.find("#danmaku-mode").val());
//'alphaFrom':1,'shadow':false,'font':'微软雅黑'
var cmdata = { 'text': text, 'mode': mode, 'stime': stime, 'size': size, 'color': color, 'border': true };
this.cm.sendComment(cmdata);
color = this.colorpicker.color2int(color);
var cmsenddata = { 'text': text, 'mode': mode, 'stime': stime, 'size': size, 'color': color };
this.postdata(cmsenddata);
}
};
Danmaku.prototype.loader = function (ssid, callback) {
CommentLoader('/comment.php?mod=danmaku&do=get&ssid=' + ssid, this.cm, false, callback);
};
Danmaku.prototype.load = function (ssid, callback) {
this.ssid = ssid;
this.cm.clear();
this.start = 0;
this.loader(ssid, callback);
};
Danmaku.prototype.play = function () {
try {
clearInterval(this.tmr);
} catch (e) { }
this.cm.startTimer();
this.start = new Date().getTime();
this.tmr = setInterval(function () {
danmaku.run();
}, 100);
};
Danmaku.prototype.stop = function () {
this.cm.stopTimer();
clearInterval(this.tmr);
};
Danmaku.prototype.resume = function () {
this.cm.startTimer();
this.tmr = setInterval(function () {
danmaku.run();
}, 100);
};