-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbackbone.api.adsense.js
More file actions
104 lines (86 loc) · 2.38 KB
/
Copy pathbackbone.api.adsense.js
File metadata and controls
104 lines (86 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/* Backbone API: Adsense
* Source: https://github.com/backbone-api/adsense
*
* Created by Makis Tracend (@tracend)
* Distributed through [Makesites.org](http://makesites.org)
* Released under the [MIT license](http://makesites.org/licenses/MIT)
*/
(function(Backbone, _, $){
window.adsbygoogle = window.adsbygoogle || [];
// load dependencies (assume jQuery is available?)
var async = ( typeof c != "undefined" && !_.isUndefined(c.script) ) ? c.sript : $.getScript;
async("//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js")
var Adsense = new Backbone.Model({
id: 0
});
// namespace
Adsense.Ads = {};
// Support backbone-app (if available)
var View = ( typeof APP != "undefined" && !_.isUndefined( APP.View) ) ? APP.View : Backbone.View;
var Banner = View.extend({
el: ".banner",
options: {
width: 0,
height: 0
},
initialize: function( options ){
this.options.pubID = Adsense.get("id");
this.render();
return View.prototype.initialize.call( this, options );
},
render: function(){
var html = template( this.options );
$(this.el).html( html );
// queue an ad
window.adsbygoogle.push({});
}
});
Adsense.Ads.Banner = Banner;
Adsense.Ads.MediumRect = Banner.extend({
options: {
width: 320,
height: 250
}
});
Adsense.Ads.LargeRect = Banner.extend({
options: {
width: 336,
height: 280
}
});
Adsense.Ads.Leaderboard = Banner.extend({
options: {
width: 728,
height: 90
}
});
Adsense.Ads.WideSkyscraper = Banner.extend({
options: {
width: 160,
height: 600
}
});
Adsense.Ads.Mobile = Banner.extend({
options: {
width: 320,
height: 50
}
});
// Templates
// support mustache syntax
_.templateSettings.interpolate = /\{\{(.+?)\}\}/g;
var template = _.template('<ins class="adsbygoogle" style="display:inline-block;width:{{width}}px;height:{{height}}px" data-ad-client="ca-{{pubID}}" data-ad-slot="{{id}}"></ins>');
// Fallbacks
//APP = window.APP || (APP = { Models: {}, Collections: {}, Views: {} });
if( _.isUndefined(Backbone.API) ) Backbone.API = {};
Backbone.API.Adsense = Adsense;
// alias APP.API
if( typeof APP != "undefined" && (_.isUndefined( APP.API) || _.isUndefined( APP.API.Adsense) ) ){
APP.API = APP.API || {};
APP.API.Adsense = Backbone.API.Adsense;
}
// Shortcut
if(typeof window.Adsense == "undefined"){
window.Adsense = Adsense;
}
})(this.Backbone, this._, this.$);