(function () { var scriptName = "embed.js"; //name of this script, used to get reference to own tag var jQuery; //noconflict reference to jquery var jqueryPath = "https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"; var jqueryVersion = "1.12.4"; var scriptTag; //reference to the html script tag /******** Get reference to self (scriptTag) *********/ var allScripts = document.getElementsByTagName('script'); var targetScripts = []; for (var i in allScripts) { var name = allScripts[i].src if(name && name.indexOf(scriptName) > 0) targetScripts.push(allScripts[i]); } scriptTag = targetScripts[targetScripts.length - 1]; function loadVideoPlayer (SM_RemoteUrl, SM_Widget, SM_Quantidade, SM_bid) { var jsonp_url = SM_RemoteUrl + "/widget/?site=" + SM_Widget + "&qtd=" + SM_Quantidade + "&bid=" + SM_bid; jQuery.getJSON(jsonp_url, function(result) { console.log('SM window width ->x ' + jQuery(window).width()); var SM_window = jQuery(window).width(); jQuery('#onevideo').html(result.videohtml); var sm_my_image = new Image(); var sm_cid = Math.floor(Math.random() * 0x7FFFFFFF) + "." + Math.floor(Date.now() / 1000); sm_my_image.src = 'https://www.google-analytics.com/collect?v=1&tid=UA-55691057-15&cid=' + sm_cid + '&t=event&ec=' + SM_Widget + '&ea=' + window.location.href ; //loadAds(result.site.AdTag); playvideo(); jQuery('#ov_ContentLst').val(JSON.stringify(result.lstContent)); }); } function playvideo(){ console.log("play video") var player = videojs('content_video', { width: '730', controls: true, preload: 'auto', loop: true, autoplay: 'muted', // responsive: true, // sources: [{ // src: 'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4', // type: 'video/mp4' // }] }); } /******** load ads *********/ function loadAds(adTag) { console.log('adtag -> ' + adTag) var player = videojs('content_video'); var options = { id: 'content_video', // adTagUrl: 'http://pubads.g.doubleclick.net/gampad/ads?sz=640x480&' + // 'iu=/124319096/external/ad_rule_samples&ciu_szs=300x250&ad_rule=1&' + // 'impl=s&gdfp_req=1&env=vp&output=xml_vmap1&unviewed_position_start=1&' + // 'cust_params=sample_ar%3Dpremidpostpod%26deployment%3Dgmf-js&cmsid=496&' + // 'vid=short_onecue&correlator=' adTagUrl: adTag }; player.ima(options); // Remove controls from the player on iPad to stop native controls from stealing // our click var contentPlayer = document.getElementById('content_video_html5_api'); if ((navigator.userAgent.match(/iPad/i) || navigator.userAgent.match(/Android/i)) && contentPlayer.hasAttribute('controls')) { contentPlayer.removeAttribute('controls'); } // Initialize the ad container when the video player is clicked, but only the // first time it's clicked. var initAdDisplayContainer = function() { player.ima.initializeAdDisplayContainer(); wrapperDiv.removeEventListener(startEvent, initAdDisplayContainer); } var startEvent = 'click'; if (navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i) || navigator.userAgent.match(/Android/i)) { startEvent = 'touchend'; } var wrapperDiv = document.getElementById('content_video'); wrapperDiv.addEventListener(startEvent, initAdDisplayContainer); } /******** helper function to load external scripts *********/ function loadScript(src, onLoad) { var script_tag = document.createElement('script'); script_tag.setAttribute("type", "text/javascript"); script_tag.setAttribute("src", src); if (script_tag.readyState) { script_tag.onreadystatechange = function () { if (this.readyState == 'complete' || this.readyState == 'loaded') { onLoad(); } }; } else { script_tag.onload = onLoad; } (document.getElementsByTagName("head")[0] || document.documentElement).appendChild(script_tag); } /******** helper function to load external css *********/ function loadCss(href) { var link_tag = document.createElement('link'); link_tag.setAttribute("type", "text/css"); link_tag.setAttribute("rel", "stylesheet"); link_tag.setAttribute("href", href); (document.getElementsByTagName("head")[0] || document.documentElement).appendChild(link_tag); } /******** load jquery into 'jQuery' variable then call main ********/ if (window.jQuery === undefined || window.jQuery.fn.jquery !== jqueryVersion) { loadScript(jqueryPath, initjQuery); } else { initjQuery(); } function initjQuery() { jQuery = window.jQuery.noConflict(true); main(); } function getP(name){ if(name=(new RegExp('[?&]'+encodeURIComponent(name)+'=([^&]*)')).exec(location.search)) return decodeURIComponent(name[1]); } /******** starting point for your widget ********/ function main() { //your widget code goes here //configuracoes aqui console.log('SM INIT -> '); var SM_bid = getP('buildId') console.log("bid = " + SM_bid) SM_bid = "430c2a3f-932d-415c-838b-9cbeda4bd600" var SM_RemoteUrl = 'https://videolab.com.br' // var SM_RemoteUrl = 'http://localhost:23080' var SM_Widget = "meucliente"; var SM_Quantidade = "5" ; loadCss(SM_RemoteUrl + "/static/widget/site.css"); //loadCss("http://localhost:18080/static/widget/site.css"); // load dos arquivos videojs loadCss("https://videolab.com.br/static/videojs/video-js.css"); loadCss("https://videolab.com.br/static/ima/videojs.ads.css"); loadCss("https://videolab.com.br/static/ima/videojs.ima.css"); loadScript("https://videolab.com.br/static/videojs/video.js", function() { loadScript("//imasdk.googleapis.com/js/sdkloader/ima3.js" , function() { loadScript("https://videolab.com.br/static/ima/videojs.ads.min.js" , function() { loadScript("https://videolab.com.br/static/ima/videojs.ima.js" , function() { loadVideoPlayer(SM_RemoteUrl, SM_Widget, SM_Quantidade, SM_bid); }); }); }); }); jQuery(document).ready(function ($) { jQuery(document).on("click","#ov_LeiaMais",function() { console.log("ov_LeiaMais Click"); var myPlayer = videojs('content_video'); var whereYouAt = myPlayer.currentTime(); console.log( whereYouAt + " sec." ); var lstContent = JSON.parse(jQuery('#ov_ContentLst').val()); //console.log(' lstContent = ' + lstContent) jQuery.each(lstContent, function(index, element) { if (whereYouAt >= element.Ini && whereYouAt <= element.End ) { console.log("CLICK --> " + element.Title ); window.location.href = element.PermalinkUrl; } }); }); //loadScript("http://example.com/anotherscript.js", function() { /* loaded */ }); }); } })(); function LeiaMais(){ console.log('hi'); }