PageSourceSearch

https://www.coachhirecomparison.co.uk/_assets/js/plugins/jquery.userProfile.js?v08100739

js coachhirecomparison.co.uk collected 2026-10-08 18:39:48 UTC 5,744 bytes, 189 lines download raw bytes

1(function ($) {
2    $.fn.userProfile = function (options) {
3        // support multiple elements
4        if (this.length > 1) {
5            this.each(function () {
6                $(this).userProfile(options);
7            });
8            return this;
9        }
10
11        var theSelector = $(this);
12        var thisInstance = this;
13
14        // private variables
15        var settings = $.extend(
16            {
17                class: "",
18            },
19            options
20        );
21
22        var getUserDetails = function () {
23            var def = $.Deferred();
24
25            var theUrl =
26                "/api/me";
27
28            $.ajax({
29                type: "GET",
30                url: theUrl,
31                dataType: "json",
32                encode: true,
33                async: true,
34            })
35                .done(function (data) {
36                    theSelector.find('.user-name').text(data.profile.name);
37                    theSelector.find('.user-email').text(data.profile.email);
38
39                    if (data.authenticatedAs?.admin) {
40                        if (data.authenticatedAs) {
41                            if (data.authenticatedAs.type != data.profile.type || data.authenticatedAs.id != data.profile.id) {
42                                theSelector.find('.bottom-bit ul').prepend(
43                                    $("<li>", {
44                                        html: "<a href='/auth/switch_back'>Switch back</a>"
45                                    })
46                                )
47                            }
48                        }
49
50                        theSelector.find('.bottom-bit ul').prepend(
51                            $("<li>", {
52                                html: "<a href='/admin/switch_operator'>Switch operator</a>"
53                            })
54                        )
55                    }
56
57                    def.resolve();
58                })
59                .fail(function (e) {
60                    console.dir(e);
61                    def.reject(e.statusText);
62                });
63
64            return def.promise();
65        };
66
67        var whenNoCookie = function () {
68            theSelector.before(
69                $("<li>", {
70                    class: "nav__item nav__item--main",
71                    html: '<a href="/how-it-works" class="nav__link nav__link--main">How it works</a>'
72                })
73            );
74
75            theSelector.before(
76                $("<li>", {
77                    class: "nav__item nav__item--main",
78                    html: '<a href="/about-us" class="nav__link nav__link--main">Our story</a>'
79                })
80            );
81
82            theSelector.before(
83                $("<li>", {
84                    class: "nav__item nav__item--main margin-right-0",
85                    html: '<a href="/blog" class="nav__link nav__link--main">Blog</a>'
86                })
87            );
88        }
89
90        var whenCookie = function () {
91            var container = $("<div>", {
92                class: "user-profile border-rounded border-grey relative"
93            });
94
95            theSelector.append(container);
96
97            var topBit = $("<div>", {
98                class: "top-bit text-purple font-14px padding-left-10 flex padding-15"
99            });
100
101            var bottomBit = $("<div>", {
102                class: "bottom-bit bg-purple padding-15 hidden absolute left-0 top-100 w-100",
103                html: '<ul class="padding-left-0"></ul>'
104            });
105
106            container.append(topBit);
107            container.append(bottomBit);
108
109            topBit.append(
110                $("<div>", {
111                    class: "bg-purple border-rounded-50 size-40 profile-image"
112                })
113            );
114
115            var contactDetails = $("<div>", {
116                class: "text-purple font-14px padding-left-10"
117            });
118
119            topBit.append(contactDetails);
120
121            contactDetails.append(
122                $("<div>", {
123                    class: "text-bold user-name",
124                    text: ""
125                })
126            );
127
128            contactDetails.append(
129                $("<div>", {
130                    class: "some-class user-email",
131                    text: ""
132                })
133            );
134
135            topBit.append(
136                $("<div>", {
137                    class: "margin-left-10 expand-container",
138                    html: "<div class='action expand'></div>"
139                })
140            );
141
142            bottomBit.find('ul').append(
143                $("<li>", {
144                    html: "<a href='/dashboard'>Dashboard</a>"
145                })
146            );
147
148            bottomBit.find('ul').append(
149                $("<li>", {
150                    html: "<a href='/logout'>Log out</a>"
151                })
152            );
153
154            theSelector.show();
155
156            getUserDetails();
157
158            theSelector.find('.top-bit').on('click', function (e) {
159                if ($(e.target).hasClass('top-bit')) {
160                    t = $(e.target).find('.action');
161                } else {
162                    t = $(e.target).closest('.top-bit').find('.action');
163                }
164
165                t.toggleClass('expand collapse');
166                theSelector.find('.bottom-bit').toggleClass('hidden', t.hasClass('expand'));
167            })
168        }
169
170        this.initialize = function (options) {
171            var def = $.Deferred();
172
173            theSelector.empty();
174            theSelector.off();
175
176            if (document.cookie.indexOf("chc_auth_token") < 0) {
177                whenNoCookie();
178            } else {
179                whenCookie();
180            }
181
182            def.resolve();
183
184            return def.promise();
185        };
186
187        return this;
188    };
189})(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.