PageSourceSearch

https://www.kronplatz.com/cache-buster-1785761361/bundles/destisui…/html/src/js/components/watchlist_common.js

js kronplatz.com collected 2026-10-01 12:19:08 UTC 7,371 bytes, 251 lines download raw bytes

1var setWatchlistCookie = function (o, i) {
2    var e = "watchlist_cookie";
3    var n = new Date;
4    i = 30;
5
6    n.setTime(n.getTime() + 24 * i * 60 * 60 * 1000);
7    var t = "expires=" + n.toUTCString(),
8        c = "path=/ ";
9    document.cookie = e + "=" + o + "; " + t + "; " + c;
10};
11window.ds_setWatchlistCookie = setWatchlistCookie;
12var getWatchlistCookie = function() {
13    var cname = "watchlist_cookie";
14
15    var name = cname + "=";
16    var ca = document.cookie.split(';');
17    for(var i=0; i<ca.length; i++) {
18        var c = ca[i];
19        while (c.charAt(0)==' ') {
20            c = c.substring(1);
21        }
22        if (c.indexOf(name) == 0) {
23            return c.substring(name.length, c.length);
24        }
25    }
26    return "";
27};
28var checkWatchlistCookie = function() {
29    var e = getWatchlistCookie();
30    return e ? !0 : !1
31};
32var getWatchlistCookies_keys = function() {
33    var cookie = getWatchlistCookie();
34    cookie = JSON.parse(cookie);
35
36    if (!Array.isArray( cookie )) {
37        return [];
38    }
39
40    return cookie;
41};
42window.ds_getWatchlistCookies_keys = getWatchlistCookies_keys;
43
44
45if (!checkWatchlistCookie()) {
46    setWatchlistCookie(JSON.stringify([]), 1);
47}
48
49var updateWatchlistCounter = function() {
50    var watchlistKeys = getWatchlistCookies_keys();
51    
52    document.querySelectorAll('.js-watchlist-counter').forEach((anfrageCounter, i) => {
53        
54        anfrageCounter.innerHTML = watchlistKeys.length;
55        anfrageCounter.classList.add('pulse');
56        var counterOuter = anfrageCounter.closest('.js-watchlist-counter-outer');
57
58        setTimeout(function(){
59            anfrageCounter.classList.remove('pulse');
60        }, 1500);
61        if (watchlistKeys.length >  0) {
62            anfrageCounter.classList.remove('d-none');
63        } else {
64            anfrageCounter.classList.add('d-none');
65        }
66        
67        if (counterOuter) {
68            if (watchlistKeys.length >  0) {
69                counterOuter.classList.add('ds-active');
70            } else {
71                counterOuter.classList.remove('ds-active');
72            }
73        }
74    
75    })
76}; 
77
78
79var checkKeyInWatchlist = function(key) {
80    var cookie = getWatchlistCookie();
81    cookie = JSON.parse(cookie);
82
83    if (Array.isArray( cookie )) {
84        for (var i = 0; i < cookie.length; i++) {
85            if (cookie[i] == key) {
86                return true;
87            }
88        }
89    }
90
91    return false;
92};
93
94var toggleKeyInWatchlist = function(key) {
95    var isInCookie = checkKeyInWatchlist(key);
96    var cookie = getWatchlistCookie();
97    cookie = JSON.parse(cookie);
98
99    if (!Array.isArray( cookie )) {
100        cookie = [];
101    }
102
103    if ( !isInCookie ) {
104        cookie.push( key );
105        setWatchlistCookie(JSON.stringify( cookie ), 1);
106    } else {
107        // remove the id from array
108        var newCookie = [];
109        for (var i = 0; i < cookie.length; i++) {
110            if (cookie[i] != key) {
111                newCookie.push( cookie[i] );
112            }
113        }
114        setWatchlistCookie(JSON.stringify( newCookie ), 1);
115    }
116
117    watchlistKeys = getWatchlistCookies_keys();
118
119    return false;
120};
121
122/////////////////////////
123/////////////////////////
124/////////////////////////
125/////////////////////////
126
127
128var updateWatchlistToggleAccoButton = function() {
129    
130    document.querySelectorAll('.js-watchlist-toggle-acco').forEach(($this, i) => {
131    
132        var watchlistKey = $this.getAttribute('data-watchlist-key');
133
134        var content = null;
135        if (checkKeyInWatchlist(watchlistKey)){
136            content = $this.getAttribute('data-watchlist-remove-content');
137        } else {
138            content = $this.getAttribute('data-watchlist-add-content');
139        }
140
141        $this.innerHTML = content;
142    });
143    
144};
145
146var updateWatchlistToggleButton = function() {
147    
148    document.querySelectorAll('.js-watchlist-toggle').forEach(($this, i) => {
149        var watchlistKey = $this.getAttribute('data-watchlist-key');
150
151        var icon = null;
152        var content = null;
153        if (checkKeyInWatchlist(watchlistKey)){
154            icon = $this.getAttribute('data-watchlist-remove-icon');
155            content = $this.getAttribute('data-watchlist-remove-content');
156            $this.classList.add('ds-active');
157        } else {
158            icon = $this.getAttribute('data-watchlist-add-icon');
159            content = $this.getAttribute('data-watchlist-add-content');
160            $this.classList.remove('ds-active');
161        }
162
163        if (icon) {
164            $this.querySelectorAll('i').forEach(($this_i, i) => {
165                $this_i.setAttribute('class', icon);
166            });
167        }
168        
169        if (content) {
170            $this.innerHTML = content;
171        }
172    });
173    
174};
175
176
177var onWatchlistToggleChanged = function(callback) {
178    updateWatchlistToggleAccoButton();
179    updateWatchlistToggleButton();
180    updateWatchlistCounter();
181
182    if (typeof callback == 'function') {
183        callback();
184    }
185};
186onWatchlistToggleChanged();
187document.addEventListener("DOMContentLoaded", function(){onWatchlistToggleChanged();})
188window.ds_onWatchlistToggleChanged = onWatchlistToggleChanged;
189
190
191
192document.addEventListener('click', function(event) {
193    var el = null;
194    var searchedTarget = null;
195    var targetTmp = null;
196    
197    if (typeof event.target != 'undefined') {
198        targetTmp = event.target;
199        if (targetTmp.classList && (targetTmp.classList.contains('js-watchlist-toggle') || targetTmp.classList.contains('js-watchlist-toggle-acco'))) {
200            searchedTarget = targetTmp;
201        }
202    }
203    while (searchedTarget == null && targetTmp && targetTmp.parentNode != null) {
204        targetTmp = targetTmp.parentNode;
205        if (targetTmp.classList && (targetTmp.classList.contains('js-watchlist-toggle') || targetTmp.classList.contains('js-watchlist-toggle-acco'))) {
206            searchedTarget = targetTmp;
207        }
208    }
209        
210
211    
212    if (searchedTarget != null) {
213        event.preventDefault();
214        var el = searchedTarget;
215        var watchlistKey = el.getAttribute('data-watchlist-key');
216        toggleKeyInWatchlist( watchlistKey );
217        
218        // gtm tracking - event binding
219        if (el.getAttribute('data-gtm-el') && 
220            typeof window.ds_track != 'undefined' && typeof window.ds_track.wishlist != 'undefined' && typeof window.ds_track.wishlist.add != 'undefined'
221        ) {
222            if (checkKeyInWatchlist(watchlistKey)){
223                var gtmEl = JSON.parse( el.getAttribute('data-gtm-el') );
224                var listId = '';
225                var listName = '';
226                
227                var domTmp = el.closest('[data-gtm-list-id]');
228                if (domTmp) {
229                    listId = domTmp.getAttribute('data-gtm-list-id');
230                }
231                domTmp = el.closest('[data-gtm-list-name]');
232                if (domTmp) {
233                    listName = domTmp.getAttribute('data-gtm-list-name');
234                }
235                window.ds_track.wishlist.add(gtmEl, listId, listName);
236            }
237        }
238
239        var callback = null;
240        
241        document.querySelectorAll('.js-wishlist-container').forEach((wishlistContainerEl, i) => {
242            callback = function(){
243                window.location.reload();
244            };
245        });
246        
247        onWatchlistToggleChanged(callback);
248    }
249    
250}, false);
251

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.