-
Notifications
You must be signed in to change notification settings - Fork 228
/
ngopenfb.js
81 lines (72 loc) · 2.19 KB
/
ngopenfb.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
/**
* Angular wrapper for the OpenFB library
* Allows you to use OpenFB "the Angular way":
* - As an Angular service instead of a global object
* - Using promises instead of callbacks
* @author Christophe Coenraets @ccoenraets
* @version 0.5
*/
angular.module('ngOpenFB', [])
.factory('ngFB', function ($q, $window) {
function init(params) {
return $window.openFB.init(params);
}
function login(options) {
var deferred = $q.defer();
$window.openFB.login(function(result) {
if (result.status === "connected") {
deferred.resolve(result);
} else {
deferred.reject(result);
}
}, options);
return deferred.promise;
}
function logout() {
var deferred = $q.defer();
$window.openFB.logout(function() {
deferred.resolve();
});
return deferred.promise;
}
function api(obj) {
var deferred = $q.defer();
obj.success = function(result) {
deferred.resolve(result);
};
obj.error = function(error) {
deferred.reject(error);
};
$window.openFB.api(obj);
return deferred.promise;
}
function revokePermissions() {
var deferred = $q.defer();
$window.openFB.revokePermissions(
function() {
deferred.resolve();
},
function() {
deferred.reject();
}
);
return deferred.promise;
}
function getLoginStatus() {
var deferred = $q.defer();
$window.openFB.getLoginStatus(
function(result) {
deferred.resolve(result);
}
);
return deferred.promise;
}
return {
init: init,
login: login,
logout: logout,
revokePermissions: revokePermissions,
api: api,
getLoginStatus: getLoginStatus
};
});