diff --git a/assets/javascripts/discourse/components/google-adsense.js.es6 b/assets/javascripts/discourse/components/google-adsense.js.es6
index 74e5a1d..3b01972 100644
--- a/assets/javascripts/discourse/components/google-adsense.js.es6
+++ b/assets/javascripts/discourse/components/google-adsense.js.es6
@@ -3,6 +3,10 @@ import PageTracker from 'discourse/lib/page-tracker';
var ad_width = '';
var ad_height = '';
var ad_code = '';
+var ad_mobile_width = 320;
+var ad_mobile_height = 50;
+var ad_mobile_code = '';
+var currentUser = Discourse.User.current();
var publisher_id = Discourse.SiteSettings.adsense_publisher_code;
var preGoogleVars = null;
var postGoogleVars = null;
@@ -18,43 +22,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);
});
@@ -68,22 +71,27 @@ var data = {
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_show_topic_list_top && !((currentUser) && (currentUser.get('trust_level') > Discourse.SiteSettings.adsense_through_trust_level))) {
+ if (!Discourse.Mobile.mobileView && Discourse.SiteSettings.adsense_topic_list_top_code) {
+ 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.Mobile.mobileView && Discourse.SiteSettings.adsense_mobile_topic_list_top_code) {
+ data["topic-list-top"]["ad_mobile_code"] = Discourse.SiteSettings.adsense_mobile_topic_list_top_code;
+ }
}
- if (Discourse.SiteSettings.adsense_topic_above_post_stream_code && !Discourse.SiteSettings.adsense_show_topic_above_post_stream) {
+ 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) {
+ 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) {
+ 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));
@@ -98,11 +106,14 @@ export default Ember.Component.extend({
publisher_id: publisher_id,
ad_width: ad_width,
ad_height: ad_height,
+ ad_mobile_width: ad_mobile_width,
+ ad_mobile_height: ad_mobile_height,
init: function() {
this.set('ad_width', data[this.placement]["ad_width"] );
this.set('ad_height', data[this.placement]["ad_height"] );
this.set('ad_code', data[this.placement]["ad_code"] );
+ this.set('ad_mobile_code', data[this.placement]["ad_mobile_code"] );
this._super();
},
@@ -115,8 +126,8 @@ export default Ember.Component.extend({
}.property('adWrapperStyle'),
adWrapperStyleMobile: function() {
- return `width: 320px; height: 50px; margin:0 auto;`.htmlSafe();
- },
+ return `width: ${this.get('ad_mobile_width')}px; height: ${this.get('ad_mobile_height')}px; margin:0 auto;`.htmlSafe();
+ }.property('ad_mobile_width', 'ad_mobile_height'),
adInsStyleMobile: function() {
return `display: inline-block; ${this.get('adWrapperStyleMobile')}`.htmlSafe();
diff --git a/assets/javascripts/discourse/components/google-dfp-ad.js.es6 b/assets/javascripts/discourse/components/google-dfp-ad.js.es6
index 9b42b54..a969855 100755
--- a/assets/javascripts/discourse/components/google-dfp-ad.js.es6
+++ b/assets/javascripts/discourse/components/google-dfp-ad.js.es6
@@ -3,6 +3,9 @@ import loadScript from 'discourse/lib/load-script';
var const_width = '';
var const_height = '';
+var const_mobile_width = 320;
+var const_mobile_height = 50;
+var currentUser = Discourse.User.current();
var _loaded = false,
_promise = null;
@@ -86,7 +89,7 @@ function loadGoogle(settings) {
custom_targeting((keyParse(Discourse.SiteSettings.dfp_target_topic_list_top_key_code)), (keyParse(Discourse.SiteSettings.dfp_target_topic_list_top_value_code)), topic_list_top)
}
}
- if (settings.dfp_topic_above_post_stream_code && !settings.dfp_show_topic_above_post_stream && settings.topic_above_post_stream_ad_sizes) {
+ if (settings.dfp_topic_above_post_stream_code && !settings.dfp_show_topic_above_post_stream && settings.topic_above_post_stream_ad_sizes && !((currentUser) && (currentUser.get('trust_level') > Discourse.SiteSettings.dfp_through_trust_level))) {
const_width = parseInt(splitWidthInt(settings.topic_above_post_stream_ad_sizes));
const_height = parseInt(splitHeightInt(settings.topic_above_post_stream_ad_sizes));
if (Discourse.Mobile.mobileView) {
@@ -96,7 +99,7 @@ function loadGoogle(settings) {
custom_targeting((keyParse(Discourse.SiteSettings.dfp_target_topic_above_post_stream_key_code)), (keyParse(Discourse.SiteSettings.dfp_target_topic_above_post_stream_value_code)), topic_above_post_stream)
}
}
- if (settings.dfp_topic_above_suggested_code && !settings.dfp_show_topic_above_suggested && settings.topic_above_suggested_ad_sizes) {
+ if (settings.dfp_topic_above_suggested_code && !settings.dfp_show_topic_above_suggested && settings.topic_above_suggested_ad_sizes && !((currentUser) && (currentUser.get('trust_level') > Discourse.SiteSettings.dfp_through_trust_level))) {
const_width = parseInt(splitWidthInt(settings.topic_above_suggested_ad_sizes));
const_height = parseInt(splitHeightInt(settings.topic_above_suggested_ad_sizes));
if (Discourse.Mobile.mobileView) {
@@ -106,7 +109,7 @@ function loadGoogle(settings) {
custom_targeting((keyParse(Discourse.SiteSettings.dfp_target_topic_above_suggested_key_code)), (keyParse(Discourse.SiteSettings.dfp_target_topic_above_suggested_value_code)), topic_above_suggested)
}
}
- if (settings.dfp_post_bottom_code && !settings.dfp_show_post_bottom && settings.post_bottom_ad_sizes) {
+ if (settings.dfp_post_bottom_code && !settings.dfp_show_post_bottom && settings.post_bottom_ad_sizes && !((currentUser) && (currentUser.get('trust_level') > Discourse.SiteSettings.dfp_through_trust_level))) {
const_width = parseInt(splitWidthInt(settings.post_bottom_ad_sizes));
const_height = parseInt(splitHeightInt(settings.post_bottom_ad_sizes));
if (Discourse.Mobile.mobileView) {
@@ -131,6 +134,8 @@ function loadGoogle(settings) {
export default Ember.Component.extend({
const_width: const_width,
const_height: const_height,
+ const_mobile_width: const_mobile_width,
+ const_mobile_height: const_mobile_height,
classNames: ['google-dfp-ad'],
loadedGoogletag: false,
@@ -145,8 +150,8 @@ export default Ember.Component.extend({
}.property('const_width', 'const_height'),
adWrapperStyleMobile: function() {
- return `width: 320px; height: 50px;`.htmlSafe();
- },
+ return `width: ${this.get('const_mobile_width')}px; height: ${this.get('const_mobile_height')}px;`.htmlSafe();
+ }.property('const_mobile_width', 'const_mobile_height'),
_initGoogleDFP: function() {
var self = this;
diff --git a/assets/javascripts/discourse/templates/components/google-adsense.hbs b/assets/javascripts/discourse/templates/components/google-adsense.hbs
index f98d0d7..280fdcd 100644
--- a/assets/javascripts/discourse/templates/components/google-adsense.hbs
+++ b/assets/javascripts/discourse/templates/components/google-adsense.hbs
@@ -3,7 +3,7 @@
+ data-ad-slot={{ad_mobile_code}}>