function videomplay(dom) {
var $videoarea = $(dom),
$videoitem,
videolinks = [],
videoinfor = [];
if ($videoarea.hasclass("owl-carousel")) {
$videoitem = $(".owl-item:not(.cloned) .item_block", dom);
} else {
$videoitem = $(".item_block", dom);
}
function getsingle(fn) {
var result;
return function() {
return result ? result : (result = fn.apply(this, arguments));
};
}
var singlevbg = getsingle(createvideobg);
function createvideobg(obj) {
var videobg = $(
'
'
).appendto($("body")),
initobj,
config,
result,
timer;
initobj = {
initdo: function initdo() {},
outdo: function outdo() {},
indo: function indo() {},
hide: function hide() {
config.outdo.call(this, result);
videobg.fadeout();
$(videobg).removeclass("deepview");
cleartimeout(timer);
},
show: function show() {
timer = settimeout(function() {
$(videobg).addclass("deepview");
}, 4000);
config.indo.call(this, result);
videobg.fadein();
}
};
config = $.extend(initobj, obj);
videobg.on({
click: function click(ev) {
if ($(ev.target).hasclass("vplayarea")) {
initobj.hide();
}
},
mousewheel: function mousewheel() {
return false;
},
mousemove: function mousemove() {
var _this = this;
$(_this).removeclass("deepview");
if (timer) {
cleartimeout(timer);
}
timer = settimeout(function() {
$(_this).addclass("deepview");
}, 4000);
}
});
result = {
bgjdom: videobg,
hide: initobj.hide,
show: initobj.show
};
initobj.initdo.call(this, result);
return result;
}
var videom = function videom(config, cd) {
var cb = cb || {};
this.initdo = false;
this.evlist = {};
this.initconfig = {
link: []
};
this.cb = {};
$.extend(true, this.initconfig, config);
$.extend(true, this.cb, cb);
};
videom.prototype = {
construct: videom,
init: function init(box, infor) {
var videoinfor,
v = this,
videoarea;
if (typeof infor == "number") {
videoinfor = this.initconfig.list[infor];
} else {
videoinfor = {
videolink: infor
};
}
if (this.initdo == true) {
this.tabto(videoinfor);
this._trigger("initdo");
return;
}
this.initdo = true;
var str = '";
$(str).on("click", function(ev) {
ev.stoppropagation();
});
videoarea = $(str).appendto(box);
v.box = box;
v.videoarea = videoarea;
v.video = videoarea.find("iframe");
v.videobox = videoarea.find(".vplayitem");
v.inforbox = videoarea.find(".videoinfor");
v.desbox = videoarea.find(".videodes");
v.videodom = v.video[0];
// v._tabtext(v.inforbox.find('.title'), videoinfor.title);
// v._tabtext(v.inforbox.find('.subtitle'), videoinfor.subtitle);
// v._tabtext(v.desbox.find('.description'), videoinfor.description);
v._addcontrol(infor);
this._bind("initdo", function() {
var _this = this;
this.video.on("click", function(ev) {
if (ev.which == 1) {
_this.tabstate();
}
});
});
this._trigger("initdo");
this.tabto(videoinfor);
},
on: function on(name, fn) {
this._bind(name, fn);
},
tabto: function tabto(infor) {
void 0;
var initinfor = {
index: 0,
description: "",
subtitle: "",
title: "",
videolink: ""
};
$.extend(initinfor, infor);
this._tabbtn(infor.index);
this.video.attr("src", initinfor.videolink);
this._tabtext(this.inforbox.find(".title"), initinfor.title);
this._tabtext(this.inforbox.find(".subtitle"), initinfor.subtitle);
this._tabtext(
this.desbox.find(".description"),
initinfor.description
);
},
out: function out() {
this._trigger("outvideo");
},
stop: function stop() {
this.videodom.src = "";
},
play: function play() {
this.videodom.src = "";
},
state: function state() {
var isplay;
if (this.videodom.paused) {
isplay = false;
} else {
isplay = true;
}
return isplay;
},
tabstate: function tabstate() {
var isplay = this.state();
if (isplay) {
this.stop();
} else {
this.play();
}
},
_addcontrol: function _addcontrol(num) {
if (typeof num != "number") return;
var hascontrol = false,
v = this,
prev,
next,
prevbtn,
nextbtn;
v.currentindex = num;
prev = {
index: num - 1,
classname: (function() {
if (typeof v.initconfig.list[num - 1] == "undefined") {
return "disable";
} else {
return "able";
}
})()
};
next = {
index: num + 1,
classname: (function() {
if (typeof v.initconfig.list[num + 1] == "undefined") {
return "disable";
} else {
return "able";
}
})()
};
if (hascontrol) {
prevbtn.data("index", prev.index).addclass(prev.classname);
nextbtn.data("index", next.index).addclass(next.classname);
return;
}
hascontrol = true;
var tabcontrolstr, tabcontrol;
tabcontrolstr =
'\n \n ';
tabcontrol = $(tabcontrolstr).appendto(v.box);
prevbtn = tabcontrol.find(".prev");
nextbtn = tabcontrol.find(".next");
tabcontrol.on("click", ".videotabbtn", function(ev) {
ev.stoppropagation();
var btn = this;
if ($(btn).hasclass("disable") == false) {
v.tabto(v.initconfig.list[$(btn).data("index")]);
}
return false;
});
v.tabcontrol = tabcontrol;
},
_tabbtn: function _tabbtn(index) {
this._addcontrol(index);
},
_tabtext: function _tabtext(el, text) {
if (typeof text == "undefined") {
$(el).css({
display: "none"
});
} else {
$(el).text(text);
}
},
_bindev: function _bindev(name, fn) {
var _this = this;
this.cb[name] = fn;
$.each(_this.cb, function(indexinarray, valueofelement) {
$(_this)
.off(name)
.on(name, fn);
});
},
_trigerev: function _trigerev(name, option) {
if (typeof this.cb[name] != "function") {
this._bindev(name, function() {});
}
$(this).trigger(name, option);
},
_bind: function _bind(name, fn) {
var _self = this,
evlist = this.evlist;
if (!evlist[name]) {
evlist[name] = [];
} else if (fn in evlist[name]) {
return;
}
this.evlist[name].push(fn);
},
_trigger: function _trigger(name, context, arg) {
var fns = this.evlist[name];
if (!fns || fns.length === 0) {
return false;
}
if (!context) {
context = this;
} else if (
object.prototype.tostring.call(context) == "[object array]"
) {
arg = context;
context = this;
}
$.each(fns, function(i, v) {
v.apply(context, arg);
});
}
};
$videoitem.each(function(i, e) {
var infor = {};
infor.index = i;
infor.title = $(e)
.find(".item_info .title")
.text();
infor.subtitle = $(e)
.find(".item_info .subtitle")
.text();
infor.description = $(e)
.find(".description")
.text();
infor.videolink = $(e).data("href");
videoinfor.push(infor);
videolinks.push($(e).data("href"));
});
var vplayer = new videom({
list: videoinfor
});
var vbg = singlevbg({
initdo: function initdo(bg) {},
indo: function indo(bg) {
$("body").on("keydown.video", function(ev) {
if (ev.keycode == 32) {
ev.stoppropagation();
ev.preventdefault();
vplayer.tabstate();
}
});
},
outdo: function outdo(bg) {
vplayer.out();
$("body").off("keydown.video");
}
}),
mask = vbg.bgjdom;
vplayer.on("initdo", function() {
vbg.show();
this.videoarea.addclass("vshow");
});
vplayer.on("outvideo", function() {
this.videoarea.removeclass("vshow");
settimeout(() => {
this.stop();
}, 360);
});
$videoitem.off().on({
"click.video": function clickvideo() {
var link = $(this).data("href"),
index = $(this).data("index");
if (typeof link == "undefined") return;
vplayer.init(mask, index);
return false;
}
});
}
if ($("html").hasclass("agent-pc")) {
$("script").on("load", function() {
settimeout(() => {
$(".videom .content_list .item_block").off();
$(function() {
$(".videom .content_list").each(function(i, e) {
videomplay(e);
});
});
}, 1000);
});
} else {
if ($(".bodyvideom .item_box.videom-box").attr("data-href")) {
$(".bodyvideom .item_box.videom-box").on("click", function() {
window.open($(this).attr("data-href"));
return false;
});
}
}