PageSourceSearch

https://www.cn.edu/wp-content/plugins/upup-alert-bar/js/upup-alert-bar.js?ver=7.1.2

js cn.edu collected 2026-09-24 08:39:10 UTC 3,619 bytes, 119 lines download raw bytes

1/**
2 * UpupAlertBar
3 * Find alert bar and manage its visibility
4 * Allow the user to dismiss the alert bar
5 * Use localstorage to keep up with what version of the alert bar was dismissed (changes each time settings are saved)
6 * @constructor
7 */
8
9function UpupAlertBar() {
10  this.__construct = function () {
11    // we check a key that changes each time the alert bar gets saved
12    this.storageKey = 'upup-alert-bar-dismissed-key';
13    this.lastActivityKey = 'upup-alert-bar-last-activity';
14    this.dismissedKey = sessionStorage.getItem(this.storageKey);
15    this.refs = {};
16
17    this.discover();
18
19    if (this.refs.alertBar) {
20      this.listen();
21      this.maybeActivate(); // depends on user's local storage
22      // record last activity time - updated with each page visit (wherever this script runs)
23      sessionStorage.setItem(this.lastActivityKey, (new Date().getTime()).toString());
24    }
25  };
26
27  /**
28   * Find the alert bar and associated controls
29   */
30  this.discover = function () {
31    this.refs.alertBar = document.querySelector('.upup-alert-bar');
32
33    if (!this.refs.alertBar) {
34      return;
35    }
36
37    this.refs.dismissButtons = Array.from(this.refs.alertBar.querySelectorAll('.upup-alert-bar__dismiss'));
38  }
39
40  /**
41   * Listen for dismiss buttons
42   */
43  this.listen = function () {
44    this.refs.dismissButtons.forEach(function (button) {
45      button.addEventListener('click', this.handleDismiss.bind(this));
46    }.bind(this));
47  }
48
49  /**
50   * Activate the bar by removing a hidden class
51   */
52  this.maybeActivate = function () {
53    let alertBarUkey = this.refs.alertBar.dataset.ukey,
54      lastActivity = parseInt(sessionStorage.getItem(this.lastActivityKey));
55
56    // user has not dismissed this unique alert or there has been no activity here for 1+ hours
57    if (!this.dismissedKey || this.dismissedKey !== alertBarUkey || Math.abs(lastActivity - new Date().getTime()) / (1000 * 3600) > 1) {
58      this.refs.alertBar.classList.remove('hidden');
59      sessionStorage.removeItem(this.storageKey);
60    }
61  }
62
63  /**
64   * Dismiss the bar by adding a dismissed class
65   * Add the alert bar ukey to the user's localstorage so we can know they dismissed this message
66   * @param e
67   */
68  this.handleDismiss = function (e) {
69    let alertBarUkey = this.refs.alertBar.dataset.ukey;
70    this.refs.alertBar.classList.add('dismissed');
71    const navBar = document.getElementById("site-header")
72    navBar.classList.remove('sticky')
73    navBar.classList.remove('alert-bar')
74    navBar.style.position = "fixed"
75    navBar.style.top = "0"
76    sessionStorage.setItem(this.storageKey, alertBarUkey);
77
78  }
79
80  this.__construct();
81}
82
83new UpupAlertBar();
84
85
86
87const alertBar = document.getElementById("upup-alert-bar")
88
89
90if (alertBar) {
91  const height = alertBar.offsetHeight
92  const navBar = document.getElementById("site-header")
93  navBar.classList.add('alert-bar')
94  if (navBar.classList.contains('alert-bar')) {
95    navBar.style.top = `${height}px`
96  }
97  let sticky = navBar.offsetTop;
98
99  window.onscroll = function () { navBarSticky() };
100
101  function navBarSticky() {
102    if (!alertBar.classList.contains("dismissed")) {
103      if (window.pageYOffset >= sticky) {
104        navBar.classList.add("sticky")
105        navBar.classList.remove('alert-bar')
106        navBar.style.top = "0"
107      } else {
108        navBar.classList.remove("sticky");
109        navBar.classList.add('alert-bar');
110        navBar.style.top = `${height}px`;
111      }
112    } else {
113      navBar.classList.remove("sticky");
114      navBar.classList.remove('alert-bar');
115      navBar.style.top = "0";
116      navBar.style.position = "fixed";
117    }
118  }
119}

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.