PageSourceSearch

https://www.rhulstudentpad.co.uk/Javascript/Final.js?f_ver=105_10

js rhulstudentpad.co.uk collected 2026-10-07 22:20:37 UTC 18,031 bytes, 488 lines download raw bytes

1let _currentPath = location.pathname.toLowerCase();
2
3if (document.readyState === "loading") {
4    document.addEventListener("DOMContentLoaded", finalJSDocReady);
5} else {
6    finalJSDocReady(200); // add delay to ensure its last to run 
7}
8
9function finalJSDocReady() {
10    log("final document ready")
11    $("html").addClass("fsj-doc-ready");
12
13    $("#waitDialog").dialog({ autoOpen: false, draggable: false, resizable: false, dialogClass: "waitCursor" });
14
15    //$("iframe").attr("credentialless", "true");
16
17    // notification checks, when doc ready
18    if (g_notifications && supportsPushNotifications()) {
19        if (g_notifications_enabled) {
20            var tokenValid = getStorage("pushTokenValid"); //saved for 2 minutes so we can keep tokens fresh and update last active in db
21            if (tokenValid == null || tokenValid == "" || tokenValid == undefined) {
22                requestNotificationPermission();
23            }
24        } else {
25            log("notifications have not been enabled yet");
26            if (!g_notifications_blocked) {
27                togglePushBanner("show");
28            }
29        }
30    }
31
32    if (!isPWA()) {
33        if (g_installAppBanner) {
34            togglePWABanner("show");
35        }
36    }
37    checkLogInOutButton();
38    setHMFFrameSize(); // set on load
39}
40
41
42$(window).load(function () {
43    log("final window load");
44    $("html").addClass("fsj-window-loaded");
45    checkLogInOutButton();
46    setHMFFrameSize(); // set on load
47    //showHMFPromotionPopup();
48    window.setTimeout(function () { appBarAmendments() }, 500); // .5s delay to allow some external content to load
49});
50
51function checkLogInOutButton(delay) {
52
53    delay = delay || 0;
54
55    setTimeout(function () {
56
57        if (g_theme != '') {
58
59            // update login box
60            if ($("body.logged_in").length > 0) {
61
62                // we are logged in so lets check if a nav menu exists for the account page 
63                if ($("#navigationFull a[href*='tudent'],#navigationFull a[href*='user'],#navigationFull a[href*='enant']").length == 0) {
64                    // no nav menu so lets update the login box to an account page link
65                    $("body.logged_in li.hlogin a").attr("onclick", "window.location.href='" + g_students_url + "'");
66                    $("body.logged_in li.hlogin a span").text("Account");
67                } else {
68                    // we have a nav menu so lets update the login box
69                    $("body.logged_in li.hlogin a").attr("onclick", "logout()").removeAttr("href").css("cursor", "pointer");
70                    $("body.logged_in li.hlogin a span").text("Logout");
71                    $("body.logged_in li.hlogin a em").removeClass("fa-user").addClass("fa-sign-out");
72                }
73            }
74
75        }
76
77    }, delay);
78}
79
80let deferredPrompt = null;
81
82//app bar functions
83function setActiveMobileBarNavItem(element) {
84    var items = document.querySelectorAll('.app-bar-item');
85    items.forEach(function (item) {
86        item.classList.remove('active');
87    });
88    element.classList.add('active');
89
90    var targetName = element.getAttribute('data-target');
91    log("Navigated to: " + targetName);
92
93    switch (targetName) {
94        case "Properties":
95            navigateToURL("/Accommodation");
96            break;
97        case "House Mate Finder":
98            navigateToURL("/HMF/Home"); 
99            break;
100        case "Chats":
101            navigateToURL("/HMF/Conversations");
102            break;
103        case "Settings":
104            navigateToURL(g_students_url);
105            break;
106        case "My Profile":
107            navigateToURL("/HMF/editprofile");
108            break;
109    }
110
111
112}
113
114if (g_showAppBar) {
115
116    
117    $("body").attr("data-ahmfp","");
118    //add a resize event for hmf pages with iframes to resize the iframe to fit the content
119    if (_currentPath.startsWith("/hmf/")) {
120        $(window).resize(function () { waitForFinalEvent(function () { setHMFFrameSize() }, 1, "chkiFrameSize"); });
121    }
122
123    switch (_currentPath) {
124
125        case "/": case "/accommodation": case "/home":
126            $('.app-bar-item[data-target="Properties"]').addClass('active');
127            break;  
128
129        case "/hmf/home":
130            $('.app-bar-item[data-target="House Mate Finder"]').addClass('active');
131            $("body").attr("data-ahmfp", "HMF");
132            break;
133
134        case "/hmf/conversations":
135            $('.app-bar-item[data-target="Chats"]').addClass('active');
136            $("body").attr("data-ahmfp", "Chat");
137            break;
138
139        case "/hmf/editprofile":
140            $('.app-bar-item[data-target="My Profile"]').addClass('active');
141            $("body").attr("data-ahmfp", "Profile");
142            break;
143
144        case "/students":
145        case "/users":
146        case "/tenants":
147            $('.app-bar-item[data-target="Settings"]').addClass('active');
148            break;
149
150        default:
151            switch (true) {
152                case _currentPath.startsWith("/searchresults/"):
153                case _currentPath.startsWith("/property/"):
154                case _currentPath.startsWith("/advert/"):
155                    $('.app-bar-item[data-target="Properties"]').addClass('active');
156                    break;
157
158                case _currentPath.startsWith("/students/"):
159                case _currentPath.startsWith("/users/"):
160                case _currentPath.startsWith("/tenants/"):
161                    $('.app-bar-item[data-target="Settings"]').addClass('active');
162                    break;
163            }
164            break;
165    }
166}
167
168function setHMFFrameSize(pageName, container, adjustment) {
169    if (_currentPath.startsWith("/hmf/") || _currentPath == "/hmf") {
170
171        pageName = pageName || "#pageBody.itg_HMF";
172        container = container || "#itg_HMF";
173        adjustment = adjustment || 0;
174
175        let _currentInnerHeight = window.innerHeight;
176        let _usedAppBarHeight = g_appBarHeight;
177        if (isMobile) {
178            _currentInnerHeight -= _mobileTopBarHeight;   
179        } else {
180            _currentInnerHeight -= $("#banner").first().height();
181            _usedAppBarHeight = 0;
182        }         
183        $(container).height(_currentInnerHeight - _usedAppBarHeight - adjustment);
184        $(pageName + " #pageHolder").css("min-height", _currentInnerHeight);
185    }
186}
187
188function setActiveAppBarItemByiFrame(passedUrl) {
189
190    let checkUrl = passedUrl || g_currentHMFUrl;
191
192    $('.app-bar-item.active').removeClass('active');
193    switch (true) {
194        case checkUrl.toLowerCase().indexOf("/conversation") > -1: 
195            $('.app-bar-item[data-target="Chats"]').addClass('active');
196            $("body").attr("data-ahmfp", "Chat");
197            break;
198
199        case checkUrl.toLowerCase().indexOf("housematematch") > -1:
200            $('.app-bar-item[data-target="House Mate Finder"]').addClass('active');
201            $("body").attr("data-ahmfp", "HMF");
202            break;
203
204        case checkUrl.toLowerCase().indexOf("aboutme") > -1:
205        case checkUrl.toLowerCase().indexOf("mypreferences") > -1:
206        case checkUrl.toLowerCase().indexOf("additionalinformation") > -1:
207        case checkUrl.toLowerCase().indexOf("currentsituation") > -1:
208        case checkUrl.toLowerCase().indexOf("aboutyourproperty") > -1:
209        case checkUrl.toLowerCase().indexOf("housepreferences") > -1:
210        case checkUrl.toLowerCase().indexOf("uploadpropertyimages") > -1:
211        case checkUrl.toLowerCase().indexOf("mypropertypreferences") > -1:
212            $('.app-bar-item[data-target="My Profile"]').addClass('active');
213            $("body").attr("data-ahmfp", "Profile");
214            break;
215
216        default: // default to HMF
217            $('.app-bar-item[data-target="House Mate Finder"]').addClass('active');
218            $("body").attr("data-ahmfp", "HMF");
219            break;
220    }
221}
222
223function updateAppBarChatCount(count) {
224    if (count != undefined && count != null && count > 0) {
225        log("Updating unread chat count to:", count);
226        $('.app-bar-item[data-target="Chats"]').attr("data-notification", count);
227    }
228}
229
230function checkUserHMFStatus() {
231    if (!g_currentHMFComplete) {
232        wsAccount.checkUserHMFStatus(function (response) {
233            g_currentHMFComplete = response;
234        });
235    }
236}
237
238function navigateToURL(url) {
239    if (url == undefined || url == null || url == "") {
240        return;
241    }
242    if (url.startsWith("http://") || url.startsWith("https://")) {
243        if (window.location.href.toLowerCase() !== url.toLowerCase()) {
244            window.location.href = url;
245        }
246    } else if (url.startsWith("/")) {
247
248        let nonHMFPaths = ["/accommodation", "/home", "/students", "/users", "/tenants"];
249
250        //lets check if iframe is already loaded 
251        if ($("#itg_HMF").length > 0 && g_currentHMFComplete && !nonHMFPaths.includes(url.toLowerCase())) {
252            var hmfiframe = document.getElementById("itg_HMF");
253            var tURL = hmfURLTranslate(url);
254            hmfiframe.contentWindow.postMessage({
255                type: "navigate",
256                url: tURL
257            }, g_hmf_url_base);
258
259            // if we are on mobile and the menu is open, close it on navigation to a new page
260            if (isMobile) {
261                if ($("#mob-menu-sub").hasClass("active")) {
262                    toggleMobileNavigationView($("#mob-menu-sub")[0]);
263                    setActiveAppBarItemByiFrame(tURL);
264                }
265            }
266
267        } else {
268            // default check 
269            if (_currentPath !== url.toLowerCase()) {
270                window.location.href = url;
271            }
272        }
273    }
274}
275
276function hmfURLTranslate(url) {
277    switch (url.toLowerCase()) {
278        case "/hmf/home":
279            $("body").attr("data-ahmfp", "HMF");
280            return "/HousemateMatches";
281        case "/hmf/conversations":
282            $("body").attr("data-ahmfp", "Chat");
283            return "/ConversationBoard";
284        case "/hmf/editprofile":
285            $("body").attr("data-ahmfp", "Profile");
286            return "/MyPreferences";
287        default:
288            return "/Login";
289    }
290}
291
292// INSTALL AS WEB APP BANNER/PROMPT
293if (g_notifications) {
294
295    if (!isPWA()) {
296        if (g_installAppBanner) {
297            window.addEventListener("beforeinstallprompt", (event) => {
298                event.preventDefault(); // Prevent automatic prompt
299                deferredPrompt = event; // Store event for later use
300
301                // Show a custom install prompt
302                const installBanner = document.getElementById("PWANotificationsPrompt");
303                const installText = document.getElementById("installText");
304
305                // Set any browser specific text 
306                switch (browser.os) {
307                    case "iOS":
308                        if (browser.browser == "Safari" && supportsPushNotifications()) {
309                            installText.innerHTML = "Install " + g_software_type_name + " as an app on your " + browser.device + " to receive push notifications";
310                        } else {
311                            installText.innerHTML = "Install " + g_software_type_name + " as an app on your " + browser.device;
312                        }
313                        break;
314
315                    case "Android": case "macOS":
316                        installText.innerHTML = "Install " + g_software_type_name + " as an app on your " + browser.device;
317                        break;
318
319                }
320                g_installAppBannerVisible = true;
321                $("#PWANotificationsPrompt").show();
322                installBanner.style.zIndex = "99999";
323            });
324
325            window.addEventListener("appinstalled", () => {
326                log("PWA installed successfully!");
327                setStorage("Hide_PWA_Install_Prompt", true, 525600); // hide for 1 Year
328                togglePWABanner("hide");
329            });
330
331        }
332    }
333
334    // check to see if push notifications are not supported, if not remove the notifications tiles etc
335    if (!supportsPushNotifications()) {
336
337        // hide anything with the push-notifications class
338        $(".push-notifications").remove();
339
340    }
341
342}
343
344function togglePWABanner(forceState) {
345    if (getStorage("Hide_PWA_Install_Prompt") != 'true') {
346        let showNotificationPrompt = true;
347        if (!isPWA() && browser.os == "iOS" && browser.browser == "Safari" && supportsPushNotifications()) {
348            showNotificationPrompt = false; // on iOS Safari we will show the PWA install prompt first as its required for push notifications to work
349        }
350        if (showNotificationPrompt) {
351            if (forceState != undefined) {
352                if (forceState === "show") {
353                    $("#PWANotificationsPrompt").show();
354                } else {
355                    $("#PWANotificationsPrompt").hide();
356                }
357            } else {
358                if (!$("#PWANotificationsPrompt:visible")[0]) {
359                    $("#PWANotificationsPrompt").show();
360                } else {
361                    $("#PWANotificationsPrompt").hide();
362                }
363            }
364        }
365    } else {
366        $("#PWANotificationsPrompt").hide();
367    }
368
369}
370function togglePushBanner(forceState) {
371    if (getStorage("Hide_Push_Notifications_Prompt") != g_user_public_id) {
372        if (forceState != undefined) {
373            if (forceState === "show") {
374                $("#pushNotificationsPrompt").show();
375            } else {
376                $("#pushNotificationsPrompt").hide();
377            }
378        } else {
379            if (!$("#pushNotificationsPrompt:visible")[0]) {
380                $("#pushNotificationsPrompt").show();
381            } 
382        }
383    } else {
384        $("#pushNotificationsPrompt").hide();
385    }
386
387}
388
389function promptPWAInstall() {
390    if (browser.os == "iOS" || browser.os == "macOS") {
391        $("#iOSInstallationPrompt").show();
392        dismissPWAPrompt(); // hide the PWA banner as we are showing the iOS instructions
393        return;
394    }
395
396    if (deferredPrompt) {
397        deferredPrompt.prompt();
398        deferredPrompt.userChoice.then((choiceResult) => {
399            if (choiceResult.outcome === "accepted") {
400                log("User accepted the PWA install");
401                deferredPrompt = null; // Reset
402            } else {
403                log("User dismissed the PWA install");
404            }
405        });
406    }
407}
408
409function dismissManualInstallPrompt() {
410    $("#iOSInstallationPrompt").hide();
411}
412function dismissNotificationPrompt() {
413    togglePushBanner("hide");
414    setStorage("Hide_Push_Notifications_Prompt", g_user_public_id, 10080); // hide for 7 days
415}
416function requestNotificationPrompt() {
417    togglePushBanner("hide");
418
419    g_notification_devices.push(g_push_device_id); // add current device to list of devices to request permission for
420
421    requestNotificationPermission();
422
423}
424
425function dismissPWAPrompt() {
426    togglePWABanner("hide");
427    setStorage("Hide_PWA_Install_Prompt", true, 10080); // hide for 7 days
428}
429
430
431function deleteHMFProfile() {
432    popupAlert(`
433    <p>You are about to delete your housemate finder profile, this action cannot be undone. </p>
434    <p>When you delete your profile you will be removed from all current conversations and lose access to the chat area.</p>
435    <p>Are you sure you want to continue?</p>
436    <div class="popup-buttons">
437        <a class="action" onclick="deleteHMFProfile_confirm();">Yes, delete my profile</a>
438        <a class="action" onclick="$('.ui-dialog-titlebar-close').click();">Cancel</a>
439    </div>
440    `, undefined, undefined, true, undefined, "Confirmation Required", "hmf-terms-popup solid-colour-popup red", '600px');
441}
442
443function deleteHMFProfile_confirm() {
444    $('.ui-dialog-titlebar-close').click();
445    showWaitCursor({ message: "Removing House Mate Finder Profile..." });
446
447    wsAccount.deleteHMFProfile(function (response) {
448        hideWaitCursor();
449        if (response) {
450            popupAlert(`<p>Your housemate finder profile has been deleted.</p>`, "refresh", undefined, true, undefined, "Profile Deleted", "hmf-terms-popup solid-colour-popup", '600px');
451        } else {
452            popupAlert(`<p>There was an error deleting your housemate finder profile, please try again later.</p>`, undefined, undefined, true, undefined, "Error", "hmf-terms-popup solid-colour-popup red", '600px');
453        }
454    })
455
456}
457
458function showHMFPromotionPopup() {
459    if (g_cookies_set > 0 && g_cookies_performance > 0) {
460        if (g_hmf_url_base.length > 10) {
461            if (isMobile) {
462                popupOnce("HMF_Notice_Mobile", "Housemate Finder", "<a href='/HMF/Home'><img src='/global%20media/images/HMF_Popup_Mobile.webp' width='343' height='400'/></a>", 343, "img-ono-popup solid-colour-popup r10", 10080, true, 0.5);
463            } else {
464                popupOnce("HMF_Notice_Desktop", "Housemate Finder", "<a href='/HMF/Home'><img src='/global%20media/images/HMF_Popup_Desktop.webp' width='500' height='400'/></a>", 500, "img-ono-popup solid-colour-popup r10", 10080, true, 0.5);
465            }
466        }
467    }
468}
469
470function appBarAmendments() {
471    if (typeof Tawk_API !== "undefined") {
472        moveTawkTo();
473    }
474}
475
476let _moveTawkTo = 0;
477function moveTawkTo() {
478    if (isMobile) {
479        if (_moveTawkTo < 5) {
480            if ($("iframe[title='Chat widget']")[0]) {
481                $("iframe[title='Chat widget']").css("bottom", "70px");
482            } else {
483                _moveTawkTo++;
484                window.setTimeout(function () { moveTawkTo() }, 500);
485            }
486        }
487    }
488}

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.