You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
2.6 KiB
JavaScript

function loadjscssfile(filename,filetype){
if(filetype == "js"){
var fileref = document.createElement('script');
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("src",filename);
}else if(filetype == "css"){
var fileref = document.createElement('link');
fileref.setAttribute("rel","stylesheet");
fileref.setAttribute("type","text/css");
fileref.setAttribute("href",filename);
}
if(typeof fileref != "undefined"){
document.getElementsByTagName("head")[0].appendChild(fileref);
}
}
function getVars(Parameter)
{
var vars = [], hash;
var hashes = Parameter.substring(Parameter.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}
if ( typeof jQuery == 'undefined' ) {
loadjscssfile("http://data.chinahighlights.com/js/jquery-1.8.2.min.js","js");
}
loadjscssfile("//www.chinahighlights.com/js/video/video-js.min.css","css");
loadjscssfile("http://data.chinahighlights.com/js/video/video.js","js");
$(function(){
chkVideo()
});
//判断加载
function chkVideo()
{
vstate=false;
if(typeof videojs != 'undefined'){
vstate=true;
videojs.options.flash.swf = "//www.chinahighlights.com/js/video/video-js.swf";
var obj=document.getElementById("js_chtvideo");
var arr=getVars(obj.getAttribute("data"));
var v_width=arr["v_width"];
var v_height=arr["v_height"];
var v_url=arr["v_url"];
var v_image=arr["v_image"];
var v_adimage=arr["v_adimage"];
var v_adurl=arr["v_adurl"];
var v_type=arr["v_type"];
var v_sn=arr["v_sn"];
var v_t=arr["t"];
var v_sourc=arr["sourc"];
var video_str="";
video_str = '<video id="chvideo" class="video-js vjs-default-skin" controls preload="none" width="'+v_width+'" height="'+v_height+'" poster="'+v_image+'" data-setup="{}"><source src="'+v_url+'" type=\'video/mp4\' /></video>';
$('#js_chtvideo').after(video_str);
videojs("chvideo", {"height":"auto", "width":"auto"}).ready(function(){
var myPlayer = this; // Store the video object
var aspectRatio = 3/4; // Make up an aspect ratio
function resizeVideoJS(){
console.log('1');
// Get the parent element's actual width
var width = document.getElementById(myPlayer.id()).parentElement.offsetWidth;
// Set width to fill parent element, Set height
myPlayer.width(width).height( width * aspectRatio );
}
resizeVideoJS(); // Initialize the function
window.onresize = resizeVideoJS; // Call the function on resize
});
}
if(vstate){return;}
stopt=setTimeout("chkVideo()", 3000);
}