Created
November 27, 2015 06:34
-
-
Save baquiax/403a6883512fc5485712 to your computer and use it in GitHub Desktop.
Ads Video JS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(document).ready(function() { | |
if(window.location.hash) { | |
console.log("Pasa el hash " + window.location.hash); | |
jQuery(window).load(function() { | |
if ( window.location.hash.length > 0) { | |
console.log("Pasa el hash length " + window.location.hash.length); | |
var adIdFrame = window.location.hash; | |
console.log("id: " + adIdFrame); | |
console.log(jQuery("" + adIdFrame)); | |
var videoIframe = jQuery("" + adIdFrame).closest(".centerAd").siblings(".videoPlayer:first"); | |
console.log(videoIframe); | |
jQuery(videoIframe).attr('src', jQuery(videoIframe).attr('src') + '?autoplay=1'); | |
console.log(jQuery(videoIframe).attr('src')); | |
jQuery(adIdFrame).closest(".centerAd").siblings(".videoBlock").remove(); | |
jQuery(adIdFrame).closest(".centerAd").remove(); | |
} | |
}); | |
return; | |
} | |
window.lastIframe = ""; | |
window.onbeforeunload = function (e) { | |
if (window.lastIframe.length) | |
window.open(document.location.href + "#" + window.lastIframe); | |
} | |
var isOverIFrame = false; | |
function processMouseOut() { | |
log("IFrame mouse >> OUT << detected."); | |
isOverIFrame = false; | |
top.focus(); | |
} | |
function processMouseOver() { | |
log("IFrame mouse >> OVER << detected."); | |
window.lastIframe = jQuery(this).attr("id"); | |
isOverIFrame = true; | |
} | |
function processIFrameClick() { | |
if(isOverIFrame) { | |
log("IFrame >> CLICK << detected. " + window.lastIframe); | |
var videoIframe = jQuery("#"+window.lastIframe).closest(".centerAd").siblings(".videoPlayer:first"); | |
jQuery(videoIframe).attr('src', jQuery(videoIframe).attr('src') + '?autoplay=1'); | |
setTimeout(function(){ | |
jQuery("#"+window.lastIframe).closest(".centerAd").siblings(".videoBlock").remove(); | |
jQuery("#"+window.lastIframe).closest(".centerAd").remove(); | |
}, 1000); | |
} | |
} | |
function log(message) { | |
console.log(message); | |
} | |
function attachOnloadEvent(func, obj) { | |
if(typeof window.addEventListener != 'undefined') { | |
window.addEventListener('load', func, false); | |
} else if (typeof document.addEventListener != 'undefined') { | |
document.addEventListener('load', func, false); | |
} else if (typeof window.attachEvent != 'undefined') { | |
window.attachEvent('onload', func); | |
} else { | |
if (typeof window.onload == 'function') { | |
var oldonload = onload; | |
window.onload = function() { | |
oldonload(); | |
func(); | |
}; | |
} else { | |
window.onload = func; | |
} | |
} | |
} | |
function init() { | |
var element = jQuery('iframe[name^=aswift_]'); | |
for (var i=0; i<element.length; i++) { | |
element[i].onmouseover = processMouseOver; | |
element[i].onmouseout = processMouseOut; | |
} | |
if (typeof window.attachEvent != 'undefined') { | |
top.attachEvent('onblur', processIFrameClick); | |
} | |
else if (typeof window.addEventListener != 'undefined') { | |
top.addEventListener('blur', processIFrameClick, false); | |
} | |
} | |
attachOnloadEvent(init); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment