PageSourceSearch

https://www.natureetverger.fr/js/design/facebook/jquery.fblogin.js

js natureetverger.fr collected 2026-10-01 16:14:20 UTC 5,813 bytes, 154 lines download raw bytes

1/**
2 * jquery.fblogin - v1.1.3 (2016-09-14)
3 * https://github.com/ryandrewjohnson/jquery-fblogin
4 * Copyright (c) 2016 Ryan Johnson; Licensed MIT
5 */
6(function ($) {
7    $.extend({
8        /**
9         * fblogin
10         * @property {object}  options      - settings for fblogin plugin.
11         *
12         * Required:
13         * options.fbId         {string}    - the Facebook app id
14         *
15         * Optional:
16         * options.permissions  {string}    - a comma seperated list of FB permissions. See http://bit.ly/1plqJSs
17         * options.fields       {string}    - a comma seperated list of field ids. See http://bit.ly/1plrevO
18         * options.success      {function}  - callback that will be triggered when data is successfully returned from FB.
19         * options.error        {function}  - callback that will be triggered by any errors.
20         * options.rerequest        {bool}
21         */
22        fblogin: function (options) {
23
24            /**
25             * Private Props
26             * @property {object}  __               - add private module functions here.
27             * @property {object}  isSdkLoaded      - a flag for when the FB SDK has loaded.
28             * @property {object}  isFbInitiated    - a flag for when FB.init has been called.
29             * @property {object}  $dfd             - stores an instance of jquery Deferred.
30             */
31            var __,
32                isSdkLoaded,
33                isFbInitiated,
34                $dfd;
35
36            options = options || {};
37            isSdkLoaded = false;
38            isFbInitiated = false;
39            $dfd = $.Deferred();
40
41            // PRIVATE FUNCTIONS
42            __ = {
43                init: function () {
44                    // FB ID is required
45                    if (!options.fbId) {
46                        throw new Error('Required option "fbId" is missing!');
47                    }
48
49                    options.permissions = options.permissions || '';
50                    options.fields = options.fields || '';
51                    options.success = options.success || function () {
52                        };
53                    options.error = options.error || function () {
54                        };
55                    options.rerequest = options.rerequest || false;
56
57                    __.listenForFbAsync();
58                },
59                listenForFbAsync: function () {
60                    if (window.fbAsyncInit) {
61                        var notMyFunction = window.fbAsyncInit;
62                    }
63                    // listen for FB SDK load
64                    window.fbAsyncInit = function () {
65                        __.initFB();
66                        isSdkLoaded = true;
67                        if (notMyFunction) {
68                            notMyFunction();
69                        }
70                    };
71
72                    if (isSdkLoaded || window.FB) {
73                        window.fbAsyncInit();
74                        return;
75                    }
76                },
77                initFB: function () {
78                    if (!isFbInitiated) {
79                        window.FB.init({
80                            appId: options.fbId,
81                            cookie: true,
82                            xfbml: true,
83                            version: 'v2.7'
84                        });
85
86                        isFbInitiated = true;
87                    }
88
89                    $dfd.notify({status: 'init.fblogin'});
90                },
91                loginToFB: function () {
92                    var paramLogin = {
93                        scope: options.permissions,
94                        return_scopes: true,
95                        auth_type: 'rerequest'
96                    };
97
98                    window.FB.login(function (response) {
99                        if (response.authResponse) {
100
101                            $dfd.notify({
102                                status: 'authenticate.fblogin',
103                                data: response
104                            });
105
106                        } else {
107                            // mimic facebook sdk error format
108                            $dfd.reject({
109                                error: {
110                                    message: 'User cancelled login or did not fully authorize.'
111                                }
112                            });
113                        }
114                    }, paramLogin);
115                },
116                getFbFields: function (accessToken) {
117                    window.FB.api('/me', {fields: options.fields}, function (response) {
118                        if (response && !response.error) {
119                            $dfd.resolve(response);
120                        }
121                        else {
122                            $dfd.reject(response);
123                        }
124                    });
125                }
126            };
127
128            // This monitors the FB login progresssion
129            // 1. Init FB
130            // 2. FB.login
131            // 3. Get user data
132            $dfd.progress(function (response) {
133                if (response.status === 'init.fblogin') {
134                    __.loginToFB();
135                } else if (response.status === 'authenticate.fblogin') {
136                    __.getFbFields(response.data.authResponse.accessToken);
137                } else {
138                    dfd.reject();
139                }
140            });
141
142            // point callbacks at deffereds
143            $dfd.done(options.success);
144            $dfd.fail(options.error);
145
146            // here we go!
147            __.init();
148
149            return $dfd;
150        }
151
152
153    });
154})(jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.