Skip to content

Commit

Permalink
弹幕bug
Browse files Browse the repository at this point in the history
  • Loading branch information
刘俊涛 committed Mar 1, 2017
1 parent 84a3e35 commit 2167c68
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 43 deletions.
1 change: 1 addition & 0 deletions plugins/danmu/DanmuWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function init()
public function run()
{
DanmuAsset::register($this->view);
$this->entity = str_replace('\\', '\\\\', $this->entity);
$script = "initDm('{$this->entity}', {$this->entityId}, '{$this->listUrl}');";
$this->view->registerJs($script);
}
Expand Down
30 changes: 15 additions & 15 deletions plugins/danmu/assets/js/danmuManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ var DanmuManager = function(opt) {
this.last_dm_ids = {};
};

DanmuManager.protoentity.push = function(dm) {
DanmuManager.prototype.push = function(dm) {
if(!dm){
return this.log('push, NULL data pushed');
}
dm.avatar = dm.avatar || '../image/default/avatar.png';
dm.entity = 'realtime';
dm.type = 'realtime';
this.q.unshift(dm);
this.log('EVENT push_fired EMITTED:' + DM_ToString.call(dm));
};

/**
* 取出一条需要显示的数据
*/
DanmuManager.protoentity.read = function(cb) {
DanmuManager.prototype.read = function(cb) {
//始终返回队列顶部数据
var dm = this.q.shift();
//检查队列长度以判断是否需要拉取新的弹幕列表
Expand All @@ -58,7 +58,7 @@ DanmuManager.protoentity.read = function(cb) {
}
}

DanmuManager.protoentity.optimizeImg = function(url){
DanmuManager.prototype.optimizeImg = function(url){
if(url && url.search('qzapp.qlogo.cn/') > 0){ // QQ avatar
url = url.replace(/\/100$/,'\/30');
}
Expand All @@ -71,7 +71,7 @@ DanmuManager.protoentity.optimizeImg = function(url){
/**
* 取出一条需要显示的数据
*/
DanmuManager.protoentity.readSync = function() {
DanmuManager.prototype.readSync = function() {
//始终返回队列顶部数据
var dm = this.q.shift();
//检查队列长度以判断是否需要拉取新的弹幕列表
Expand All @@ -92,7 +92,7 @@ DanmuManager.protoentity.readSync = function() {
}

var kw = [/兼职/,/淘宝/,/扣扣/,/结算/,/结算/,/加Q/,/天猫/,/傔职/,/掏宝/,/在线客服/,/诚聘/,/贝兼/,/间职/,/空余时间/,/日結/,/加q/,/蒹职/,/上班族/];
DanmuManager.protoentity.filterContent = function(str){
DanmuManager.prototype.filterContent = function(str){
for(var len = kw.length, i=0; i< len; i++){
if(str.match(kw[i])){
return "笑Cry!";
Expand All @@ -102,15 +102,15 @@ DanmuManager.protoentity.filterContent = function(str){
return str;
};

DanmuManager.protoentity.get_current_pos = function(){
DanmuManager.prototype.get_current_pos = function(){
var _tmp = parseInt($(document).scrollTop() / $(document).height() * 100, 10);
if(_tmp < 0){
_tmp = 0;
}
return _tmp;
};

DanmuManager.protoentity.get_pos_section = function(_tmp_pos){
DanmuManager.prototype.get_pos_section = function(_tmp_pos){
_tmp_pos = _tmp_pos || this.get_current_pos();
var _pos = 0;
for(var i=0, len=this.pos_sections.length; i < len; i++){
Expand All @@ -124,7 +124,7 @@ DanmuManager.protoentity.get_pos_section = function(_tmp_pos){
return _pos < 1 ? 1 : _pos;
};

DanmuManager.protoentity.prepare_pos_section = function(pos_arr){
DanmuManager.prototype.prepare_pos_section = function(pos_arr){
// 不重复设置值
if(this.pos_sections && this.pos_sections.length > 0){
return;
Expand All @@ -139,7 +139,7 @@ DanmuManager.protoentity.prepare_pos_section = function(pos_arr){
/**
* 向服务器端获取列表数据
*/
DanmuManager.protoentity.get_list = function() {
DanmuManager.prototype.get_list = function() {
// 如果ajax正在执行,直接跳过
if(this.is_fetching){
return this.log('get_list, is_fetching=true');
Expand Down Expand Up @@ -183,9 +183,9 @@ DanmuManager.protoentity.get_list = function() {
jlog(post_data);
$.ajax({
url : that.danmu_list_url,
dataentity : 'json',
dataType : 'json',
data: post_data,
entity: 'post',
type: 'post',
success:function(data) {
that.is_fetching = false;
if(!data){
Expand Down Expand Up @@ -215,7 +215,7 @@ DanmuManager.protoentity.get_list = function() {
that.pos_last_time = that.pos_current;
};

DanmuManager.protoentity.transform = function(data, curr_section){
DanmuManager.prototype.transform = function(data, curr_section){
var arr = data.list || [];
if(arr){
var dm = arr[arr.length - 1];
Expand All @@ -226,7 +226,7 @@ DanmuManager.protoentity.transform = function(data, curr_section){
return arr;
};

DanmuManager.protoentity.append_data = function(data) {
DanmuManager.prototype.append_data = function(data) {
this.log('append_data, data.length=' + (!data ? 'null' : data.length));
this.is_fetching = false;
if(data && data.length > 0){
Expand All @@ -238,6 +238,6 @@ DanmuManager.protoentity.append_data = function(data) {
}
};

DanmuManager.protoentity.log = function(text) {
DanmuManager.prototype.log = function(text) {
jlog('[DanmuManager] ' + text);
};
18 changes: 9 additions & 9 deletions plugins/danmu/assets/js/dm.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function start_sio(entity, entity_id, dm_mgr, cb){
socket.on('error', function(err){
jlog('[EE] socket.io error: ' + err);
});
if(entityof(cb) !== 'undefined'){
if(typeof(cb) !== 'undefined'){
cb(socket);
}
}
Expand All @@ -50,7 +50,7 @@ function start(entity, entity_id, list_url){

// Get article_id
/* var article_id = getParameterByName('id');
if(entityof(art_id) != 'undefined'){
if(typeof(art_id) != 'undefined'){
article_id = art_id
}
Expand All @@ -66,11 +66,11 @@ function start(entity, entity_id, list_url){
danmu_list_url : list_url
};

if(entityof(danmuListUrl) !== 'undefined'){
if(typeof(danmuListUrl) !== 'undefined'){
opt.danmu_list_url = danmuListUrl
}

jQuery.extend(DanmuManager.protoentity, jQuery.eventEmitter);
jQuery.extend(DanmuManager.prototype, jQuery.eventEmitter);
window.dm_mgr = new DanmuManager(opt);

dm_mgr.on('no_more_data', function(){
Expand All @@ -79,7 +79,7 @@ function start(entity, entity_id, list_url){
});

dm_mgr.on('dm_on', function(){
if(entityof __socket == 'undefined'){
if(typeof __socket == 'undefined'){
// start_sio(article_id, dm_mgr);
return;
}
Expand All @@ -89,7 +89,7 @@ function start(entity, entity_id, list_url){
});

dm_mgr.on('dm_off', function(){
if(entityof __socket != 'undefined' && __socket.connected){
if(typeof __socket != 'undefined' && __socket.connected){
__socket.disconnect();
}
});
Expand Down Expand Up @@ -132,11 +132,11 @@ var DM = function(){
this.nickname = '';
this.content = '';
this.avatar = '';
this.entity = 'polling';
this.type = 'polling';
};

var DM_ToString = DM.protoentity.toString = function(){
return 'nickname=' + this.nickname + ', content=' + this.content + ', avatar=' + this.avatar + ', entity=' + this.entity;
var DM_ToString = DM.prototype.toString = function(){
return 'nickname=' + this.nickname + ', content=' + this.content + ', avatar=' + this.avatar + ', type=' + this.type;
};


Expand Down
6 changes: 3 additions & 3 deletions plugins/danmu/assets/js/dm_util.min.js

Large diffs are not rendered by default.

32 changes: 16 additions & 16 deletions plugins/danmu/assets/js/hjz.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ var DMRE = function(mgr, is_full_control){
this.PIVOT_FOR_START_GETTING_NEW_DMS = 4;
}

DMRE.protoentity._getUrlParam = function(name){
DMRE.prototype._getUrlParam = function(name){
var _reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)');
var _target = window.location.search.substr(1).match(_reg);
// if(_target != null) return unescape(_target[2]);
if(_target != null) return true;
return false;
}

DMRE.protoentity._init = function(){
DMRE.prototype._init = function(){
var that = this;
this.dmWrap = Zepto('#dm');
this.dmWrapHeight = Zepto('#dm').height();
Expand All @@ -68,7 +68,7 @@ DMRE.protoentity._init = function(){
}
this._isDown = this._getUrlParam('down');
Zepto(this.dmWrap).empty();
entityof this.is_full_control == 'boolean' && this.is_full_control ? Zepto(this.dmSwitch).css('display', 'none') : Zepto(this.dmSwitch).css('display', 'block');
typeof this.is_full_control == 'boolean' && this.is_full_control ? Zepto(this.dmSwitch).css('display', 'none') : Zepto(this.dmSwitch).css('display', 'block');
if(window.localStorage && !localStorage.dmState){
localStorage.dmState = 'on'; // 初始化弹幕状态,默认打开,关闭为off
this.manager.emit('dm_on');
Expand Down Expand Up @@ -114,11 +114,11 @@ DMRE.protoentity._init = function(){
}
}

DMRE.protoentity.log = function(text){
DMRE.prototype.log = function(text){
jlog('[DMRE] ' + text);
}

DMRE.protoentity._cutStr = function(str, len){
DMRE.prototype._cutStr = function(str, len){
var str_length = 0;
var str_len = 0;
str_cut = new String();
Expand All @@ -140,7 +140,7 @@ DMRE.protoentity._cutStr = function(str, len){
}
}

DMRE.protoentity._getDM = function(){
DMRE.prototype._getDM = function(){
var obj = this.manager.readSync();
if(!obj){
this.log('get_dm, get null value');
Expand All @@ -159,7 +159,7 @@ DMRE.protoentity._getDM = function(){
return dm;
}

DMRE.protoentity._cutStr = function(str, len){
DMRE.prototype._cutStr = function(str, len){
var str_length = 0;
var str_len = 0;
str_cut = new String();
Expand All @@ -181,12 +181,12 @@ DMRE.protoentity._cutStr = function(str, len){
}
}

DMRE.protoentity._renderDM = function(dm){
DMRE.prototype._renderDM = function(dm){
if(!dm){
return null;
}
var html = [];
if(dm.entity && dm.entity == 'realtime'){ //是否为实时
if(dm.type && dm.type == 'realtime'){ //是否为实时
html.push('<div onclick=\'ga("send", "event", "dm", "click", "dm-item")\' class="dm-item new" style="top: ' + this.dmWrapHeight + 'px; opacity: ' + this.itemOpacity + '">');
}else{
html.push('<a data-id="'+dm.id+'" data-nickname="'+dm.nickname+'" class="dm-item" style="top: ' + this.dmWrapHeight + 'px; opacity: ' + this.itemOpacity + '" tapmode="">');
Expand All @@ -207,7 +207,7 @@ DMRE.protoentity._renderDM = function(dm){
return html.join('');
}

DMRE.protoentity._load = function(){
DMRE.prototype._load = function(){
var _html = this._renderDM(this._getDM());
if(_html != null){
return _html;
Expand All @@ -216,7 +216,7 @@ DMRE.protoentity._load = function(){
}
}

DMRE.protoentity._start = function(){
DMRE.prototype._start = function(){
if(localStorage.dmState === 'off'){
return;
}
Expand All @@ -238,7 +238,7 @@ DMRE.protoentity._start = function(){
// }
}

DMRE.protoentity._pause = function(){
DMRE.prototype._pause = function(){
clearTimeout(this.timer);
// if(/android/i.test(this._ua)){
// Zepto(this.dmSwitchIcon).css('background-position', '0 0');
Expand All @@ -247,7 +247,7 @@ DMRE.protoentity._pause = function(){
// }
}

DMRE.protoentity._close = function(){
DMRE.prototype._close = function(){
clearTimeout(this.timer);
var dmWrap = Zepto(this.dmWrap);
dmWrap.animate({ 'opacity': 0 }, this.ANIM_TIME, 'ease-out', function(){
Expand All @@ -263,7 +263,7 @@ DMRE.protoentity._close = function(){
this.manager.emit('dm_off');
}

DMRE.protoentity._open = function(){
DMRE.prototype._open = function(){
clearTimeout(this.timer);
var that = this,
dmWrap = Zepto(this.dmWrap);
Expand All @@ -281,11 +281,11 @@ DMRE.protoentity._open = function(){
this.manager.emit('dm_on');
}

DMRE.protoentity._getTranslateY = function(item){
DMRE.prototype._getTranslateY = function(item){
return parseInt(Zepto(item).css('-webkit-transform').match(/\-?[0-9]+/g)[0]);
}

DMRE.protoentity._anmite = function(isEnd){
DMRE.prototype._anmite = function(isEnd){
var that = this;
var dmItems = Zepto(this.dmWrap).find(this.dmItemClass);
var newItemHeight = Zepto(dmItems).last().height();
Expand Down

0 comments on commit 2167c68

Please sign in to comment.