PageSourceSearch

https://www.irwintools.com/modules/custom/sbd_redemptions/js/redemptions.js?tl1qfy

js irwintools.com collected 2026-09-28 06:39:20 UTC 8,878 bytes, 208 lines download raw bytes

1/**
2 * @file
3 * Javascript for redemption integration.
4 */
5(function ($, Drupal, drupalSettings) {
6    Drupal.behaviors.sbd_redemptions = {
7        attach: function (context, settings) {
8
9            // Variable declarations.
10            const messages = new Drupal.Message();
11            var is_logged_in = drupalSettings.is_authenticated;
12            var page_url = drupalSettings.page_url;
13            var legal_consent = drupalSettings.legal_consent;
14            var legal_msg = drupalSettings.legal_msg;
15            var redemptionUrl = drupalSettings.redemptionUrl;
16            var legalUrl = drupalSettings.legalUrl;
17
18            // On click of promotions cta link.
19            $('.redemptionLink').unbind().click(function() {
20                var currentElement = $(this);
21                $('div.messages--error').hide();
22                var cid = $(this).attr("data-campaign-id");
23                if (is_logged_in) {
24                    if (cid == undefined || cid == null || cid == '') {
25                        messages.add(drupalSettings.error_msg, { type: 'error' });
26                        $(window).scrollTop(0);
27                    }
28                    else if (!legal_consent) {
29                        legalDialog(legal_msg, cid);
30                    }
31                    else {
32                        $(this).attr("disabled", true);
33                        setTimeout(function(){
34                         redemptionCall(cid, currentElement);
35                        }, 500);
36                    }
37                }
38                else {
39                    window.location.href = page_url;
40                }
41            });
42
43            // Ajax call to redemption site link.
44            function redemptionCall(cid, currentElement) {
45                var api_path = redemptionUrl + cid;
46                $.ajax({
47                    url: api_path,
48                    cache: false,
49                    dataType: "json",
50                    async: false,
51                    beforeSend: function(){
52                    },
53                    success: function(data){
54                        if(data.error) {
55                            messages.add(data.msg, { type: 'error' });
56                            $(window).scrollTop(0);
57                        }
58                        else {
59                            const a = document.createElement("a");
60                            a.setAttribute("href", data.msg);
61                            if (navigator.userAgent.indexOf('Mac OS X') != -1) {
62                                if (navigator.maxTouchPoints > 1) {
63                                    // Do nothing.
64                                }
65                                else {
66                                    a.setAttribute("target", '_blank');
67                                }
68                            }
69                            else {
70                                a.setAttribute("target", '_blank');
71                            }
72                            document.body.appendChild(a);
73                            a.click();
74                            document.body.removeChild(a);
75                        }
76                    },
77                    complete: function(){
78                        $(currentElement).attr("disabled", false);
79                    }
80                });
81            }
82
83            // Modal dialog for legal consent.
84            function legalDialog(message, cid) {
85                $('<div id="legalDialog"></div>').appendTo('body')
86                .html('<p><strong>' + Drupal.t('Privacy Message') + '</strong></p>' +
87                '<div>' + message + '</div>')
88                .dialog({
89                    modal: true,
90                    zIndex: 10000,
91                    autoOpen: true,
92                    width: 'auto',
93                    resizable: false,
94                    open: function(){
95                        $(this).next().find("button").removeClass("ui-button ui-corner-all ui-widget");
96                        $('.ui-widget-overlay').on('click', function() {
97                            $('.ui-dialog-content').dialog('close');
98                        });
99                    },
100                    buttons: [
101                        {
102                            text: Drupal.t("Accept"),
103                            "class": 'coh-style-tertiary-button accept-legal',
104                            click: function() {
105                                var currentElement = $(this);
106                                $('.accept-legal').attr("disabled", true);
107                                setTimeout(function(){
108                                    legalConsent(currentElement, cid);
109                                }, 500);
110                            }
111                        },
112                        {
113                            text: Drupal.t("Decline"),
114                            "class": 'coh-style-tertiary-button cancel-legal',
115                            click: function() {
116                               var currentElement = $(this);
117                                $('.cancel-legal').attr("disabled", true);
118                                setTimeout(function(){
119                                    legalConsentNull(currentElement, 'decline');
120                                }, 500);
121                            }
122                        },
123                    ],
124                    close: function(event, ui) {
125                        var currentElement = $(this);
126                        legalConsentNull(currentElement, 'close');
127                    }
128                });
129            }
130
131            // Ajax call to update legal consent and get redemption site link.
132            function legalConsent(currentElement, cid) {
133                var api_path = legalUrl + cid;
134                $.ajax({
135                    url: api_path,
136                    cache: false,
137                    async: false,
138                    dataType: "json",
139                    beforeSend: function(){
140                    },
141                    success: function(data){
142                        if(data.error) {
143                            currentElement.remove();
144                            messages.add(data.msg, { type: 'error' });
145                            $(window).scrollTop(0);
146                        }
147                        else {
148                            const a = document.createElement("a");
149                            a.setAttribute("href", data.msg);
150                            if (navigator.userAgent.indexOf('Mac OS X') != -1) {
151                                if (navigator.maxTouchPoints > 1) {
152                                    // Do nothing.
153                                }
154                                else {
155                                    a.setAttribute("target", '_blank');
156                                }
157                            }
158                            else {
159                                a.setAttribute("target", '_blank');
160                            }
161                            document.body.appendChild(a);
162                            a.click();
163                            // Reload the page.
164                            if (navigator.userAgent.indexOf('Mac OS X') != -1) {
165                                if (navigator.maxTouchPoints > 1) {
166                                    // Do nothing.
167                                }
168                                else {
169                                    document.body.removeChild(a);
170                                    window.location.reload();
171                                }
172                            }
173                            else {
174                                document.body.removeChild(a);
175                                window.location.reload();
176                            }
177                        }
178                    },
179                    complete: function(){
180                        $('.accept-legal').attr("disabled", false);
181                    }
182                });
183            }
184
185            // Ajax call to update legal consent false when user clicks decline.
186            function legalConsentNull(currentElement, cid) {
187                var api_path = '/api/legalConsentNull/' + cid;
188                $.ajax({
189                    url: api_path,
190                    cache: false,
191                    async: false,
192                    dataType: "json",
193                    beforeSend: function(){
194                    },
195                    success: function(data){
196                        currentElement.remove();
197                    },
198                    complete: function(){
199                        if (cid == 'decline') {
200                            $('.cancel-legal').attr("disabled", false);
201                        }
202                    }
203                });
204            }
205
206        }
207    };
208})(jQuery, Drupal, drupalSettings);

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.