Added trust levels to site setting and bug found in adsense reload comment out in line 30 to 57

This commit is contained in:
vi 2015-09-01 11:16:07 +10:00
parent a7258f4848
commit 2f1ac77380
4 changed files with 55 additions and 50 deletions

View File

@ -3,6 +3,7 @@ import PageTracker from 'discourse/lib/page-tracker';
var ad_width = '';
var ad_height = '';
var ad_code = '';
var currentUser = Discourse.User.current();
var publisher_id = Discourse.SiteSettings.adsense_publisher_code;
var preGoogleVars = null;
var postGoogleVars = null;
@ -18,43 +19,42 @@ function splitHeightInt(value) {
return str.trim();
}
PageTracker.current().on('change', function(url) {
var ads = document.getElementById("adsense_loader");
if (ads) {
// clear the old element and its state
//ads.remove();
ads.parentNode.removeChild(ads);
for (var i = 0; i < postGoogleVars.length; i++) {
var key = postGoogleVars[i];
window[key] = undefined;
}
}
if(preGoogleVars === null) {
preGoogleVars = [];
for(var key in window) {
if(key.indexOf("google") !== -1) {
preGoogleVars.push(key);
for (var key in window) {
if (key.indexOf("google") !== -1){
window[key] = undefined;
}
}
}
// for (var i = 0; i < postGoogleVars.length; i++) {
// var key = postGoogleVars[i];
// 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";
ga.src = '//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js';
ga.addEventListener('load', function(e) {
if(postGoogleVars === null) {
postGoogleVars = [];
// 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);
}
}
}
});
// 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);
});
@ -66,28 +66,29 @@ var data = {
"post-bottom" : {}
}
if (Discourse.SiteSettings.adsense_publisher_code) {
if (Discourse.SiteSettings.adsense_topic_list_top_code && !Discourse.SiteSettings.adsense_show_topic_list_top) {
data["topic-list-top"]["ad_code"] = Discourse.SiteSettings.adsense_topic_list_top_code;
data["topic-list-top"]["ad_width"] = parseInt(splitWidthInt(Discourse.SiteSettings.adsense_topic_list_top_ad_sizes));
data["topic-list-top"]["ad_height"] = parseInt(splitHeightInt(Discourse.SiteSettings.adsense_topic_list_top_ad_sizes));
}
if (Discourse.SiteSettings.adsense_topic_above_post_stream_code && !Discourse.SiteSettings.adsense_show_topic_above_post_stream) {
data["topic-above-post-stream"]["ad_code"] = Discourse.SiteSettings.adsense_topic_above_post_stream_code;
data["topic-above-post-stream"]["ad_width"] = parseInt(splitWidthInt(Discourse.SiteSettings.adsense_topic_above_post_stream_ad_sizes));
data["topic-above-post-stream"]["ad_height"] = parseInt(splitHeightInt(Discourse.SiteSettings.adsense_topic_above_post_stream_ad_sizes));
}
if (Discourse.SiteSettings.adsense_topic_above_suggested_code && !Discourse.SiteSettings.adsense_show_topic_above_suggested) {
data["topic-above-suggested"]["ad_code"] = Discourse.SiteSettings.adsense_topic_above_suggested_code;
data["topic-above-suggested"]["ad_width"] = parseInt(splitWidthInt(Discourse.SiteSettings.adsense_topic_above_suggested_ad_sizes));
data["topic-above-suggested"]["ad_height"] = parseInt(splitHeightInt(Discourse.SiteSettings.adsense_topic_above_suggested_ad_sizes));
}
if (Discourse.SiteSettings.adsense_post_bottom_code && !Discourse.SiteSettings.adsense_show_post_bottom) {
data["post-bottom"]["ad_code"] = Discourse.SiteSettings.adsense_post_bottom_code;
data["post-bottom"]["ad_width"] = parseInt(splitWidthInt(Discourse.SiteSettings.adsense_post_bottom_ad_sizes));
data["post-bottom"]["ad_height"] = parseInt(splitHeightInt(Discourse.SiteSettings.adsense_post_bottom_ad_sizes));
}
// if ((currentUser) && (currentUser.get('trust_level') > Discourse.SiteSettings.adsense_through_trust_level)) {
if (Discourse.SiteSettings.adsense_topic_list_top_code && !Discourse.SiteSettings.adsense_show_topic_list_top && !((currentUser) && (currentUser.get('trust_level') > Discourse.SiteSettings.adsense_through_trust_level))) {
data["topic-list-top"]["ad_code"] = Discourse.SiteSettings.adsense_topic_list_top_code;
data["topic-list-top"]["ad_width"] = parseInt(splitWidthInt(Discourse.SiteSettings.adsense_topic_list_top_ad_sizes));
data["topic-list-top"]["ad_height"] = parseInt(splitHeightInt(Discourse.SiteSettings.adsense_topic_list_top_ad_sizes));
}
if (Discourse.SiteSettings.adsense_topic_above_post_stream_code && !Discourse.SiteSettings.adsense_show_topic_above_post_stream && !((currentUser) && (currentUser.get('trust_level') > Discourse.SiteSettings.adsense_through_trust_level))) {
data["topic-above-post-stream"]["ad_code"] = Discourse.SiteSettings.adsense_topic_above_post_stream_code;
data["topic-above-post-stream"]["ad_width"] = parseInt(splitWidthInt(Discourse.SiteSettings.adsense_topic_above_post_stream_ad_sizes));
data["topic-above-post-stream"]["ad_height"] = parseInt(splitHeightInt(Discourse.SiteSettings.adsense_topic_above_post_stream_ad_sizes));
}
if (Discourse.SiteSettings.adsense_topic_above_suggested_code && !Discourse.SiteSettings.adsense_show_topic_above_suggested && !((currentUser) && (currentUser.get('trust_level') > Discourse.SiteSettings.adsense_through_trust_level))) {
data["topic-above-suggested"]["ad_code"] = Discourse.SiteSettings.adsense_topic_above_suggested_code;
data["topic-above-suggested"]["ad_width"] = parseInt(splitWidthInt(Discourse.SiteSettings.adsense_topic_above_suggested_ad_sizes));
data["topic-above-suggested"]["ad_height"] = parseInt(splitHeightInt(Discourse.SiteSettings.adsense_topic_above_suggested_ad_sizes));
}
if (Discourse.SiteSettings.adsense_post_bottom_code && !Discourse.SiteSettings.adsense_show_post_bottom && !((currentUser) && (currentUser.get('trust_level') > Discourse.SiteSettings.adsense_through_trust_level))) {
data["post-bottom"]["ad_code"] = Discourse.SiteSettings.adsense_post_bottom_code;
data["post-bottom"]["ad_width"] = parseInt(splitWidthInt(Discourse.SiteSettings.adsense_post_bottom_ad_sizes));
data["post-bottom"]["ad_height"] = parseInt(splitHeightInt(Discourse.SiteSettings.adsense_post_bottom_ad_sizes));
}
// }
}

View File

@ -12,7 +12,6 @@
</div>
{{else}}
<div class="google-adsense-label"><h2>Google Adsense</h2></div>
<div style={{adWrapperStyle}}>
<ins class="adsbygoogle"
style={{adInsStyle}}

View File

@ -23,6 +23,7 @@ en:
dfp_target_post_bottom_key_code: "Input key values - Inventory Level"
dfp_target_post_bottom_value_code: "Input key values - Inventory Level"
adsense_publisher_code: "Insert your Publisher ID here"
adsense_through_trust_level: "Show your ads to users based on trust."
adsense_show_topic_list_top: "Disable topic_list_top ad"
adsense_topic_list_top_code: "Show leaderboard ad above topic lists."
adsense_topic_list_top_ad_sizes: "Choose your ad sizes"

View File

@ -2,6 +2,10 @@ adsense_plugin:
adsense_publisher_code:
client: true
default: ''
adsense_through_trust_level:
client: true
default: 2
enum: 'TrustLevelSetting'
adsense_topic_list_top_code:
client: true
default: ''