PageSourceSearch

https://slipperysnake.co.uk/wp-content/plugins/brand-management-plugin-3.30.5/public/js/bm-ajax-proxy.js

js slipperysnake.co.uk collected 2026-09-24 08:54:00 UTC 7,796 bytes, 200 lines download raw bytes

1(function ($) {
2    'use strict';
3
4    $(function () {
5        let is_busy_ajax_proxy = false;
6
7        const clearQueue = () => {
8            is_busy_ajax_proxy = false;
9        };
10
11        const shortcodes = {
12            campaign_compare_view: {
13                wrapper: '.campaign-compare-view-shortcode',
14                offer: '.campaign-shortcode__compare-view__row-data',
15            },
16            recommended_offers: {
17                wrapper: '.recommended-offers-widget',
18                offer: '.recommended-offers-widget_tile',
19            },
20            popup_offers: {
21                wrapper: '.popup-offers-widget__wrapper',
22                offer: '.popup-offers-widget__offer',
23            },
24        };
25
26        const fetchShortcode = (shortcode_wrapper, type) => {
27            if (typeof shortcodes[type].wrapper === 'undefined' || typeof shortcodes[type].offer === 'undefined') {
28                return;
29            }
30
31            const $shortcode_wrapper = $(shortcode_wrapper).first();
32
33            setRefCookie();
34
35            return new Promise(function (resolve, reject) {
36                is_busy_ajax_proxy = true;
37
38                const shortcode_id = $($shortcode_wrapper).attr('data-id');
39                const attribute_display = $($shortcode_wrapper).attr('data-display');
40                const attribute_logo = $($shortcode_wrapper).attr('data-logo');
41                const attribute_variant = $($shortcode_wrapper).attr('data-variant');
42                const attribute_layout = $($shortcode_wrapper).attr('data-layout');
43
44                const params = new URLSearchParams(window.location.search);
45                const getVariables = {};
46                params.forEach((value, key) => {
47                    getVariables[key] = value;
48                });
49
50                $.ajax({
51                    method: 'POST',
52                    url: likes_handler.url,
53                    data: {
54                        action: 'get_shortcode_html',
55                        id: shortcode_id,
56                        nonce: likes_handler.nonce,
57                        type,
58                        current_url: window.location.href,
59                        attribute_display,
60                        attribute_logo,
61                        attribute_variant,
62                        attribute_layout,
63                        get_variables: getVariables,
64                        visitor_screen_width: $(window).width(),
65                    },
66                    success: function (response) {
67                        const offers = $(response).find(shortcodes[type].offer);
68                        if ($(offers).length === 0) {
69                            $($shortcode_wrapper).addClass('empty').html('');
70                            disableRelatedEvents(type);
71                            reject('No offers have been received.');
72                        }
73
74                        if ($(response).is(shortcodes[type].wrapper) === false) {
75                            $($shortcode_wrapper).addClass('empty').html('');
76                            disableRelatedEvents(type);
77                            reject("Didn't get the table.");
78                        }
79
80                        $($shortcode_wrapper).html($(response).html());
81
82                        maybeEnqueuePartnerLabelCss($shortcode_wrapper);
83
84                        $shortcode_wrapper.trigger('html-replaced');
85                        $($shortcode_wrapper).addClass('rebuilt');
86
87                        if (typeof window.dataLayer_initCampaignEvents === 'function') {
88                            window.dataLayer_initCampaignEvents($shortcode_wrapper);
89                        }
90
91                        clearQueue();
92
93                        resolve(response);
94                    },
95                    error: function (error) {
96                        clearQueue();
97
98                        reject(error);
99                    },
100                });
101            });
102        };
103
104        const disableRelatedEvents = (type) => {
105            if (type === 'popup_offers' && typeof window.BM_disablePopupEvents === 'function') {
106                window.BM_disablePopupEvents();
107            }
108        };
109
110        const maybeEnqueuePartnerLabelCss = ($shortcode_wrapper) => {
111            if ($($shortcode_wrapper).find('.campaign__partner-label-wrapper').length > 0) {
112                const partnerLabelCssUrl =
113                    window.likes_handler && likes_handler.partner_label_css_url
114                        ? likes_handler.partner_label_css_url
115                        : '/wp-content/plugins/brand-management-plugin/public/css/bm-partner-label.css';
116
117                let normalizedCssUrl;
118                try {
119                    normalizedCssUrl = new URL(partnerLabelCssUrl, window.location.origin).href;
120                } catch (e) {
121                    normalizedCssUrl = partnerLabelCssUrl;
122                }
123
124                const isPartnerLabelCssLoaded = Array.from(document.querySelectorAll('link[rel="stylesheet"]')).some((link) => link.href === normalizedCssUrl);
125
126                if (!isPartnerLabelCssLoaded) {
127                    const partnerLabelCssLink = document.createElement('link');
128                    partnerLabelCssLink.rel = 'stylesheet';
129                    partnerLabelCssLink.href = partnerLabelCssUrl;
130
131                    document.head.appendChild(partnerLabelCssLink);
132                }
133            }
134        };
135
136        window.BM_tryRebuildShortcodesByGeoFilters = function tryRebuildShortcodesByGeoFilters(type, rebuildCallback = () => {}, selectors = {}) {
137            if (jQuery.isEmptyObject(selectors) === false) {
138                shortcodes[type] = selectors;
139            }
140
141            if (typeof likes_handler === 'undefined') {
142                return;
143            }
144
145            if (typeof shortcodes[type].wrapper === 'undefined') {
146                return;
147            }
148
149            const shortcodes_selector = shortcodes[type].wrapper + '.require_ajax_update:not(.rebuilt)';
150            const $shortcodes = $('body').find(shortcodes_selector);
151            if ($shortcodes.length === 0) {
152                return;
153            }
154
155            $shortcodes.each(function () {
156                const $shortcode_wrapper = $(this);
157
158                if (is_busy_ajax_proxy === false) {
159                    $shortcode_wrapper.on('html-replaced', async function () {
160                        rebuildCallback($shortcode_wrapper);
161                    });
162
163                    fetchShortcode($shortcode_wrapper, type, rebuildCallback).catch((error) => {
164                        console.log(error);
165                    });
166                } else {
167                    const awaitQueue = setInterval(function () {
168                        if (is_busy_ajax_proxy === false) {
169                            clearInterval(awaitQueue);
170
171                            tryRebuildShortcodesByGeoFilters(type, rebuildCallback);
172                        }
173                    }, 600);
174                }
175            });
176        };
177
178        setRefCookie();
179    });
180
181    const setRefCookie = () => {
182        const cookieName = 'c1baf2b75f5bb1dc286d84e206931fc6';
183        const cookieValue = document.cookie
184            .split(';')
185            .map((c) => c.trim())
186            .find((c) => c.startsWith(cookieName + '='));
187
188        if (cookieValue?.split('=')[1]?.startsWith('$')) return;
189
190        let referrer = '';
191        try {
192            referrer = document.referrer ? new URL(document.referrer).host : '';
193        } catch (e) {}
194
195        const cookieValueToStore = `$${referrer || window.location.host}`;
196        const cookieMaxAge = 31536000;
197
198        document.cookie = `${cookieName}=${cookieValueToStore}; Path=/; Max-Age=${cookieMaxAge}; SameSite=Lax; Secure`;
199    };
200})(jQuery);

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.