Support linting, clean up some unused variables and weird spacing

This commit is contained in:
Robin Ward 2016-02-19 15:06:13 -05:00
parent 64996ed78c
commit ebed90fab7
4 changed files with 152 additions and 54 deletions

102
.eslintrc Normal file
View File

@ -0,0 +1,102 @@
{
"env": {
"jasmine": true,
"node": true,
"mocha": true,
"browser": true,
"builtin": true
},
ecmaVersion: 7,
"globals":
{"Ember":true,
"jQuery":true,
"$":true,
"RSVP":true,
"Discourse":true,
"Em":true,
"PreloadStore":true,
"Handlebars":true,
"I18n":true,
"bootbox":true,
"module":true,
"moduleFor":true,
"moduleForComponent":true,
"Pretender":true,
"sandbox":true,
"controllerFor":true,
"test":true,
"ok":true,
"not":true,
"expect":true,
"equal":true,
"visit":true,
"andThen":true,
"click":true,
"currentPath":true,
"currentRouteName":true,
"currentURL":true,
"fillIn":true,
"keyEvent":true,
"triggerEvent":true,
"count":true,
"exists":true,
"visible":true,
"invisible":true,
"asyncRender":true,
"selectDropdown":true,
"asyncTestDiscourse":true,
"fixture":true,
"find":true,
"sinon":true,
"moment":true,
"start":true,
"_":true,
"alert":true,
"containsInstance":true,
"deepEqual":true,
"notEqual":true,
"define":true,
"require":true,
"requirejs":true,
"hasModule":true,
"Blob":true,
"File":true},
"rules": {
"block-scoped-var": 2,
"dot-notation": 0,
"eqeqeq": [
2,
"allow-null"
],
"guard-for-in": 2,
"no-bitwise": 2,
"no-caller": 2,
"no-cond-assign": 0,
"no-debugger": 2,
"no-empty": 0,
"no-eval": 2,
"no-extend-native": 2,
"no-extra-parens": 0,
"no-irregular-whitespace": 2,
"no-iterator": 2,
"no-loop-func": 2,
"no-multi-str": 2,
"no-new": 2,
"no-plusplus": 0,
"no-proto": 2,
"no-script-url": 2,
"no-sequences": 2,
"no-shadow": 2,
"no-undef": 2,
"no-unused-vars": 2,
"no-with": 2,
"semi": 2,
"strict": 0,
"valid-typeof": 2,
"wrap-iife": [
2,
"inside"
]
},
"parser": "babel-eslint"
}

View File

