discourse-adplugin/assets/javascripts/initializers/initialize-ad-plugin.js.es6

47 lines
1.3 KiB
Plaintext
Raw Normal View History

2015-08-03 21:25:00 -04:00
import PostModel from 'discourse/models/post';
2016-02-22 12:11:29 -05:00
import { withPluginApi } from 'discourse/lib/plugin-api';
2015-08-03 21:25:00 -04:00
export default {
2016-02-22 12:11:29 -05:00
name: 'initialize-ad-plugin',
initialize(container) {
const siteSettings = container.lookup('site-settings:main');
2015-08-03 21:25:00 -04:00
PostModel.reopen({
postSpecificCountDFP: function() {
return this.isNthPost(parseInt(siteSettings.dfp_nth_post_code));
}.property('post_number'),
postSpecificCountAdsense: function() {
return this.isNthPost(parseInt(siteSettings.adsense_nth_post_code));
}.property('post_number'),
postSpecificCountAmazon: function() {
return this.isNthPost(parseInt(siteSettings.amazon_nth_post_code));
}.property('post_number'),
isNthPost: function(n) {
if (n && n > 0) {
return (this.get('post_number') % n) === 0;
} else {
return false;
}
}
2015-08-03 21:25:00 -04:00
});
2016-02-22 12:11:29 -05:00
withPluginApi('0.1', api => {
api.decorateWidget('post:after', dec => {
if (dec.canConnectComponent) {
return dec.connect({ component: 'adplugin-container', context: 'model' });
}
// Old way for backwards compatibility
2016-02-22 12:11:29 -05:00
return dec.connect({
templateName: 'connectors/post-bottom/discourse-adplugin',
context: 'model'
});
});
});
2015-08-03 21:25:00 -04:00
}
};