Created
August 22, 2014 18:56
-
-
Save astein/5bdb77111755c31b6108 to your computer and use it in GitHub Desktop.
Celtra js wrapper example. For 2.0 container.
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
TXM.dispatcher.addEventListener('START_ENGAGEMENT', function() { | |
TXM.params.celtraCorrectionId = setInterval(correctZIndex, 200); | |
var celtraDiv = document.createElement('div'); | |
document.body.appendChild(celtraDiv); | |
celtraDiv.className = 'celtra-ad-v3'; | |
var celtraImg = document.createElement('img'); | |
celtraImg.id = 'celtra-anchor-img'; | |
celtraDiv.appendChild(celtraImg); | |
celtraImg.style.display = 'none'; | |
celtraImg.onerror = function() { | |
var img = document.getElementById('celtra-anchor-img'); | |
var params = { | |
'channelId': 'ef09fa5a', | |
'clickUrl': '', | |
'preferredClickThroughWindow': '', | |
'clickEvent': 'advertiser', | |
'externalAdServer': 'Custom' | |
}; | |
var req = document.createElement('script'); | |
req.id = params.scriptId = 'celtra-script-' + (window.celtraScriptIndex = (window.celtraScriptIndex || 0) + 1); | |
params.clientTimestamp = new Date() / 1000; | |
req.src = (window.location.protocol == 'https:' ? 'https' : 'http') + '://ads.celtra.com/b3215997/web.js?'; | |
for (var k in params) { | |
req.src += '&' + encodeURIComponent(k) + '=' + encodeURIComponent(params[k]); | |
} | |
img.parentNode.insertBefore(req, img.nextSibling); | |
}; | |
celtraImg.src = 'data:image/png,celtra'; | |
}); | |
function correctZIndex() { | |
if ($("div[style*='2147483645']").length > 0) { | |
clearInterval(TXM.params.celtraCorrectionId); | |
console.log('here'); | |
var celtraWrapper = $("div[style*='2147483645']").css('z-index', 0); | |
TXM.params.engagement = celtraWrapper.children('iframe').contents().find('.celtra-screen-container'); | |
TXM.params.engagement.addClass('content engagement'); | |
TXM.params.engagement.on('click.anyClick', function(e) { | |
var zoom = document.body.style.zoom || 1; | |
var coords = TXM.utils.getMouseCoords(e); | |
if (coords[0] !== null) { | |
TXM.api.track('click', 'interaction', (coords[0] / zoom) + ',' + (coords[1] / zoom)); | |
} | |
}); | |
TXM.params.engagement.one('click.firstInteraction', TXM.api.true_attention._onFirstInteraction); | |
} | |
} | |
TXM.dispatcher.dispatchEvent('INTERACTIVE_ASSET_READY'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment