-
Notifications
You must be signed in to change notification settings - Fork 70
/
FacebookAds.js
122 lines (104 loc) · 3.88 KB
/
FacebookAds.js
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
var argscheck = require('cordova/argscheck'),
exec = require('cordova/exec');
var fbanExport = {};
fbanExport.AD_SIZE = {
SMART_BANNER: 'SMART_BANNER',
BANNER: 'BANNER',
MEDIUM_RECTANGLE: 'MEDIUM_RECTANGLE',
FULL_BANNER: 'FULL_BANNER',
LEADERBOARD: 'LEADERBOARD',
SKYSCRAPER: 'SKYSCRAPER'
};
fbanExport.AD_POSITION = {
NO_CHANGE: 0,
TOP_LEFT: 1,
TOP_CENTER: 2,
TOP_RIGHT: 3,
LEFT: 4,
CENTER: 5,
RIGHT: 6,
BOTTOM_LEFT: 7,
BOTTOM_CENTER: 8,
BOTTOM_RIGHT: 9,
POS_XY: 10
};
/*
* set options:
* {
* adSize: string, // banner type size
* width: integer, // banner width, if set adSize to 'CUSTOM'
* height: integer, // banner height, if set adSize to 'CUSTOM'
* position: integer, // default position
* x: integer, // default X of banner
* y: integer, // default Y of banner
* isTesting: boolean, // if set to true, to receive test ads
* autoShow: boolean, // if set to true, no need call showBanner or showInterstitial
* }
*/
fbanExport.setOptions = function(options, successCallback, failureCallback) {
if(typeof options === 'object') {
cordova.exec( successCallback, failureCallback, 'FacebookAds', 'setOptions', [options] );
} else {
if(typeof failureCallback === 'function') {
failureCallback('options should be specified.');
}
}
};
fbanExport.createBanner = function(args, successCallback, failureCallback) {
var options = {};
if(typeof args === 'object') {
for(var k in args) {
if(k === 'success') { if(args[k] === 'function') successCallback = args[k]; }
else if(k === 'error') { if(args[k] === 'function') failureCallback = args[k]; }
else {
options[k] = args[k];
}
}
} else if(typeof args === 'string') {
options = { adId: args };
}
cordova.exec( successCallback, failureCallback, 'FacebookAds', 'createBanner', [ options ] );
};
fbanExport.removeBanner = function(successCallback, failureCallback) {
cordova.exec( successCallback, failureCallback, 'FacebookAds', 'removeBanner', [] );
};
fbanExport.hideBanner = function(successCallback, failureCallback) {
cordova.exec( successCallback, failureCallback, 'FacebookAds', 'hideBanner', [] );
};
fbanExport.showBanner = function(position, successCallback, failureCallback) {
if(typeof position === 'undefined') position = 0;
cordova.exec( successCallback, failureCallback, 'FacebookAds', 'showBanner', [ position ] );
};
fbanExport.showBannerAtXY = function(x, y, successCallback, failureCallback) {
if(typeof x === 'undefined') x = 0;
if(typeof y === 'undefined') y = 0;
cordova.exec( successCallback, failureCallback, 'FacebookAds', 'showBannerAtXY', [{x:x, y:y}] );
};
fbanExport.prepareInterstitial = function(args, successCallback, failureCallback) {
var options = {};
if(typeof args === 'object') {
for(var k in args) {
if(k === 'success') { if(args[k] === 'function') successCallback = args[k]; }
else if(k === 'error') { if(args[k] === 'function') failureCallback = args[k]; }
else {
options[k] = args[k];
}
}
} else if(typeof args === 'string') {
options = { adId: args };
}
cordova.exec( successCallback, failureCallback, 'FacebookAds', 'prepareInterstitial', [ args ] );
};
fbanExport.showInterstitial = function(successCallback, failureCallback) {
cordova.exec( successCallback, failureCallback, 'FacebookAds', 'showInterstitial', [] );
};
fbanExport.createNativeAd = function(adId, successCallback, failureCallback) {
cordova.exec( successCallback, failureCallback, 'FacebookAds', 'createNativeAd', [adId] );
};
fbanExport.removeNativeAd = function(adId, successCallback, failureCallback) {
cordova.exec( successCallback, failureCallback, 'FacebookAds', 'removeNativeAd', [adId] );
};
fbanExport.setNativeAdClickArea = function(adId, x, y, w, h, successCallback, failureCallback) {
cordova.exec( successCallback, failureCallback, 'FacebookAds', 'setNativeAdClickArea', [adId,x,y,w,h] );
};
module.exports = fbanExport;