PageSourceSearch

https://www.arboretum.ie/shop/scripts/e-availability-timeout.js

js arboretum.ie collected 2026-09-26 08:32:20 UTC 5,607 bytes, 159 lines download raw bytes

1
2let EATimer;
3
4const eAvailabilityTimeout = () => {
5
6    let pageName = window.location.pathname.substring(window.location.pathname.lastIndexOf('/') + 1);
7
8    let paymentPages = ['quick-order-confirmation.html',
9                        'order-confirmation.html',
10                        'payment-processing.html',
11                        'quick-order-confirmation-account-payment.html',
12                        'quick-order-confirmation',
13                        'order-confirmation',
14                        'payment-processing',
15                        'quick-order-confirmation-account-payment'];
16
17    let disabledOnPages = ['payment-confirmation.html',
18                           'iframe-test-ekashu.html',
19                           'ekashu-result.html',
20                           'payment-confirmation',
21                           'iframe-test-ekashu',
22                           'ekashu-result'];
23
24    // If it looks like we're on a redirect page, don't do anything
25    if (document.getElementsByTagName('body')[0].onload && document.getElementsByTagName('body')[0].onload.toString().includes('location.replace')) {
26        return;
27    }
28
29    // Don't do anything on pages that are in the disabled pages list
30    if (disabledOnPages.includes(pageName)) {
31        return;
32    }
33
34    // Grab the container object
35    let EAContainer = document.getElementById('E-Availability-Timeout-Container');
36
37    // If cookie doesn't exist, don't do anything? Hide bar if found above
38    let EABasketExpires = getEAvailabilityTimeoutCookie();
39
40
41    // If we couldn't find an element with the above ID, we'll create one
42    if (!EAContainer) {
43
44        // Build CSS element to add to the HEAD element. This may be overridden later in stylesheets
45        let EACSS = document.createElement('style');
46
47        let css = '#E-Availability-Timeout-Container { position: sticky; top: 0px; z-index: 99999; display: none; width: 100%; font-size: 12px; margin: 0px; padding: 5px; background-color: yellow; color: black; text-align: center; font-family: sans-serif }';
48
49        if (EACSS.stylesheet) { //IE
50            EACSS.stylesheet.cssText = css;
51        } else {                // rest of the world
52            EACSS.appendChild(document.createTextNode(css));
53        }
54
55        // Attach it to the HEAD element
56        document.head.prepend(EACSS);
57
58        // Build the E-Availability Timer container element
59        EAContainer = document.createElement('div');
60
61        EAContainer.id        = 'E-Availability-Timeout-Container';
62        EAContainer.innerHTML = 'The tickets in your basket will expire in: <span id="E-Availability-Timeout-Text"></span>';
63
64        // Add it to the BODY element
65        document.body.prepend(EAContainer);
66    }
67
68    // Work out how long is left on the timer
69    let now      = new Date().getTime();
70    let timeLeft = null;
71
72    if (EABasketExpires) {
73        timeLeft = EABasketExpires - now;
74    }
75
76    if (!EABasketExpires || timeLeft <= 0) {
77        EAContainer.style.display = "none";
78
79        let EAContainerText = document.getElementById('E-Availability-Timeout-Text');
80
81        if (EAContainerText) {
82            EAContainerText.innerHTML = "";
83        }
84
85        if (EATimer) {
86            clearInterval(EATimer);
87        }
88    }
89    else {
90
91        // Time calculations for days, hours, minutes and seconds
92        let days    = Math.floor(timeLeft / (1000 * 60 * 60 * 24));
93        let hours   = Math.floor((timeLeft % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
94        let minutes = Math.floor((timeLeft % (1000 * 60 * 60)) / (1000 * 60));
95        let seconds = Math.floor((timeLeft % (1000 * 60)) / 1000);
96
97        // Build the countdown text
98        let countDownText = "";
99
100        if (days  > 0) {
101            countDownText +=  days.toString().padStart(2,"0") + ":";
102        }
103
104        if (hours > 0) {
105            countDownText += hours.toString().padStart(2,"0") + ":";
106        }
107
108        countDownText += minutes.toString().padStart(2,"0") + ":";
109        countDownText += seconds.toString().padStart(2,"0");
110
111        // If we're 0 or less, the countdown has expired
112        if (timeLeft <= 0) {
113            countDownText = "EXPIRED";
114        }
115
116        let EAContainerText = document.getElementById('E-Availability-Timeout-Text');
117
118        if (EAContainerText) EAContainerText.innerHTML = countDownText;
119
120        EAContainer.style.display = "block";
121
122        if (!EATimer) {
123            EATimer = setInterval(function() {eAvailabilityTimeout();}, 1000);
124        }
125    }
126
127    if (timeLeft && timeLeft <= 0) {
128
129        document.getElementsByTagName('body')[0].style.pointerEvents = 'none'; // Disable clicks
130
131        alert("Sorry, the tickets in your basket have now expired and will be removed. Please go back to the events pages and add them again.");
132
133        if (paymentPages.includes(pageName)) {
134            window.location.replace(window.location.pathname.replace(/\/[^\/]*$/, '/basket.html'));
135        } else {
136            window.location.reload();
137        }
138    }
139}
140
141const getEAvailabilityTimeoutCookie = () => {
142    const name = "e-availability-basket-expires=";
143    const cDecoded = decodeURIComponent(document.cookie); //to be careful
144    const cArr = cDecoded.split('; ');
145    let res;
146    cArr.forEach(val => {
147      if (val.indexOf(name) === 0) {
148        res = val.substring(name.length);
149      }
150    })
151
152    if (!res) {
153        return null;
154    }
155
156    return res;
157}
158
159eAvailabilityTimeout();

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.