-
Notifications
You must be signed in to change notification settings - Fork 0
/
facebook.js
59 lines (52 loc) · 1.27 KB
/
facebook.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
angular.module('facebook', [
]).provider('Facebook', function () {
var lang = 'en_US';
var config = {
version: 'v2.2'
};
var provider = {
lang: function (language) {
if (language) {
lang = language;
return provider;
} else {
return lang;
}
},
config: function (extraConfig) {
if (extraConfig) {
config = angular.extend(config, extraConfig);
return provider;
} else {
return config;
}
},
$get: function (
$q,
$window,
$interval
) {
var deferred = $q.defer();
window.fbAsyncInit = function () {
var promise = $interval(function () {
if ($window.FB) {
$window.FB.init(config);
deferred.resolve($window.FB);
$interval.cancel(promise);
}
}, 100);
}
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = '//connect.facebook.net/' + lang + '/sdk.js';
fjs.parentNode.insertBefore(js, fjs);
}($window.document, 'script', 'facebook-jssdk'));
return {
promise: deferred.promise
};
}
};
return provider;
});