PageSourceSearch

https://www.esylux.com/_assets/581ae7819742031f221bb47d76589cd6/JavaScripts/esylux_bookmark.js?1754651095

js esylux.com collected 2026-10-04 13:23:19 UTC 12,796 bytes, 343 lines download raw bytes

1(function ($, viewport) {
2
3    function loadBookmarksOnIndex() {
4        let container = $('.bookmarks-index');
5        if (container.length > 0) {
6            $.ajax({
7                type: "POST",
8                url: container.data('url'),
9                data: {
10                    'tx_esylux_bookmark[bookmarkJson]': localStorage.getItem('bookmarks'),
11                    'tx_esylux_bookmark[bookmarkNotesJson]': localStorage.getItem('bookmarkNotes'),
12                    'tx_esylux_bookmark[action]': 'renderList'
13                },
14                success: function (response) {
15                    container.html(response);
16                    container.find('.bookmark').addClass('bookmarked');
17                    container.on(
18                        'click',
19                        '.bookmark-submit',
20                        function (event) {
21                            event.preventDefault();
22                            var button = $(this);
23                            $(button.data('submit')).submit();
24                            return false;
25                        }
26                    );
27                    container.find('.product-note')
28                        .on('change, keydown',
29                            function (event) {
30                                $('.bookmark-savenotes').removeAttr('disabled');
31                            }
32                        );
33                    container.find('.bookmark-savenotes')
34                        .on('click',
35                            function (event) {
36                                let notes = getNotes();
37                                container.find('.product-note').each(
38                                    function() {
39                                        let productId = $(this).data('productHashedId');
40                                        let note = $(this).val();
41                                        if (productId && note && note.length > 0) {
42                                            notes[productId] = note;
43                                        }
44                                    }
45                                );
46                                storeNotes(notes);
47                                $('.bookmark-savenotes').attr('disabled', 'disabled');
48                            }
49                        );
50                    if (window.esyluxRefreshBasket) {
51                        window.esyluxRefreshBasket();
52                    }
53                }
54            });
55        }
56    }
57
58    function getBookmarks() {
59        var bookmarks = JSON.parse(localStorage.getItem('bookmarks'));
60        if (bookmarks == null || bookmarks.length === 0) {
61            bookmarks = Cookies.getJSON('bookmarks');
62            Cookies.remove('bookmarks', {path: '/'});
63        }
64        var filteredBookmarks = [];
65        if ($.isArray(bookmarks)) {
66            $.each(bookmarks, function (index) {
67                if (this) {
68                    var cleanId = this.toString().match(/@IMID:[a-zA-Z]+:[a-zA-Z0-9]+/)[0];
69                    filteredBookmarks.push(cleanId);
70                }
71            });
72        }
73        return filteredBookmarks;
74    }
75
76    function getNotes() {
77        let notes = JSON.parse(localStorage.getItem('bookmarkNotes'));
78        if (!notes) {
79            notes = {};
80        }
81        return notes;
82    }
83
84    function updateBookmarkCounter(bookmarks) {
85        if (bookmarks.length > 0) {
86            $('#bookmark-counter').text(bookmarks.length + '').show();
87        } else {
88            $('#bookmark-counter').text('').hide();
89        }
90        if (bookmarks.length && $('.bookmark[data-product-id]').length > 0) {
91            $.each(bookmarks, function (index) {
92                if (this) {
93                    $('.bookmark[data-product-id="' + this + '"]').addClass('bookmarked');
94                }
95            });
96        }
97    }
98
99    var timeoutHandler;
100
101    function storeBookmarks(bookmarks, callback) {
102        if (!bookmarks || Object.keys(bookmarks).length === 0) {
103            localStorage.removeItem('bookmarks');
104            $('.bookmarkJson').val('');
105        } else {
106            var json = JSON.stringify(bookmarks);
107            localStorage.setItem('bookmarks', json);
108            $('.bookmarkJson').val(json);
109        }
110        if (callback) {
111            callback();
112        }
113    }
114
115    function storeNotes(notes, callback) {
116        if (!notes || Object.keys(notes).length === 0) {
117            localStorage.removeItem('bookmarkNotes');
118            $('.bookmarkNotesJson').val('');
119        } else {
120            var json = JSON.stringify(notes);
121            localStorage.setItem('bookmarkNotes', json);
122            $('.bookmarkNotesJson').val(json);
123        }
124        if (callback) {
125            callback();
126        }
127    }
128
129    function addBookmark(bookmarks, productId, callback) {
130        var index = bookmarks.indexOf(productId);
131        if (index === -1) {
132            bookmarks.push(productId);
133            storeBookmarks(bookmarks, callback);
134        } else {
135            if (callback) {
136                callback();
137            }
138        }
139        $('a.bookmark[data-product-id="' + productId + '"]').addClass('bookmarked');
140    }
141
142    window.esyluxRefreshBookmarks = function() {
143        var bookmarks = getBookmarks();
144        updateBookmarkCounter(bookmarks);
145    }
146
147    window.esyluxAddBookmark = function (productId, callback) {
148        var bookmarks = getBookmarks();
149        if (productId) {
150            addBookmark(bookmarks, productId, function () {
151                bookmarks = getBookmarks();
152                updateBookmarkCounter(bookmarks);
153                loadBookmarksOnIndex();
154                if (callback) {
155                    callback();
156                }
157            });
158        }
159    }
160
161    window.esyluxGetBookmarks = function() {
162        return getBookmarks();
163    }
164
165    function removeBookmark(bookmarks, productId, productHashedId) {
166        var index = bookmarks.indexOf(productId);
167        if (index > -1) {
168            bookmarks.splice(index, 1);
169            storeBookmarks(bookmarks);
170
171            let notes = getNotes();
172            delete notes[productHashedId];
173            storeNotes(notes);
174        }
175        $('.bookmarks-index .bookmark[data-product-id="' + productId + '"]').parents('.product-item').slideUp();
176        $('a.bookmark[data-product-id="' + productId + '"]').removeClass('bookmarked');
177    }
178
179    // bookmark products
180    function initializeBookmarkProducts() {
181
182        let bookmarks = getBookmarks();
183        let notes = getNotes();
184
185
186        loadBookmarksOnIndex();
187        updateBookmarkCounter(bookmarks);
188        storeBookmarks(bookmarks);
189        storeNotes(notes);
190
191        $(document).on('click', 'a.bookmark', function (event) {
192            event.preventDefault();
193            var clickedButton = $(this);
194
195            if (clickedButton.hasClass('clear-storage')) {
196                storeBookmarks([]);
197                storeNotes(null);
198                $('#bookmark-counter, .esyluxProductfilterOrigin, .clearStorageTag').hide();
199                $('p.nobookmarks').show(); // Noch keine Artikel hinzugefügt
200            } else if (clickedButton.hasClass('bookmarkAll')) {
201                if (!clickedButton.hasClass('bookmarked')) {
202                    $('a.bookmark:not(.bookmarked)').each(function () {
203                        var productId = $(this).data('productId');
204                        if (productId) {
205                            addBookmark(bookmarks, productId);
206                        }
207                    });
208                    clickedButton.addClass('bookmarked');
209                } else {
210                    $('a.bookmark.bookmarked').each(function () {
211                        let productId = $(this).data('productId');
212                        let productHashedId = $(this).data('productHashedId');
213                        if (productId) {
214                            removeBookmark(bookmarks, productId, productHashedId);
215                        }
216                    });
217                    clickedButton.removeClass('bookmarked');
218                }
219            } else {
220                var productId = clickedButton.data('productId');
221                let productHashedId = clickedButton.data('productHashedId');
222                if (productId) {
223                    if (!clickedButton.hasClass('bookmarked')) {
224                        addBookmark(bookmarks, productId);
225                    } else {
226                        removeBookmark(bookmarks, productId, productHashedId);
227                    }
228                }
229            }
230            bookmarks = getBookmarks();
231            updateBookmarkCounter(bookmarks);
232        });
233
234        let xhr;
235        $('#orderrequest-addproduct-input').autocomplete({
236            search: function (event, ui) {
237                $(event.target).data('productId', '');
238            },
239            source: function (request, response) {
240                xhr && xhr.abort();
241                xhr = $.ajax({
242                    url: ($('#configuration').data('baseuri') || '/')
243                        + '?type=1619162552',
244                    dataType: 'json',
245                    data: {
246                        'term': request.term,
247                        'allowArchived': 0
248                    },
249                    success: function (data) {
250                        response(data.suggestions);
251                    }
252                });
253            },
254            minLength: 2,
255            select: function (event, ui) {
256                if (ui.item.value && ui.item.id) {
257                    $('.orderrequest-addproduct').prop("disabled", false);
258                    $(event.target)
259                        .data('productId', ui.item.id)
260                        .data('productLabel', ui.item.label);
261                }
262            }
263        });
264
265        $('.orderrequest-addproduct').click(function (event) {
266            event.preventDefault();
267            let input = $(this)
268                .closest('form')
269                .find('.esylux-addproduct-input');
270            let productId = input.data('productId');
271            if (productId !== "" && typeof productId !== 'undefined') {
272                $('.orderrequest-addproduct').prop("disabled", true);
273                $('.orderrequest-loading-addproduct').show();
274                $(input).val('').data('productId', '');
275                $.ajax({
276                    method: 'POST',
277                    url: ($('#configuration').data('baseuri') || '/')
278                        + '?type=1652368817',
279                    data: {
280                        'tx_esylux_bookmark[productId]': productId,
281                        'tx_esylux_bookmark[action]': 'orderRequestAddProduct'
282                    },
283                    success: function (response) {
284                        if (response) {
285                            $(response).hide().insertBefore('.orderrequest-loading-addproduct').slideDown();
286                        }
287                    },
288                    complete: function () {
289                        $('.orderrequest-loading-addproduct').hide();
290                    }
291                });
292            }
293            return false;
294        });
295
296        $('.orderrequest-product-remove').click(function (event) {
297            event.preventDefault();
298            $(this).parents('.orderrequest-product').slideUp(function () {
299                $(this).remove();
300            });
301        });
302
303        $('form[name=orderRequest] .submit').click(function () {
304            if ($('form[name=orderRequest]').find('.orderrequest-product').length === 0) {
305                $('.esylux-addproduct-input').prop('required', true);
306            } else {
307                $('.esylux-addproduct-input').removeProp('required');
308            }
309        })
310
311    }
312    // checks if functional cookies are allowed
313    function optInSet(){
314        const cookieValue = "functional:1";
315        const cookieString = document.cookie.split(';').toString();
316        const indexOfFirst = cookieString.indexOf(cookieValue);
317        const optInCookie = indexOfFirst + 1;
318
319
320        // opt-in Zustand überprüfen
321        if (optInCookie) {
322            return true; // opt-in gesetzt
323
324        } else {
325            return false; // opt-in nicht gesetzt
326        }
327    }
328
329    $(document).ready(function () {
330        if(optInSet()){
331            initializeBookmarkProducts();
332            $('.nav-item.bookmark').css({
333                'display' : 'inline-block'
334            });
335        } else {
336            $('.nav-item.bookmark').hide();
337            $(document).on('click', 'a.bookmark', function (event) {
338                event.preventDefault();
339                $('.cookie-consent-user-info').addClass('active');
340            });
341        }
342    });
343})(jQuery, ResponsiveBootstrapToolkit);

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.