PageSourceSearch

https://www.esylux.com/_assets/581ae7819742031f221bb47d76589cd6/JavaScripts/esylux.basket.js?1750094461

js esylux.com collected 2026-10-04 13:23:19 UTC 10,891 bytes, 314 lines download raw bytes

1;(function ($, window, document, undefined) {
2    "use strict";
3
4    let options = {
5        counter: '#basket-counter',
6        indexContainer: '.basket-index',
7        indexProduct: '.elbridge-product',
8        noItemsText: 'p.nobasket',
9        button: 'a.elbridgeBasket',
10        active: 'inBasket',
11        storageName: 'basket',
12        storageExpireName: 'basketExpire',
13        ttl: (7 * 24 * 60 * 60 * 1000) // 7d
14    }
15
16    function cartUpdateRefreshNotice() {
17        $('.elbridge-cart-update').addClass('refresh');
18        setTimeout(
19            () => {
20                $('.elbridge-cart-update').removeClass('refresh');
21            }, 1500
22        );
23    }
24
25    function loadList() {
26        let container = $(options.indexContainer);
27        if (container.length > 0) {
28            const now = new Date();
29            const expiry = parseInt(localStorage.getItem(options.storageExpireName)) || 0;
30            let json = '';
31            if (now.getTime() > expiry) {
32                json = '';
33            } else {
34                json = (localStorage.getItem(options.storageName) || '')
35            }
36
37            $('.elbridge-basket-loading').show();
38            $.ajax({
39                type: "POST",
40                url: container.data('url'),
41                data: {
42                    'tx_esylux_basket[json]': json,
43                    'tx_esylux_basket[action]': 'renderBasketList'
44                },
45                success: function (response) {
46                    container.html(response);
47                    container.find(options.button).addClass(options.active);
48                    $('.elbridge-basket-loading').hide();
49                }
50            });
51        }
52    }
53
54    function refresh(items) {
55        if (items.length > 0) {
56            $(options.counter).text(items.length + '').show();
57        } else {
58            $(options.counter).text('').hide();
59        }
60        $(options.indexContainer).html('');
61        loadList();
62        if (items.length && $(options.button + '[data-product-id]').length > 0) {
63            $.each(items, function () {
64                if (this) {
65                    $(options.button + '[data-product-id="' + this.id + '"]').addClass(options.active);
66                }
67            });
68        }
69    }
70
71    function addItem(items, productId, amount, add) {
72        let foundAtIndex = -1;
73        let modified = false;
74        $(items).each(function(index, item) {
75            if (item.id === productId) {
76                foundAtIndex = index;
77            }
78        });
79        if (add && foundAtIndex > -1) {
80            items[foundAtIndex].amount += (amount || 1);
81            modified = true;
82        }
83        if (foundAtIndex === -1) {
84            items.push({
85                id: productId,
86                amount: (amount || 1)
87            });
88            modified = true;
89        }
90        if (modified) {
91            storeItems(items);
92            $(options.button + '[data-product-id="' + productId + '"]').addClass(options.active);
93            refresh(items);
94        }
95        cartUpdateRefreshNotice();
96    }
97
98    function removeItem(items, productId) {
99        let indexToRemove = -1;
100        $(items).each(function(index, item) {
101            if (item.id === productId) {
102                indexToRemove = index;
103            }
104        });
105        if (indexToRemove >= 0) {
106            items.splice(indexToRemove, 1);
107            storeItems(items);
108            $(options.button + '[data-product-id="' + productId + '"]').removeClass(options.active);
109            let container = $(options.indexContainer);
110            if (container.length > 0) {
111                $($(options.button + '[data-product-id="' + productId + '"]')).parents(options.indexProduct).slideUp(function () {
112                    $(this).remove();
113                });
114            }
115            refresh(items);
116        }
117        cartUpdateRefreshNotice();
118    }
119
120    function getItems() {
121        const now = new Date();
122        const expiry = parseInt(localStorage.getItem(options.storageExpireName)) || 0;
123        if (now.getTime() > expiry) {
124            return [];
125        }
126        var items = JSON.parse(localStorage.getItem(options.storageName));
127        var cleanItems = [];
128        if ($.isArray(items)) {
129            $.each(items, function () {
130                if (this && this.id) {
131                    var id = this.id.toString().match(/@IMID:[a-zA-Z]+:[a-zA-Z0-9]+/)[0];
132                    cleanItems.push({
133                        'id': id,
134                        'amount': this.amount || 1
135                    });
136                }
137            });
138        }
139        return cleanItems;
140    }
141
142    function clearAllItems() {
143        storeItems([]);
144        refresh([]);
145    }
146
147    function storeItems(items) {
148        var json = JSON.stringify(items);
149        localStorage.setItem(options.storageName, json);
150        const now = new Date();
151        localStorage.setItem(options.storageExpireName, JSON.stringify(now.getTime() + options.ttl));
152    }
153
154    window.esyluxRefreshBasket = function () {
155        let items = getItems();
156        refresh(items);
157    }
158
159    function initializeAddButtons() {
160        $(document).on('click', options.button, function (event) {
161            event.preventDefault();
162            var clickedButton = $(this);
163
164            var productId = clickedButton.data('productId');
165            if (productId) {
166                let items = getItems();
167                if (!clickedButton.hasClass(options.active)) {
168                    addItem(items, productId);
169                } else {
170                    removeItem(items, productId);
171                }
172            }
173            return false;
174        });
175    }
176
177    function initializeSubmitButton() {
178        $(document).on('click','.elbridge-submit', function (event) {
179            event.preventDefault();
180            var products = [];
181            $(this).parents('form').find('.elbridge-product').each(function () {
182                products.push({
183                    "id": $(this).find('input.product').val(),
184                    "amount": $(this).find('input.quantity').val()
185                });
186            });
187
188            $.post({
189                url: ($('#configuration').data('baseuri') || '/')
190                    + '?type=1654173175',
191                dataType: 'json',
192                data: {
193                    'tx_esylux_basket[action]': 'getResult',
194                    'tx_esylux_basket[json]': JSON.stringify(products),
195                },
196                success: function (data) {
197                    var form = $('.elbridge-submit');
198                    if (data && data['elbridge']) {
199                        if (data['elbridge']['country']) {
200                            form.find('input[name=country]').val(data['elbridge']['country']);
201                        }
202                        if (data['elbridge']['language']) {
203                            form.find('input[name=language]').val(data['elbridge']['language']);
204                        }
205                        if (data['elbridge']['hookurl']) {
206                            form.prop('action', data['elbridge']['hookurl']);
207                        }
208                    }
209                    if (data && data['result']) {
210                        form.find('input[name=result]').val(JSON.stringify(data['result']));
211                        form.submit();
212                        setTimeout(function () {
213                            clearAllItems();
214                            form.find('input[name=result]').val('');
215                        }, 500);
216                    }
217                }
218            });
219            return false;
220        });
221    }
222
223    function initializeAddAllButtons(items) {
224        $(document).on('click','.addBookmarksToBasket', function (event) {
225            event.preventDefault();
226            let items = getItems();
227            $(window.esyluxGetBookmarks()).each(function() {
228                addItem(items, this, 1);
229            });
230            window.location = this.href;
231            return false;
232        });
233        $(document).on('click','.addProjectToBasket, .clearAndAddProjectToBasket', function (event) {
234            event.preventDefault();
235            let items = getItems();
236            if ($(this).hasClass('clearAndAddProjectToBasket')) {
237                clearAllItems();
238                items = [];
239            }
240            $(window.esyluxGetProjectListProducts()).each(function() {
241                addItem(items, this.id, this.amount, true);
242            });
243            window.location = this.href;
244            return false;
245        });
246    }
247
248    function initializeAddProductButton() {
249        let xhr;
250        $('.elbridge-addproduct').prop("disabled", true);
251        $('#elbridge-addproduct-input').autocomplete({
252            search: function (event, ui) {
253                $(event.target).data('productId', '');
254            },
255            source: function (request, response) {
256                xhr && xhr.abort();
257                xhr = $.ajax({
258                    url: ($('#configuration').data('baseuri') || '/')
259                        + '?type=1619162552',
260                    dataType: 'json',
261                    data: {
262                        'term': request.term,
263                        'allowArchived': 0
264                    },
265                    success: function (data) {
266                        response(data.suggestions);
267                    }
268                });
269            },
270            minLength: 2,
271            select: function (event, ui) {
272                if (ui.item.value && ui.item.id) {
273                    $('.elbridge-addproduct').prop("disabled", false);
274                    $(event.target)
275                        .data('productId', ui.item.id)
276                        .data('productLabel', ui.item.label);
277                }
278            }
279        });
280
281        $('.elbridge-addproduct').click(function (event) {
282            event.preventDefault();
283            let input = $(this)
284                .closest('form')
285                .find('.esylux-addproduct-input');
286            let productId = input.data('productId');
287            if (productId !== "" && typeof productId !== 'undefined') {
288                $(this).prop("disabled",true);
289                let items = getItems();
290                addItem(items, productId, 1, true);
291
292                $(input).val('').data('productId', '');
293            }
294            return false;
295        });
296    }
297
298    function initialize() {
299        let items = getItems();
300        refresh(items);
301        storeItems(items);
302        initializeAddButtons(items);
303        initializeSubmitButton(items);
304        initializeAddAllButtons(items);
305        initializeAddProductButton();
306    }
307
308    $(document).ready(function () {
309        initialize();
310        $('.clear-cart').click(function(){
311            clearAllItems();
312        });
313    });
314})(jQuery, window, document);

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.