mirror of
https://github.com/discourse/discourse-adplugin.git
synced 2025-02-17 00:45:15 +00:00
Myles fixed it - fixed cmd undefined and fixed up adsense code that was undefining all vars beginning with google
This commit is contained in:
parent
d272a71b08
commit
50ee40cdfe
@ -4,6 +4,8 @@ var ad_width = '';
|
|||||||
var ad_height = '';
|
var ad_height = '';
|
||||||
var ad_code = '';
|
var ad_code = '';
|
||||||
var publisher_id = Discourse.SiteSettings.adsense_publisher_code;
|
var publisher_id = Discourse.SiteSettings.adsense_publisher_code;
|
||||||
|
var preGoogleVars = null;
|
||||||
|
var postGoogleVars = null;
|
||||||
|
|
||||||
function splitWidthInt(value) {
|
function splitWidthInt(value) {
|
||||||
var str = value.substring(0, 3);
|
var str = value.substring(0, 3);
|
||||||
@ -23,15 +25,34 @@ PageTracker.current().on('change', function(url) {
|
|||||||
// clear the old element and its state
|
// clear the old element and its state
|
||||||
//ads.remove();
|
//ads.remove();
|
||||||
ads.parentNode.removeChild(ads);
|
ads.parentNode.removeChild(ads);
|
||||||
for (var key in window) {
|
for (var i = 0; i < postGoogleVars.length; i++) {
|
||||||
if (key.indexOf("google") !== -1){
|
var key = postGoogleVars[i];
|
||||||
window[key] = undefined;
|
window[key] = undefined;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(preGoogleVars === null) {
|
||||||
|
preGoogleVars = [];
|
||||||
|
for(var key in window) {
|
||||||
|
if(key.indexOf("google") !== -1) {
|
||||||
|
preGoogleVars.push(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.id="adsense_loader";
|
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.id="adsense_loader";
|
||||||
ga.src = '//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js';
|
ga.src = '//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js';
|
||||||
|
ga.addEventListener('load', function(e) {
|
||||||
|
if(postGoogleVars === null) {
|
||||||
|
postGoogleVars = [];
|
||||||
|
|
||||||
|
for(var key in window) {
|
||||||
|
if(key.indexOf("google") !== -1 && preGoogleVars.indexOf(key) == -1) {
|
||||||
|
postGoogleVars.push(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
|
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user