Advertisement
Guest User

main.js

a guest
Jan 6th, 2016
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var loaded = false;
  2. var relativePath = config.relative_path;
  3.  
  4. $(window).on('action:ajaxify.start', function(e, url) {
  5.             $.getJSON(relativePath + "/google-adsense.config", function (data){
  6.  
  7.                     //If ad in header is enabled
  8.                     if (data.header_id && loaded == false) {
  9.                         $(getInsCode(data.client_id, data.header_id, '', 'margin:15px auto;', 'auto')).insertBefore("#content");
  10.                         (adsbygoogle = window.adsbygoogle || []).push({});
  11.                     }
  12.  
  13.                     //If ad in footer is enabled
  14.                     if (data.footer_id && loaded == false) {
  15.                         $(getInsCode(data.client_id, data.footer_id, '', 'margin:15px auto;', 'auto')).insertBefore("#footer");
  16.                         (adsbygoogle = window.adsbygoogle || []).push({});
  17.                     }
  18.  
  19.                     // After first post
  20.                     if (url.url.substring(0, 6) == "topic/") {
  21.                         if (data.after_first_post_id) {
  22.                             $(".posts >li:first-child").after("<li>" + getInsCode(data.client_id, data.after_first_post_id, '', 'margin: 15px auto', 'auto') + "</li><br>");
  23.                             (adsbygoogle = window.adsbygoogle || []).push({});
  24.                         }
  25.                         loaded = true;
  26.                     }
  27.  
  28.                     // First post
  29.                     if (data.first_post_id) {
  30.                         switch (data.first_post_position) {
  31.                             case 'bottom':
  32.                                 $(".posts >li:first-child .content").after("<li>" + getInsCode(data.client_id, data.first_post_id, '', 'margin: 15px auto', 'auto') + "</li><br>");
  33.                                 (adsbygoogle = window.adsbygoogle || []).push({});
  34.                                 break;
  35.  
  36.                             case 'top':
  37.                                 $(".posts >li:first-child .content").before("<li>" + getInsCode(data.client_id, data.first_post_id, '', 'margin: 15px auto', 'auto') + "</li><br><br>");
  38.                                 (adsbygoogle = window.adsbygoogle || []).push({});
  39.                                 break;
  40.  
  41.                             case 'left':
  42.                                 var height = $(".posts >li:first-child .content").height();
  43.                                 if (height < 250) {
  44.                                     var type = "rectangle";
  45.                                     var width = 300;
  46.                                 } else {
  47.                                     var width = 336;
  48.                                     var type = "vertical";
  49.                                 }
  50.                                 $(".posts >li:first-child .content").before(getInsCode(data.client_id, data.first_post_id, 'pull-left', 'width:' + width + 'px;  margin-right:30px;', type));
  51.                                 (adsbygoogle = window.adsbygoogle || []).push({});
  52.                                 break;
  53.  
  54.                             case 'right':
  55.                                 var height = $(".posts >li:first-child .content").height();
  56.                                 if (height < 250) {
  57.                                     var type = "rectangle";
  58.                                     var width = 300;
  59.                                 } else {
  60.                                     var width = 336;
  61.                                     var type = "vertical";
  62.                                 }
  63.                                 $(".posts >li:first-child .content").before(getInsCode(data.client_id, data.first_post_id, 'pull-right', 'width:' + width + 'px; margin-left:30px;', type));
  64.                                 (adsbygoogle = window.adsbygoogle || []).push({});
  65.                                 break;
  66.  
  67.                             default:
  68.                                 break;
  69.                         }
  70.                         loaded = true;
  71.             }
  72.                     })
  73.             })
  74.  
  75.  
  76.  
  77.         function getInsCode(clientId, dataId, customClass, style, format) {
  78.             var ad = '<ins class="adsbygoogle ' + customClass + '" style="display:block; margin-bottom:15px;' + style + ' " data-ad-format="' + format + '" data-ad-client="ca-' + clientId + '" data-ad-slot="' + dataId + '"></ins>';
  79.             return ad;
  80.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement