PageSourceSearch

https://islamic-relief.org/wp-content/plugins/irw-ten-nights/assets/js/ten-nights.js?ver=1.2.0

js islamic-relief.org collected 2026-10-02 04:12:30 UTC 11,065 bytes, 275 lines download raw bytes

1(function () {
2    'use strict';
3
4    document.addEventListener('DOMContentLoaded', function () {
5
6        /* ==================================================================
7           Accordion Toggle
8           ================================================================== */
9        var toggles = document.querySelectorAll('[data-irw-tn-toggle]');
10
11        toggles.forEach(function (btn) {
12            btn.addEventListener('click', function () {
13                var expanded = btn.getAttribute('aria-expanded') === 'true';
14                var body = btn.nextElementSibling;
15                if (!body) return;
16
17                if (expanded) {
18                    body.style.maxHeight = body.scrollHeight + 'px';
19                    requestAnimationFrame(function () {
20                        body.style.maxHeight = '0px';
21                    });
22                    btn.setAttribute('aria-expanded', 'false');
23                    body.setAttribute('aria-hidden', 'true');
24                    setTimeout(function () {
25                        if (btn.getAttribute('aria-expanded') === 'false') {
26                            body.style.display = 'none';
27                        }
28                    }, 350);
29                } else {
30                    body.style.display = 'block';
31                    body.style.maxHeight = '0px';
32                    requestAnimationFrame(function () {
33                        body.style.maxHeight = body.scrollHeight + 'px';
34                    });
35                    btn.setAttribute('aria-expanded', 'true');
36                    body.setAttribute('aria-hidden', 'false');
37                    setTimeout(function () {
38                        if (btn.getAttribute('aria-expanded') === 'true') {
39                            body.style.maxHeight = 'none';
40                        }
41                    }, 350);
42                }
43            });
44        });
45
46        // Initialize: ensure expanded sections have no max-height constraint
47        toggles.forEach(function (btn) {
48            if (btn.getAttribute('aria-expanded') === 'true') {
49                var body = btn.nextElementSibling;
50                if (body) {
51                    body.style.maxHeight = 'none';
52                    body.style.display = 'block';
53                }
54            }
55        });
56
57        /* ==================================================================
58           Countdown Timer — counts down to midnight
59           ================================================================== */
60        var timerH = document.getElementById('irwTnHours');
61        var timerM = document.getElementById('irwTnMinutes');
62        var timerS = document.getElementById('irwTnSeconds');
63
64        if (timerH && timerM && timerS) {
65            function padTimer(n) { return n < 10 ? '0' + n : '' + n; }
66
67            function getTargetTime() {
68                // Count from 12PM GMT to 12PM GMT next day
69                var now = new Date();
70                var todayNoon = new Date(Date.UTC(
71                    now.getUTCFullYear(),
72                    now.getUTCMonth(),
73                    now.getUTCDate(),
74                    12, 0, 0, 0
75                ));
76                if (now < todayNoon) {
77                    return todayNoon;
78                }
79                return new Date(todayNoon.getTime() + 86400000);
80            }
81
82            function updateTimer() {
83                var now = new Date();
84                var diff = getTargetTime() - now;
85                if (diff <= 0) {
86                    var wrap = document.querySelector('.irw-tn-timer-wrap');
87                    if (wrap) wrap.style.display = 'none';
88                    return;
89                }
90                var totalSec = Math.floor(diff / 1000);
91                var h = Math.floor(totalSec / 3600);
92                var m = Math.floor((totalSec % 3600) / 60);
93                var s = totalSec % 60;
94                timerH.textContent = padTimer(h);
95                timerM.textContent = padTimer(m);
96                timerS.textContent = padTimer(s);
97            }
98
99            updateTimer();
100            setInterval(updateTimer, 1000);
101        }
102
103        /* ==================================================================
104           Donate Popup
105           ================================================================== */
106        var overlay    = document.getElementById('irwTnDonateOverlay');
107        var closeBtn   = document.getElementById('irwTnDonateClose');
108        var popupTitle = document.getElementById('irwTnDonateTitle');
109        var popupSub   = document.getElementById('irwTnDonateSubtitle');
110        var fundInput  = document.getElementById('irwTnDonateFund');
111        var currSelect = document.getElementById('irwTnDonateCurrency');
112        var amtInput   = document.getElementById('irwTnDonateAmount');
113        var symbolEl   = document.getElementById('irwTnDonateSymbol');
114        var submitBtn  = document.getElementById('irwTnDonateSubmit');
115
116        var GATEWAY_URL = 'https://donate.islamic-relief.org/feed.php';
117        var selectedAmount = 100;
118        var currencySymbols = { USD: '$', GBP: '\u00A3', EUR: '\u20AC' };
119
120        function openDonatePopup(fundId, title, fallbackUrl) {
121            if (!overlay) return;
122
123            // If no fund_id, fall back to direct URL redirect
124            if (!fundId && fallbackUrl && fallbackUrl !== '#') {
125                window.location.href = fallbackUrl;
126                return;
127            }
128            if (!fundId) return;
129
130            // Set popup data
131            fundInput.value = fundId;
132            popupTitle.textContent = 'Donate Now';
133            popupSub.textContent = title || '';
134
135            // Reset form state
136            selectedAmount = 100;
137            amtInput.value = '';
138            currSelect.value = 'USD';
139            symbolEl.textContent = '$';
140
141            // Reset amount buttons
142            overlay.querySelectorAll('.irw-tn-donate-popup__amount').forEach(function (b) {
143                b.classList.toggle('active', b.getAttribute('data-amount') === '100');
144            });
145
146            overlay.classList.add('active');
147            document.body.style.overflow = 'hidden';
148        }
149
150        function closeDonatePopup() {
151            if (!overlay) return;
152            overlay.classList.remove('active');
153            document.body.style.overflow = '';
154        }
155
156        // Currency dropdown change
157        if (currSelect) {
158            currSelect.addEventListener('change', function () {
159                symbolEl.textContent = currencySymbols[currSelect.value] || '$';
160            });
161        }
162
163        if (overlay) {
164            // Amount preset buttons
165            overlay.querySelectorAll('.irw-tn-donate-popup__amount').forEach(function (btn) {
166                btn.addEventListener('click', function () {
167                    selectedAmount = parseInt(btn.getAttribute('data-amount'), 10);
168                    amtInput.value = '';
169                    overlay.querySelectorAll('.irw-tn-donate-popup__amount').forEach(function (b) {
170                        b.classList.toggle('active', b === btn);
171                    });
172                });
173            });
174
175            // Custom amount input clears preset selection
176            if (amtInput) {
177                amtInput.addEventListener('input', function () {
178                    if (amtInput.value) {
179                        selectedAmount = 0;
180                        overlay.querySelectorAll('.irw-tn-donate-popup__amount').forEach(function (b) {
181                            b.classList.remove('active');
182                        });
183                    }
184                });
185            }
186        }
187
188        // Submit donation
189        if (submitBtn) {
190            submitBtn.addEventListener('click', function () {
191                var fund = fundInput.value;
192                var currency = currSelect.value;
193                var amount = amtInput.value ? parseInt(amtInput.value, 10) : selectedAmount;
194
195                if (!fund || !amount || amount < 1) return;
196
197                var url = GATEWAY_URL
198                    + '?product=' + encodeURIComponent(fund)
199                    + '&currency=' + encodeURIComponent(currency)
200                    + '&amount=' + encodeURIComponent(amount);
201
202                window.location.href = url;
203            });
204        }
205
206        // Attach to all donate buttons
207        document.querySelectorAll('[data-donate-fund]').forEach(function (btn) {
208            btn.addEventListener('click', function (e) {
209                e.preventDefault();
210                openDonatePopup(
211                    btn.getAttribute('data-donate-fund'),
212                    btn.getAttribute('data-donate-title'),
213                    btn.getAttribute('data-donate-url')
214                );
215            });
216        });
217
218        if (closeBtn) {
219            closeBtn.addEventListener('click', closeDonatePopup);
220        }
221
222        if (overlay) {
223            overlay.addEventListener('click', function (e) {
224                if (e.target === overlay) {
225                    closeDonatePopup();
226                }
227            });
228        }
229
230        // ESC key closes popup
231        document.addEventListener('keydown', function (e) {
232            if (e.key === 'Escape' && overlay && overlay.classList.contains('active')) {
233                closeDonatePopup();
234            }
235        });
236
237        /* ==================================================================
238           Instagram Share (Web Share API → fallback to profile)
239           ================================================================== */
240        document.querySelectorAll('.irw-tn-share__btn--ig').forEach(function (btn) {
241            btn.addEventListener('click', function () {
242                var url = btn.getAttribute('data-share-url');
243                var text = btn.getAttribute('data-share-text');
244                var isMobile = /Android|iPhone|iPad|iPod/i.test(navigator.userAgent);
245
246                if (isMobile && navigator.share) {
247                    navigator.share({
248                        title: text,
249                        text: text,
250                        url: url
251                    }).catch(function () {});
252                } else {
253                    window.open('https://www.instagram.com/irworldwide/', '_blank');
254                }
255            });
256        });
257
258        /* ==================================================================
259           Copy Link Button
260           ================================================================== */
261        document.querySelectorAll('.irw-tn-share__btn--copy').forEach(function (btn) {
262            btn.addEventListener('click', function () {
263                var url = btn.getAttribute('data-url');
264                if (!url) return;
265
266                navigator.clipboard.writeText(url).then(function () {
267                    btn.classList.add('copied');
268                    setTimeout(function () {
269                        btn.classList.remove('copied');
270                    }, 2000);
271                });
272            });
273        });
274    });
275})();

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.