gitbook-plugin-adsense
Advanced tools
Comparing version 0.0.4 to 0.0.5
require(["gitbook"], function(gitbook) { | ||
var config = config.adsense | ||
, adInsertPoint = document.querySelector('.page-inner section') | ||
, adsByGoogleScript | ||
var adInsertPoint = '.page-inner section' | ||
, ad | ||
; | ||
gitbook.events.bind("start", function(e, config) { | ||
gitbook.events.bind("start", function(e, cnf) { | ||
var config = cnf.adsense | ||
, adsByGoogleScript | ||
; | ||
// Use custom insert point if defined | ||
if (config.element) { | ||
adInsertPoint = config.element; | ||
} | ||
// Inject script to head. | ||
@@ -15,4 +22,3 @@ adsByGoogleScript = document.createElement('script'); | ||
// Generate <ins> | ||
// Generate <ins> (ad) | ||
ad = document.createElement('ins'); | ||
@@ -24,12 +30,15 @@ ad.style = 'display: block'; | ||
ad.setAttribute('data-ad-format', config.format); | ||
adInsertPoint.appendChild(ad); | ||
// Add the ad to the DOM | ||
document.querySelector(adInsertPoint).appendChild(ad); | ||
(adsbygoogle = window.adsbygoogle || []).push({}); | ||
}); | ||
// I insert ad again when switching pages | ||
gitbook.events.bind("page.change", function() { | ||
if (ad) { | ||
adInsertPoint.appendChild(ad); | ||
document.querySelector(adInsertPoint).appendChild(ad); | ||
} | ||
}); | ||
}); |
@@ -5,3 +5,3 @@ { | ||
"main": "index.js", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"engines": { | ||
@@ -35,2 +35,7 @@ "gitbook": ">=2.5.1" | ||
"required": true | ||
}, | ||
"element": { | ||
"type": "string", | ||
"title": "Element to append the ad to", | ||
"required": false | ||
} | ||
@@ -37,0 +42,0 @@ } |
14735
43