Forked from richrhee/mps-fandango-scaling-component.js
Created
April 9, 2014 23:58
-
-
Save MaxKramnik/10331520 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Fandango Redesign Ad Scaling - jQuery ($) Required | |
mps._ready(function() { | |
mps.__scaleAds = function(adslot) { | |
var ADSLOT=adslot; var $aiframe = $('#'+mps.adslots[ADSLOT]+' iframe'); var $adivgpt = $('#'+mps.adslots[ADSLOT]); | |
if(typeof($)=='function' && typeof($aiframe)=='object' && typeof(vpSize)=='object' && vpSize.getW() < $aiframe.width()) { | |
window.console && console.debug('[IFRAME RESIZE: Triggered] Current Width: '+vpSize.getW()+' | Iframe Width: '+$aiframe.width()); | |
var scalesize = vpSize.getW(); | |
var scaleratio = (vpSize.getW() / $aiframe.width()); | |
var scaledheight = Math.floor($aiframe.height() * scaleratio); | |
var scaledwidth = Math.floor($aiframe.width() * scaleratio); | |
window.console && console.debug('[IFRAME RESIZE: Calculations] Scale Ratio: '+scaleratio+' | Scaled Width: '+scaledwidth+' | Scaled Height: '+scaledheight); | |
$aiframe.css('zoom',scaleratio).css('scale',scaleratio).css('-moz-transform-origin','0 0').css(' -o-transform','scale('+scaleratio+')').css('-o-transform-origin','0 0').css('-webkit-transform','scale('+scaleratio+')').css('-webkit-transform-origin','0 0').css('border','0').css('zoom','1'); | |
//$adivgpt.css('width','728px').css('padding','0').css('overflow','hidden'); | |
$adivgpt.css('margin','0 auto').css('padding',0).css('height',scaledheight+'px').css('width',scaledwidth+'px'); | |
} else { | |
window.console && console.debug('[IFRAME RESIZE] Bypass') | |
} | |
} | |
mps.__checkAndScale = function(ADSLOT) { | |
if(typeof(ADSLOT)!='string') return false; | |
// Check until ad unit is available | |
var checkslotcount = 0; | |
var checkslotinterval = 300; | |
var checkslotmax = 10; | |
var checkslot = function(recheckms) { | |
var checkslotrun = setTimeout(function () { | |
if(adselect = mps.selectAd(ADSLOT) && $('#'+mps.adslots[ADSLOT]+' iframe').width() > 299) { | |
window.console && console.debug('--> Scaling Attempt on try#'+checkslotcount); | |
mps.__scaleAds(ADSLOT); | |
clearTimeout(checkslotrun); | |
} else { | |
debugmode.log && window.console && console.debug('No ['+ADSLOT+'] ad found. Checking again in '+checkslotinterval+'ms'); | |
checkslotcount++; | |
if(checkslotcount < checkslotmax) { | |
checkslot(checkslotinterval); | |
} else { | |
window.console && console.debug('Reached ['+checkslotmax+'] max retries every ['+checkslotinterval+'ms] for ['+ADSLOT+'] '+mps._elapsed()); | |
} | |
} | |
}, recheckms); | |
} | |
checkslot(); | |
} | |
setTimeout(function(){ mps.__checkAndScale('topbanner') },1000); | |
setTimeout(function(){ mps.__checkAndScale('fishtank') },1500); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment