PageSourceSearch

https://abainternational.org/scripts/shopping/incShowDonateToSabaMessage.js?v=12

js abainternational.org collected 2026-09-24 08:53:00 UTC 8,652 bytes, 216 lines download raw bytes

1const cStorageKey = 'abai_shopping_id';
2const CONTROL_TIMEOUT = 'timeout';
3const CONTROL_XBUTTON = 'xbutton';
4const CONTROL_LINK = 'donationlink';
5const CONTROL_NEVER_AGAIN = 'neverShow';
6const DEFAULT_DEST_URL = "https://saba.abainternational.org/giving-tuesday/";
7
8var m_timerId;
9
10$(document).ready(function () {
11
12    fnGenerateShoppingCartId();
13
14    if (window.location.hostname !== "saba.abainternational.org")
15        fnShowDonateBanner();
16
17});
18
19function fnGenerateShoppingCartId() {
20    try {
21        // Function to generate a GUID - used to identify the shopping cart
22        const generateGuid = () => 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
23            const r = Math.random() * 16 | 0;
24            const v = c === 'x' ? r : (r & 0x3 | 0x8);
25            return v.toString(16);
26        });
27
28        // Function to validate if a string is a valid GUID
29        const isValidGuid = guid => /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(guid);
30
31        // Check for 'abai_shopping_id' in localStorage and validate or generate it
32        let abaiShoppingId = localStorage.getItem(cStorageKey);
33
34        if (!isValidGuid(abaiShoppingId)) {
35            abaiShoppingId = generateGuid();
36            localStorage.setItem(cStorageKey, abaiShoppingId);
37        }
38
39        // Set the GUID into the hidden field ending with 'abai_shopping_id'
40        $("input[id$='abai_shopping_id']").val(abaiShoppingId);
41    } catch (ex) {
42        console.log(ex);
43    }
44}
45
46function fnShowDonateBanner() {
47
48    try {
49        // Get the json properties object
50        // <control_data id="saba_donor_banner_data">{"isActive":true,"interval":86400000,"timeout":20000}</control_data>
51        let sabaBannerData = JSON.parse($('#saba_donor_banner_data').text())
52
53        if (sabaBannerData.hasOwnProperty('isActive') ? sabaBannerData.isActive : false) {
54
55            // Make this key name vary by year, so it resets every year.
56            const currentYear = new Date().getFullYear();
57            const cNeverShowBannerLocalStorageKey = `abai_saba_never_show_banner_${currentYear}`;
58
59            // Check if the user opted to never show the banner
60            if (localStorage.getItem(cNeverShowBannerLocalStorageKey) === 'true') {
61                return; // user checked "never show me this again - quit processing"
62            }
63
64            const cDefaultTimeout = 20000;
65            const cDefaultInterval = 86400000;
66            const cBannerLocalStorageKey = "abai_saba_banner_dismissed";
67            
68            const cBannerHtmlKey = "saba_donor_banner_html";
69            const cDefaultHtml = "<h3>Don't forget to donate to SABA!</h3>";
70            const cBannerHtml = sabaBannerData.hasOwnProperty(cBannerHtmlKey) ? sabaBannerData.saba_donor_banner_html : cDefaultHtml;
71            $('#sabaBannerHtml').html(cBannerHtml);
72
73            const cDonateNowButtonTextKey = "saba_donor_banner_buttontext";
74            const cDefaultButtonText = "Donate Now";
75            const cDonateNowButtonText = sabaBannerData.hasOwnProperty(cDonateNowButtonTextKey) ? sabaBannerData.saba_donor_banner_buttontext : cDefaultButtonText;
76            $('#goto_donation_url_button').text(cDonateNowButtonText);
77
78            // this is a setting stored in the database
79            const cTimeOut = sabaBannerData.hasOwnProperty('timeout') ? sabaBannerData.timeout : cDefaultTimeout;
80
81            // this is a setting stored in the database
82            const cInterval = sabaBannerData.hasOwnProperty('interval') ? sabaBannerData.interval : cDefaultInterval;
83
84            // Check if the banner was dismissed in the last 24 hours
85            let lastDismissed = localStorage.getItem(cBannerLocalStorageKey);
86            if (lastDismissed && (new Date().getTime() - lastDismissed) < cInterval) { // 24 hours in milliseconds
87                return;
88            }
89
90            // Set the donation URL
91            const cUrl = sabaBannerData.hasOwnProperty('url') ? sabaBannerData.url : DEFAULT_DEST_URL;
92            $('#sabaDonationUrl').prop('href', cUrl).text(cUrl);
93            $('#incShowDonateToSabaMessage_donationurl_hidden').val(cUrl);
94
95            // Show the modal banner
96            $('#bannerModal').fadeIn();
97
98            fnSetBannerPosition();
99
100            // Adjust position when the window is resized
101            $(window).resize(function () {
102                fnSetBannerPosition();
103            });
104
105
106            // Set a timer to auto-close the banner after 20 seconds
107            m_timerId = setTimeout(function () {
108                fnFadeOutBanner(CONTROL_TIMEOUT)
109                localStorage.setItem(cBannerLocalStorageKey, new Date().getTime());
110            }, cTimeOut);
111
112            // Close the banner when the close button is clicked
113            $('#closeBtn').click(function () {
114                fnFadeOutBanner(CONTROL_XBUTTON);
115                localStorage.setItem(cBannerLocalStorageKey, new Date().getTime());
116            });
117
118            $('#sabaDonationUrl').click(function () {
119                fnFadeOutBanner(CONTROL_LINK);
120                return true;
121            });
122
123            const dest_url = $('#incShowDonateToSabaMessage_donationurl_hidden').val().trim();
124            let sDestUrl = '';
125            if (dest_url === '') {
126                // handle blank/missing - supply a default
127                sDestUrl = DEFAULT_DEST_URL;
128            } else {
129                // send the user on
130                sDestUrl = dest_url;
131            }
132                    
133            $('#goto_donation_url_button').click(function() {
134                fnFadeOutBanner(CONTROL_LINK);
135                localStorage.setItem(cBannerLocalStorageKey, new Date().getTime());
136                window.location.href = sDestUrl;               
137            });
138
139            // If "Never show this again" is checked, store that preference
140            $('#neverShow').change(function () {
141                if ($(this).is(':checked')) {
142                    localStorage.setItem(cNeverShowBannerLocalStorageKey, 'true');
143                    fnSaveClickData(`${CONTROL_NEVER_AGAIN}: true`);
144                } else {
145                    localStorage.removeItem(cNeverShowBannerLocalStorageKey);
146                    fnSaveClickData(`${CONTROL_NEVER_AGAIN}: false`);
147                }
148            });
149        }
150    }
151    catch (ex) {
152        console.log(ex);
153    }
154}
155
156function fnFadeOutBanner(vControl_Link) {
157    $('#bannerModal').fadeOut();
158    fnSaveClickData(vControl_Link);
159    clearTimeout(m_timerId);
160}
161
162// Function to set the banner position
163function fnSetBannerPosition() {
164    const screenHeight = $(window).height();
165    const bannerHeight = $('#bannerContent').outerHeight();
166
167    // Calculate the top position to place the banner a third of the way down
168    const topPosition = screenHeight / 3 - bannerHeight / 2;
169
170    // Apply the calculated position
171    $('#bannerContent').css({
172        top: topPosition + 'px'
173    });
174}
175
176function fnSaveClickData(controlId) {
177
178    // Data to send to the function
179    //var abaiShoppingId = 'your_shopping_id_here'; // Replace with actual shopping ID
180    let abaiShoppingId = localStorage.getItem(cStorageKey);
181
182//    // testing
183//    console.log(
184//
185//        JSON.stringify({
186//            abai_shopping_id: abaiShoppingId,
187//            page_name: window.location.href,
188//            control_id: controlId
189//        })
190//
191//    );
192    
193    // AJAX call
194    $.ajax({
195        url: '/webservice/SABA_Methods.asmx/SaveSabaDonorBannerData', // Replace with the actual URL where the function is hosted
196        type: 'POST',
197        contentType: 'application/json; charset=utf-8', // Required content type for ASP.NET web services
198        dataType: 'json', // Data type expected from the server
199        data: JSON.stringify({
200            abai_shopping_id: abaiShoppingId,
201            page_name: window.location.href,
202            control_id: controlId
203        }), // Data must be stringified for the request body
204        success: function (response) {
205            // No need to handle the return value since we are ignoring it
206            console.log('Data sent successfully.');
207        },
208        error: function (xhr, status, error) {
209            console.error('Error occurred: ' + error);
210            // You can also handle the error by showing a message to the user
211            //alert('An error occurred while sending data. Please try again.');
212        }
213    });
214
215}
216

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.