PageSourceSearch

https://www.umb.edu/media/umassboston/site-assets/javascript/emergency.js

js umb.edu collected 2026-09-24 08:27:03 UTC 9,568 bytes, 168 lines download raw bytes

1/**
2 * Emergency Notice Module
3 * version 1.1
4 */
5var EmergencyNotices;
6(function ($) {
7    EmergencyNotices = {
8        setCookie: function (cname, cvalue, exdays) {
9            var d = new Date();
10            d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
11            var expires = "expires=" + d.toUTCString();
12            document.cookie = cname + "=" + cvalue + "; " + expires + ";" + "path=/";
13        },
14        getCookie: function (cname) {
15            var name = cname + "=";
16            var ca = document.cookie.split(';');
17            for (var i = 0; i < ca.length; i++) {
18                var c = ca[i];
19                while (c.charAt(0) == ' ') c = c.substring(1);
20                if (c.indexOf(name) != -1) return c.substring(name.length, c.length);
21            }
22            return "";
23        },
24        init: function (attrs) {
25
26            var $this = this;
27            //Path of the JSON file with the Related Content Navigation Object
28            var url = typeof attrs !== 'undefined' && typeof attrs.url !== 'undefined' ? attrs.url : $('[data-t4-emergency-notices]').data('t4-emergency-notices');
29            var mainContainerClass = typeof attrs !== 'undefined' && typeof attrs.mainContainerClass !== 'undefined' ? attrs.mainContainerClass : '[data-t4-emergency-notices]';
30            var singleNoticeClass = typeof attrs !== 'undefined' && typeof attrs.singleNoticeClass !== 'undefined' ? attrs.singleNoticeClass : '[data-t4-emergency-notices] [data-id]';
31            var closeButtonClass = typeof attrs !== 'undefined' && typeof attrs.closeButtonClass !== 'undefined' ? attrs.closeButtonClass : '[data-close]';
32            var closedClass = typeof attrs !== 'undefined' && typeof attrs.closedClass !== 'undefined' ? attrs.closedClass : 'closed';
33
34            var EmCookieSet = $this.getCookie('emergency').split(',');
35            var random = Math.floor(Math.random() * (1 - 1000 + 1) + 1);
36            var checkBanner = $.getJSON((url.indexOf("?") >= 0 ? url : url + '?ver=' + random), function (data) {
37                // Ignore dummy element
38                let idsInUse = {};
39                let noticesClean = {};
40                if (data.notices.length > 1) {
41                    for (i = 0; i < data.notices.length - 1; i++) {
42                        if (Object.keys(idsInUse).indexOf(data.notices[i].id) > -1) {
43                            let publishDateNotice = new Date(data.notices[i].publishDate);
44                            let expireDateNotice = new Date(data.notices[i].expireDate);
45
46                            if ((!isNaN(publishDateNotice) && new Date() >= publishDateNotice && !isNaN(expireDateNotice) && new Date() < expireDateNotice)) {
47                                idsInUse[data.notices[i].id] = i;
48                            }
49                        } else {
50                            idsInUse[data.notices[i].id] = i;
51                        }
52                    }
53                }
54
55                if (data.notices.length > 1) {
56                    // Iterate over each notice in the JSON
57                    for (i = 0; i < data.notices.length - 1; i++) {
58
59                        if (Object.values(idsInUse).indexOf(i) === -1) {
60                            continue;
61                        }
62
63                        // Create an array containing the IDs of all the notices already output on the page
64                        var noticesOnPage = $(singleNoticeClass + '[data-id]').map(function () {
65                            return $.map($(this).data(), function (v, k) {
66                                if (k == 'id') {
67                                    return v.toString();
68                                }
69                            });
70                        }).get();
71
72                        // Checks if the notice is in the cookie
73                        var noticeInCookie = ($.inArray(data.notices[i].id + '>>' + data.notices[i].version , EmCookieSet) < 0) ? false : true;
74                        // Checks if notice is already on the page
75                        var noticeOnPage = ($.inArray(data.notices[i].id, noticesOnPage) < 0) ? false : true;
76                        // Checks if notice is of type 'emergency;
77                        var isEmergency = (data.notices[i].noticetype == 'Emergency') ? true : false;
78
79                        if (noticeOnPage) {
80                            if (noticeOnPage && $(singleNoticeClass + '[data-id="' + data.notices[i].id + '"]').data('version') != data.notices[i].version) {
81                                $(singleNoticeClass + '[data-id="' + data.notices[i].id + '"]').remove();
82                                noticeOnPage = false;
83                            } else {
84                                let publishDate = new Date($(singleNoticeClass + '[data-id="' + data.notices[i].id + '"]').data('publishDate'));
85                                let expireDate = new Date($(singleNoticeClass + '[data-id="' + data.notices[i].id + '"]').data('expireDate'));
86                                let publishDateNotice = new Date(data.notices[i].publishDate);
87                                let expireDateNotice = new Date(data.notices[i].expireDate);
88                                if (!isNaN(publishDate) && new Date() < publishDate) {
89                                    $(singleNoticeClass + '[data-id="' + data.notices[i].id + '"]').remove();
90                                    noticeOnPage = false;
91                                } else if (!isNaN(publishDateNotice) && new Date() < publishDateNotice) {
92                                    $(singleNoticeClass + '[data-id="' + data.notices[i].id + '"]').remove();
93                                    noticeOnPage = false;
94                                } else if (!isNaN(expireDate) && new Date() >= expireDate) {
95                                    $(singleNoticeClass + '[data-id="' + data.notices[i].id + '"]').remove();
96                                    noticeOnPage = false;
97                                } else if (!isNaN(expireDateNotice) && new Date() >= expireDateNotice) {
98                                    $(singleNoticeClass + '[data-id="' + data.notices[i].id + '"]').remove();
99                                    noticeOnPage = false;
100                                }
101                            }
102                        }
103
104                        // Output the notice only if:
105                        // this notice is not in the cookie and is not on the page OR
106                        // the notice is in the cookie AND not on the page already but is also an Emergency notice
107                        if ((!noticeInCookie && !noticeOnPage) || (noticeInCookie && !noticeOnPage && isEmergency)) {
108                            
109                            let publishDateNotice = new Date(data.notices[i].publishDate);
110                            let expireDateNotice = new Date(data.notices[i].expireDate);
111                            
112                            if (!isNaN(publishDateNotice) && new Date() < publishDateNotice) {
113                                continue;
114                            } else if (!isNaN(expireDateNotice) && new Date() > expireDateNotice) {
115                                continue;
116                            }
117                            $(mainContainerClass).append(data.notices[i].html);
118
119                            // Remove ability to dismiss "Emergency" notices
120                            if (isEmergency) {
121                                $(closeButtonClass + '[data-close="' + data.notices[i].id + '"]').remove();
122                            }
123                            
124                        }
125
126                    }
127
128                    // Hide notices on click
129                    $(singleNoticeClass + ' ' + closeButtonClass).on('click', function () {
130                        var thisId = $(this).parents('[data-id]').attr('data-id');
131                        var thisVer = $(this).parents('[data-id]').attr('data-version');
132                        var parentNotice = $(this).parents(singleNoticeClass).slideUp(300).addClass(closedClass);
133
134                        // Double checks notice type before addign to cookie
135                        if (!parentNotice.hasClass('emergency')) {
136                            var currentCookie = $this.getCookie('emergency');
137
138                            if (currentCookie == '') {
139                                $this.setCookie('emergency', thisId + '>>' + thisVer, 1);
140                            } else {
141                                var cookieArray = currentCookie.split(',');
142                                if ($.inArray(thisId + '>>' + thisVer, cookieArray) < 0) {
143                                    $this.setCookie('emergency', currentCookie + ',' + thisId + '>>' + thisVer, 1);
144                                }
145                            }
146                        }
147                    });
148                }
149            }).fail(function () {
150                console.error("Failed to get emergency notice JSON File");
151            })
152
153            
154            setTimeout(function () {
155                $this.init(attrs);
156            }, 10000); // Modify this number to change how often the json file is polled
157        }
158    }
159
160
161    /** Emergency Notices **/
162    // Cookie Functions
163
164    if ($('[data-t4-emergency-notices]').length) {
165        EmergencyNotices.init({});
166    }
167
168})(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.