@ -2,28 +2,27 @@ import PageTracker from 'discourse/lib/page-tracker';
var ad_width = ''; var ad_width = '';
var ad_height = ''; var ad_height = '';
var ad_code = '';
var ad_mobile_width = 320; var ad_mobile_width = 320;
var ad_mobile_height = 50; var ad_mobile_height = 50;
var ad_mobile_code = '';
var currentUser = Discourse.User.current(); var currentUser = Discourse.User.current();
var publisher_id = Discourse.SiteSettings.adsense_publisher_code; var publisher_id = Discourse.SiteSettings.adsense_publisher_code;
var mobile_width = 320; var mobile_width = 320;
var mobile_height = 50; var mobile_height = 50;
const mobileView = Discourse.Site.currentProp('mobileView');
function splitWidthInt(value) { function splitWidthInt(value) {
var str = value.substring(0, 3); var str = value.substring(0, 3);
return str.trim(); return str.trim();
} }
function splitHeightInt(value) { function splitHeightInt(value) {
var str = value.substring(4, 7); var str = value.substring(4, 7);
return str.trim(); return str.trim();
} }
// On each page change, the child is removed and elements part of Adsense's googleads are removed/undefined. // On each page change, the child is removed and elements part of Adsense's googleads are removed/undefined.
PageTracker.current().on('change', function(url) { PageTracker.current().on('change', function() {
var ads = document.getElementById("adsense_loader"); var ads = document.getElementById("adsense_loader");
if (ads) { if (ads) {
ads.parentNode.removeChild(ads); ads.parentNode.removeChild(ads);
@ -36,57 +35,54 @@ PageTracker.current().on('change', function(url) {
} }
} }
// Reinitialize script so that the ad can reload // Reinitialize script so that the ad can reload
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';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
}); });
var data = { var data = {
"topic-list-top" : {}, "topic-list-top" : {},
"topic-above-post-stream" : {}, "topic-above-post-stream" : {},
"topic-above-suggested" : {}, "topic-above-suggested" : {},
"post-bottom" : {} "post-bottom" : {}
} };
if (Discourse.SiteSettings.adsense_publisher_code) { if (Discourse.SiteSettings.adsense_publisher_code) {
if (!Discourse.Mobile.mobileView && Discourse.SiteSettings.adsense_topic_list_top_code) { if (!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_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_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)); 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) { if (mobileView && Discourse.SiteSettings.adsense_mobile_topic_list_top_code) {
data["topic-list-top"]["ad_mobile_code"] = 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.Mobile.mobileView && Discourse.SiteSettings.adsense_topic_above_post_stream_code) { if (!mobileView && Discourse.SiteSettings.adsense_topic_above_post_stream_code) {
data["topic-above-post-stream"]["ad_code"] = Discourse.SiteSettings.adsense_topic_above_post_stream_code; 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_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)); data["topic-above-post-stream"]["ad_height"] = parseInt(splitHeightInt(Discourse.SiteSettings.adsense_topic_above_post_stream_ad_sizes));
} }
if (Discourse.Mobile.mobileView && Discourse.SiteSettings.adsense_mobile_topic_above_post_stream_code) { if (mobileView && Discourse.SiteSettings.adsense_mobile_topic_above_post_stream_code) {
data["topic-above-post-stream"]["ad_mobile_code"] = Discourse.SiteSettings.adsense_mobile_topic_above_post_stream_code; data["topic-above-post-stream"]["ad_mobile_code"] = Discourse.SiteSettings.adsense_mobile_topic_above_post_stream_code;
} }
if (!Discourse.Mobile.mobileView && Discourse.SiteSettings.adsense_topic_above_suggested_code) { if (!mobileView && Discourse.SiteSettings.adsense_topic_above_suggested_code) {
data["topic-above-suggested"]["ad_code"] = Discourse.SiteSettings.adsense_topic_above_suggested_code; 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_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)); data["topic-above-suggested"]["ad_height"] = parseInt(splitHeightInt(Discourse.SiteSettings.adsense_topic_above_suggested_ad_sizes));
} }
if (Discourse.Mobile.mobileView && Discourse.SiteSettings.adsense_mobile_topic_above_suggested_code) { if (mobileView && Discourse.SiteSettings.adsense_mobile_topic_above_suggested_code) {
data["topic-above-suggested"]["ad_mobile_code"] = Discourse.SiteSettings.adsense_mobile_topic_above_suggested_code; data["topic-above-suggested"]["ad_mobile_code"] = Discourse.SiteSettings.adsense_mobile_topic_above_suggested_code;
} }
if (!Discourse.Mobile.mobileView && Discourse.SiteSettings.adsense_post_bottom_code) { if (!mobileView && Discourse.SiteSettings.adsense_post_bottom_code) {
data["post-bottom"]["ad_code"] = Discourse.SiteSettings.adsense_post_bottom_code; 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_width"] = parseInt(splitWidthInt(Discourse.SiteSettings.adsense_post_bottom_ad_sizes));
data["post-bottom"]["ad_height"] = parseInt(splitHeightInt(Discourse.SiteSettings.adsense_post_bottom_ad_sizes)); data["post-bottom"]["ad_height"] = parseInt(splitHeightInt(Discourse.SiteSettings.adsense_post_bottom_ad_sizes));
} }
if (Discourse.Mobile.mobileView && Discourse.SiteSettings.adsense_mobile_post_bottom_code) { if (mobileView && Discourse.SiteSettings.adsense_mobile_post_bottom_code) {
data["post-bottom"]["ad_mobile_code"] = Discourse.SiteSettings.adsense_mobile_post_bottom_code; data["post-bottom"]["ad_mobile_code"] = Discourse.SiteSettings.adsense_mobile_post_bottom_code;
} }
} }
export default Ember.Component.extend({ export default Ember.Component.extend({
classNames: ['google-adsense'], classNames: ['google-adsense'],
loadedGoogletag: false, loadedGoogletag: false,
@ -107,7 +103,7 @@ export default Ember.Component.extend({
this.set('ad_mobile_code', data[this.placement]["ad_mobile_code"] ); this.set('ad_mobile_code', data[this.placement]["ad_mobile_code"] );
this._super(); this._super();
}, },
adWrapperStyle: function() { adWrapperStyle: function() {
return `width: ${this.get('ad_width')}px; height: ${this.get('ad_height')}px; margin:0 auto;`.htmlSafe(); return `width: ${this.get('ad_width')}px; height: ${this.get('ad_height')}px; margin:0 auto;`.htmlSafe();
}.property('ad_width', 'ad_height'), }.property('ad_width', 'ad_height'),

View File

@ -1,5 +1,5 @@
{{#if checkTrustLevels}} {{#if checkTrustLevels}}
{{#if site.mobileView}} {{#if site.mobileView}}
<div class="google-adsense-label" style={{adTitleStyleMobile}}><h2>ADVERTISEMENT</h2></div> <div class="google-adsense-label" style={{adTitleStyleMobile}}><h2>ADVERTISEMENT</h2></div>
<div style={{adWrapperStyleMobile}}> <div style={{adWrapperStyleMobile}}>
<ins class="adsbygoogle" <ins class="adsbygoogle"
@ -7,7 +7,7 @@
data-ad-client="ca-pub-{{publisher_id}}" data-ad-client="ca-pub-{{publisher_id}}"
data-ad-slot={{ad_mobile_code}}> data-ad-slot={{ad_mobile_code}}>
</ins> </ins>
<script> <script>
(adsbygoogle = window.adsbygoogle || []).push({}); (adsbygoogle = window.adsbygoogle || []).push({});
</script> </script>
@ -27,5 +27,3 @@
</div> </div>
{{/if}} {{/if}}
{{/if}} {{/if}}

View File

@ -2,18 +2,20 @@ import PostModel from 'discourse/models/post';
export default { export default {
name: 'extend-post-model', name: 'extend-post-model',
initialize() { initialize(container) {
const siteSettings = container.lookup('site-settings:main');
PostModel.reopen({ PostModel.reopen({
postSpecificCountDFP: function() { postSpecificCountDFP: function() {
return this.get('post_number') === parseInt(Discourse.SiteSettings.dfp_nth_post_code); return this.get('post_number') === parseInt(siteSettings.dfp_nth_post_code);
}.property('post_number'), }.property('post_number'),
postSpecificCountAdsense: function() { postSpecificCountAdsense: function() {
return this.get('post_number') === parseInt(Discourse.SiteSettings.adsense_nth_post_code); return this.get('post_number') === parseInt(siteSettings.adsense_nth_post_code);
}.property('post_number'), }.property('post_number'),
postSpecificCountAmazon: function() { postSpecificCountAmazon: function() {
return this.get('post_number') === parseInt(Discourse.SiteSettings.amazon_nth_post_code); return this.get('post_number') === parseInt(siteSettings.amazon_nth_post_code);
}.property('post_number'), }.property('post_number'),
}); });
} }