Created
January 17, 2019 16:33
-
-
Save coderberry/710e77e683d27bc3cd0503afdd934f8d 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
(function() { | |
function embed () { | |
var evt = new Event('codefund'); | |
<% if @advertisement_html -%> | |
try { | |
var targetElement = document.getElementById('codefund'); | |
if (targetElement == null) { targetElement = document.getElementById('<%= @target %>'); } | |
targetElement.innerHTML = '<%= @advertisement_html.html_safe %>'; | |
targetElement.querySelector('img[data-src="impression_url"]').src = '<%= @impression_url.html_safe %>&uplift=' + (window.abp === true); | |
targetElement.querySelectorAll('a[data-href="campaign_url"]').forEach(function (a) { a.href = '<%= @campaign_url.html_safe %>' }); | |
evt.detail = { status: 'ok', house: <%= @campaign.fallback? %> }; | |
} catch (e) { | |
console.log('CodeFund detected an error! Please verify an element exists with id="codefund". ' + e.message); | |
evt.detail = { status: 'error', message: e.message }; | |
} | |
<% else -%> | |
console.log('CodeFund does not have a advertiser for you at this time.'); | |
evt.detail = { status: 'no-advertiser' }; | |
<% end -%> | |
document.removeEventListener('DOMContentLoaded', embed); | |
window.dispatchEvent(evt); | |
}; | |
(document.readyState === 'loading') ? document.addEventListener('DOMContentLoaded', embed) : embed(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment