(function(){
console.log("Starting Point");
// Creating and Appending scripts dynamically
function createScript(src) {
console.log("script for js");
var script = document.createElement('script');
script.src = src;
document.getElementsByTagName('head')[0].appendChild(script);
}
// End script tags Here
function createLink(href) {
console.log("script for links");
var link = document.createElement('link');
link.href = href;
link.rel = "stylesheet";
link.type = "type/css";
document.getElementsByTagName('head')[0].appendChild(link);
}
// DIV 1
// Create a main Div to hold everything
createScript('http://vjs.zencdn.net/4.7.1/video.js');
createScript('lib/videojs-contrib-ads/videojs.ads.js');
createScript('lib/vast-client.js');
createScript('videojs.vast.js');
createLink('http://vjs.zencdn.net/4.7.1/video-js.css');
createLink('lib/videojs-contrib-ads/videojs.ads.css');
createLink('videojs.vast.css');
console.log("Create mainDiv");
var mainDiv = document.createElement('div');
mainDiv.id = 'ad_placement';
// mainDiv.style.float = "right";
var currentScript = document.currentScript;
currentScript.parentElement.insertBefore(mainDiv, currentScript);
// document.body.appendChild(mainDiv);
console.log("End MainDiv");
// End main Div here
// DIV 2
// Div to hold the video
console.log("Create innerDiv")
var divContainer = document.createElement('div');
divContainer.class = 'example-video-container';
divContainer.style.display = 'inline-block';
mainDiv.appendChild(divContainer);
console.log("Create innerDiv")
// End parent Div here (parent of video div/tag)
// Video Player Below
// Create the video tag for html video player
console.log("Video Creation Started");
var video = document.createElement('video');
video.id = 'vid2';
video.width = 300;
video.height = 250;
video.class = 'video-js vjs-default-skin';
video.autoplay = true;
video.controls = true;
video.muted = true;
video.preload = 'auto';
video.poster = "http://www.jqueryscript.net/images/Simplest-Responsive-jQuery-Image-Lightbox-Plugin-simple-lightbox.jpg";
//video.data-setup = '{}';
// Function to create sources for video
function addSourceToVideo(element, src, type) {
var source = document.createElement('source');
source.src = src;
source.type = type;
element.appendChild(source);
}
addSourceToVideo(video, 'http://grochtdreis.de/fuer-jsfiddle/video/sintel_trailer-480.mp4', 'video/mp4');
addSourceToVideo(video, 'http://video-js.zencoder.com/oceans-clip.mp4', 'video/webm');
addSourceToVideo(video, 'http://video-js.zencoder.com/oceans-clip.mp4', 'video/ogg');
console.log("Video Creation End");
console.log("Para Started");
var paragraph = document.createElement('p');
paragraph.innerHTML = "Video PlayBack Not Supported";
video.appendChild(paragraph);
video.load();
//video.play();
divContainer.appendChild(video);
console.log("Para end");
// Video player creation ends here
console.log("Before calling videojs");
var vid2 = videojs('vid2');
console.log("After calling videojs");
vid2.muted(true);
vid2.ads({
timeout: 5000
});
vid2.vast({
url: 'vast_tag_url'
});
vid2.on('readyforpreroll', function() {
vid2.ads.startLinearAdMode();
vid2.one('ended', function() {
vid2.ads.endLinearAdMode();
console.log("ad finished");
document.getElementById('adPlacement').innerHTML="<img src='https://wallazee.global.ssl.fastly.net/images/variant/20140109-11d5e6789afea899c324f5d4cbfa00eca24c58c8b790e1d6305c36e-1024.png' width=300 height=250 border=0/>";
});
});
vid2.on('adtimeout', function() {
console.log("timout happened")
document.getElementById('adPlacement').innerHTML="<img src='https://wallazee.global.ssl.fastly.net/images/variant/20140109-11d5e6789afea899c324f5d4cbfa00eca24c58c8b790e1d6305c36e-1024.png' width=300 height=250 border=0/>";
});
console.log("End of file");
})();