PageSourceSearch

https://ughe.org/wp-content/plugins/woo-smart-wishlist/assets/js/frontend.js?ver=6.0.0

js ughe.org collected 2026-09-24 17:39:53 UTC 31,503 bytes, 891 lines download raw bytes

1'use strict';
2
3(function ($) {
4    var $storage = true;
5    var added_ids = [];
6    var key = Cookies.get('woosw_key');
7
8    try {
9        $storage = ('sessionStorage' in window && window.sessionStorage !== null);
10        window.sessionStorage.setItem('woosw', 'test');
11        window.sessionStorage.removeItem('woosw');
12    } catch (err) {
13        $storage = false;
14    }
15
16    $(function () {
17        if (key === null || key === undefined || key === '') {
18            key = woosw_get_key();
19            Cookies.set('woosw_key', key, {expires: 7});
20        }
21
22        // Load data for the first time
23        woosw_load_data();
24
25        if ($('.woosw-custom-menu-item').length || woosw_vars.reload_count === 'yes') {
26            // reload the count
27            woosw_load_count();
28        }
29
30        if ($('.woosw-list-ajax').length) {
31            // reload the list
32            woosw_load_list();
33        }
34
35        if (woosw_vars.added_to_cart === 'yes' && woosw_vars.auto_remove === 'yes') {
36            setTimeout(function () {
37                woosw_load_count();
38                woosw_get_data();
39            }, 300);
40        }
41
42        if (woosw_vars.button_action === 'message') {
43            $.notiny.addTheme('woosw', {
44                notification_class: 'notiny-theme-woosw',
45            });
46        }
47    });
48
49    $(document).on('change', '.woosw-switcher-dropdown', function () {
50        window.location = $(this).val();
51    });
52
53    $(document).on('woosw_refresh_data', function () {
54        woosw_get_data();
55    });
56
57    $(document).on('woosw_refresh_count', function () {
58        woosw_load_count();
59    });
60
61    // woovr
62    $(document).on('woovr_selected', function (e, selected, variations) {
63        var id = selected.attr('data-id');
64        var pid = selected.attr('data-pid');
65
66        if (id > 0) {
67            $('.woosw-btn-' + pid).attr('data-id', id).removeClass('woosw-btn-added woosw-added');
68
69            // refresh button
70            woosw_refresh_button_id(id);
71        } else {
72            $('.woosw-btn-' + pid).attr('data-id', pid).removeClass('woosw-btn-added woosw-added');
73
74            // refresh button
75            woosw_refresh_button_id(pid);
76        }
77    });
78
79    // found variation
80    $(document).on('found_variation', function (e, t) {
81        var product_id = $(e['target']).attr('data-product_id');
82
83        // change id
84        $('.woosw-btn-' + product_id).attr('data-id', t.variation_id).removeClass('woosw-btn-added woosw-added');
85
86        // refresh button
87        woosw_refresh_button_id(t.variation_id);
88    });
89
90    // reset data
91    $(document).on('reset_data', function (e) {
92        var product_id = $(e['target']).attr('data-product_id');
93
94        // change id
95        $('.woosw-btn-' + product_id).attr('data-id', product_id).removeClass('woosw-btn-added woosw-added');
96
97        // refresh button
98        woosw_refresh_button_id(product_id);
99    });
100
101    // auto remove
102    $(document.body).on('added_to_cart', function (e, fragments, cart_hash, $button) {
103        if (woosw_vars.auto_remove === 'yes') {
104            var product_id = parseInt($button.data('product_id'));
105
106            if ((product_id > 0) && $('.woosw-item-' + product_id).length) {
107                $('.woosw-item-' + product_id).remove();
108            }
109
110            woosw_load_count();
111            woosw_get_data();
112        }
113    });
114
115    // quick view
116    $(document).on('click touch', '#woosw_wishlist .woosq-link, #woosw_wishlist .woosq-btn', function (e) {
117        woosw_wishlist_hide();
118        e.preventDefault();
119    });
120
121    // add to wishlist
122    $(document).on('click touch', '.woosw-btn', function (e) {
123        var $this = $(this);
124        var id = $this.attr('data-id');
125        var pid = $this.attr('data-pid');
126        var product_id = $this.attr('data-product_id');
127        var product_name = $this.attr('data-product_name');
128        var product_image = $this.attr('data-product_image');
129
130        if (typeof pid !== typeof undefined && pid !== false) {
131            id = pid;
132        }
133
134        if (typeof product_id !== typeof undefined && product_id !== false) {
135            id = product_id;
136        }
137
138        if ($this.hasClass('woosw-added')) {
139            if (woosw_vars.button_action_added === 'remove') {
140                // remove from  wishlist
141                var data = {
142                    action: 'woosw_remove', product_id: id, key: key, nonce: woosw_vars.nonce,
143                };
144
145                $this.addClass('woosw-adding').find('.woosw-btn-icon').removeClass(woosw_vars.button_normal_icon + ' ' + woosw_vars.button_added_icon).addClass(woosw_vars.button_loading_icon);
146
147                $.post(woosw_vars.wc_ajax_url.toString().replace('%%endpoint%%', 'woosw_remove'), data, function (response) {
148                    $this.removeClass('woosw-adding').find('.woosw-btn-icon').removeClass(woosw_vars.button_loading_icon);
149
150                    if (response.content != null) {
151                        $('#woosw_wishlist').html(response.content).addClass('woosw-loaded');
152                    }
153
154                    if (response.notice != null) {
155                        woosw_notice(response.notice);
156                    }
157
158                    if (response.count != null) {
159                        woosw_change_count(response.count);
160                    }
161
162                    if ($storage && response.data) {
163                        sessionStorage.setItem('woosw_data_' + response.data.key, JSON.stringify(response.data));
164                    }
165
166                    if (response.data.fragments) {
167                        woosw_refresh_fragments(response.data.fragments);
168                    }
169
170                    if (response.data.ids) {
171                        woosw_refresh_buttons(response.data.ids);
172                        woosw_refresh_ids(response.data.ids);
173                    }
174
175                    $(document.body).trigger('woosw_remove', [product_id]);
176                });
177            } else if (woosw_vars.button_action_added === 'page') {
178                // open wishlist page
179                window.location.href = woosw_vars.wishlist_url;
180            } else {
181                // open wishlist popup
182                if ($('#woosw_wishlist').hasClass('woosw-loaded')) {
183                    woosw_wishlist_show();
184                } else {
185                    woosw_wishlist_load();
186                }
187            }
188        } else {
189            // add product
190            var data = {
191                action: 'woosw_add', product_id: id, nonce: woosw_vars.nonce,
192            };
193
194            $this.addClass('woosw-adding').find('.woosw-btn-icon').removeClass(woosw_vars.button_normal_icon + ' ' + woosw_vars.button_added_icon).addClass(woosw_vars.button_loading_icon);
195
196            $.post(woosw_vars.wc_ajax_url.toString().replace('%%endpoint%%', 'woosw_add'), data, function (response) {
197                $this.removeClass('woosw-adding').find('.woosw-btn-icon').removeClass(woosw_vars.button_loading_icon);
198
199                if (woosw_vars.button_action === 'list') {
200                    if (response.content != null) {
201                        $('#woosw_wishlist').html(response.content).addClass('woosw-loaded');
202                    }
203
204                    if (response.notice != null) {
205                        woosw_notice(response.notice.replace('{name}', '<strong>' + product_name + '</strong>'));
206                    }
207
208                    woosw_perfect_scrollbar();
209                    woosw_wishlist_show();
210                }
211
212                if (woosw_vars.button_action === 'message') {
213                    $('#woosw_wishlist').removeClass('woosw-loaded');
214
215                    $.notiny({
216                        theme: 'woosw',
217                        position: woosw_vars.message_position,
218                        image: product_image,
219                        text: response.notice.replace('{name}', '<strong>' + product_name + '</strong>'),
220                    });
221                }
222
223                if (woosw_vars.button_action === 'no') {
224                    // add to the wishlist solely
225                    $('#woosw_wishlist').removeClass('woosw-loaded');
226                }
227
228                if (response.count != null) {
229                    woosw_change_count(response.count);
230                }
231
232                if (response.status === 1) {
233                    woosw_refresh_button_id(id);
234                }
235
236                if ($storage && response.data) {
237                    sessionStorage.setItem('woosw_data_' + response.data.key, JSON.stringify(response.data));
238                }
239
240                if (response.data.fragments) {
241                    woosw_refresh_fragments(response.data.fragments);
242                }
243
244                if (response.data.ids) {
245                    woosw_refresh_buttons(response.data.ids);
246                    woosw_refresh_ids(response.data.ids);
247                }
248
249                $(document.body).trigger('woosw_add', [id]);
250            });
251        }
252
253        e.preventDefault();
254    });
255
256    // add product
257    $(document).on('click touch', '.woosw-item--add span', function (e) {
258        var $this = $(this);
259        var key = $this.closest('.woosw-items').data('key');
260        var $this_item = $this.closest('.woosw-item');
261        var product_id = $this_item.attr('data-id');
262        var product_name = $this_item.attr('data-product_name');
263        var data = {
264            action: 'woosw_add', product_id: product_id, key: key, nonce: woosw_vars.nonce,
265        };
266
267        $this.addClass('woosw-item--adding');
268
269        $.post(woosw_vars.wc_ajax_url.toString().replace('%%endpoint%%', 'woosw_add'), data, function (response) {
270            $this.addClass('woosw-item--adding');
271
272            if (response.content != null) {
273                $('#woosw_wishlist').html(response.content).addClass('woosw-loaded');
274            }
275
276            if (response.notice != null) {
277                woosw_notice(response.notice.replace('{name}', '<strong>' + product_name + '</strong>'));
278            }
279
280            if (response.count != null) {
281                woosw_change_count(response.count);
282            }
283
284            if ($storage && response.data) {
285                sessionStorage.setItem('woosw_data_' + response.data.key, JSON.stringify(response.data));
286            }
287
288            if (response.data.fragments) {
289                woosw_refresh_fragments(response.data.fragments);
290            }
291
292            if (response.data.ids) {
293                woosw_refresh_buttons(response.data.ids);
294                woosw_refresh_ids(response.data.ids);
295            }
296
297            $(document.body).trigger('woosw_add', [product_id]);
298
299            // list shortcode
300            if ($this.closest('.woosw-list').length) {
301                location.reload();
302            }
303        });
304
305        e.preventDefault();
306    });
307
308    // remove product
309    $(document).on('click touch', '.woosw-item--remove span', function (e) {
310        var $this = $(this);
311        var key = $this.closest('.woosw-items').data('key');
312        var $this_item = $this.closest('.woosw-item');
313        var product_id = $this_item.attr('data-id');
314        var data = {
315            action: 'woosw_remove', product_id: product_id, key: key, nonce: woosw_vars.nonce,
316        };
317
318        $this.addClass('woosw-item--removing');
319
320        $.post(woosw_vars.wc_ajax_url.toString().replace('%%endpoint%%', 'woosw_remove'), data, function (response) {
321            $this.removeClass('woosw-item--removing');
322            $this_item.remove();
323
324            if (response.content != null) {
325                $('#woosw_wishlist').html(response.content).addClass('woosw-loaded');
326            }
327
328            if (response.notice != null) {
329                woosw_notice(response.notice);
330            }
331
332            if (response.count != null) {
333                woosw_change_count(response.count);
334            }
335
336            if ($storage && response.data) {
337                sessionStorage.setItem('woosw_data_' + response.data.key, JSON.stringify(response.data));
338            }
339
340            if (response.data.fragments) {
341                woosw_refresh_fragments(response.data.fragments);
342            }
343
344            if (response.data.ids) {
345                woosw_refresh_buttons(response.data.ids);
346                woosw_refresh_ids(response.data.ids);
347            }
348
349            $(document.body).trigger('woosw_remove', [product_id]);
350        });
351
352        e.preventDefault();
353    });
354
355    // empty wishlist
356    $(document).on('click touch', '.woosw-empty', function (e) {
357        var $this = $(this);
358
359        if (confirm(woosw_vars.empty_confirm)) {
360            woosw_popup_loading();
361
362            var key = $this.data('key');
363            var data = {
364                action: 'woosw_empty', key: key, nonce: woosw_vars.nonce,
365            };
366
367            $.post(woosw_vars.wc_ajax_url.toString().replace('%%endpoint%%', 'woosw_empty'), data, function (response) {
368                if (response.content != null) {
369                    $('#woosw_wishlist').html(response.content).addClass('woosw-loaded');
370                }
371
372                if (response.notice != null) {
373                    woosw_notice(response.notice);
374                }
375
376                if (response.count != null) {
377                    woosw_change_count(response.count);
378                }
379
380                if ($storage && response.data) {
381                    sessionStorage.setItem('woosw_data_' + response.data.key, JSON.stringify(response.data));
382                }
383
384                if (response.data.fragments) {
385                    woosw_refresh_fragments(response.data.fragments);
386                }
387
388                if (response.data.ids) {
389                    woosw_refresh_buttons(response.data.ids);
390                    woosw_refresh_ids(response.data.ids);
391                }
392
393                woosw_popup_loaded();
394
395                $(document.body).trigger('woosw_empty', [key]);
396            });
397        }
398
399        e.preventDefault();
400    });
401
402    // click on area
403    $(document).on('click touch', '.woosw-popup', function (e) {
404        var woosw_content = $('.woosw-popup-content');
405
406        if (!$(e.target).closest(woosw_content).length) {
407            woosw_wishlist_hide();
408            woosw_manage_hide();
409        }
410    });
411
412    // continue
413    $(document).on('click touch', '.woosw-continue', function (e) {
414        var url = $(this).attr('data-url');
415        woosw_wishlist_hide();
416
417        if (url !== '') {
418            window.location.href = url;
419        }
420
421        e.preventDefault();
422    });
423
424    // close
425    $(document).on('click touch', '#woosw_wishlist .woosw-popup-close', function (e) {
426        woosw_wishlist_hide();
427        e.preventDefault();
428    });
429
430    // manage close
431    $(document).on('click touch', '#woosw_manage .woosw-popup-close', function (e) {
432        woosw_manage_hide();
433        e.preventDefault();
434    });
435
436    // manage wishlists
437    $(document).on('click touch', '.woosw-manage', function (e) {
438        e.preventDefault();
439        woosw_popup_loading();
440
441        var data = {
442            action: 'woosw_manage_wishlists', nonce: woosw_vars.nonce,
443        };
444
445        $.post(woosw_vars.wc_ajax_url.toString().replace('%%endpoint%%', 'woosw_manage_wishlists'), data, function (response) {
446            woosw_wishlist_hide();
447            $('#woosw_manage').html(response);
448            woosw_manage_show();
449            woosw_popup_loaded();
450        });
451    });
452
453    // add wishlist
454    $(document).on('click touch', '#woosw_add_wishlist', function (e) {
455        e.preventDefault();
456        woosw_popup_loading();
457
458        var name = $('#woosw_wishlist_name').val();
459        var data = {
460            action: 'woosw_add_wishlist', name: name, nonce: woosw_vars.nonce,
461        };
462
463        $.post(woosw_vars.wc_ajax_url.toString().replace('%%endpoint%%', 'woosw_add_wishlist'), data, function (response) {
464            $('#woosw_manage').html(response);
465            $('#woosw_wishlist').removeClass('woosw-loaded');
466            woosw_popup_loaded();
467        });
468    });
469
470    // set default
471    $(document).on('click touch', '.woosw-set-default', function (e) {
472        e.preventDefault();
473        woosw_popup_loading();
474
475        var key = $(this).data('key');
476        var data = {
477            action: 'woosw_set_default', key: key, nonce: woosw_vars.nonce,
478        };
479
480        $.post(woosw_vars.wc_ajax_url.toString().replace('%%endpoint%%', 'woosw_set_default'), data, function (response) {
481            if (response.count != null) {
482                woosw_change_count(response.count);
483            }
484
485            if ((response.products != null) && response.products.length) {
486                response.products.forEach((product_id) => {
487                    woosw_refresh_button_id(product_id);
488                });
489            }
490
491            $('#woosw_manage').html(response.content);
492
493            if ($storage && response.data) {
494                sessionStorage.setItem('woosw_data_' + response.data.key, JSON.stringify(response.data));
495            }
496
497            if (response.data.fragments) {
498                woosw_refresh_fragments(response.data.fragments);
499            }
500
501            if (response.data.ids) {
502                woosw_refresh_buttons(response.data.ids);
503                woosw_refresh_ids(response.data.ids);
504            }
505
506            $('#woosw_wishlist').removeClass('woosw-loaded');
507            woosw_popup_loaded();
508        });
509    });
510
511    // delete wishlist
512    $(document).on('click touch', '.woosw-delete-wishlist', function (e) {
513        e.preventDefault();
514
515        if (confirm(woosw_vars.delete_confirm)) {
516            woosw_popup_loading();
517
518            var key = $(this).data('key');
519            var data = {
520                action: 'woosw_delete_wishlist', key: key, nonce: woosw_vars.nonce,
521            };
522
523            $.post(woosw_vars.wc_ajax_url.toString().replace('%%endpoint%%', 'woosw_delete_wishlist'), data, function (response) {
524                $('#woosw_manage').html(response);
525                $('#woosw_wishlist').removeClass('woosw-loaded');
526                woosw_popup_loaded();
527            });
528        }
529    });
530
531    // view wishlist
532    $(document).on('click touch', '.woosw-view-wishlist', function (e) {
533        e.preventDefault();
534        woosw_popup_loading();
535
536        var key = $(this).data('key');
537        var data = {
538            action: 'woosw_view_wishlist', key: key, nonce: woosw_vars.nonce,
539        };
540
541        $.post(woosw_vars.wc_ajax_url.toString().replace('%%endpoint%%', 'woosw_view_wishlist'), data, function (response) {
542            woosw_manage_hide();
543            $('#woosw_wishlist').removeClass('woosw-loaded').html(response);
544            woosw_wishlist_show();
545            woosw_popup_loaded();
546        });
547    });
548
549    // menu item
550    $(document).on('click touch', '.woosw-menu-item a, .woosw-menu a, .woosw-link.woosw-link-auto a', function (e) {
551        if (woosw_vars.menu_action === 'open_popup') {
552            e.preventDefault();
553
554            if ($('#woosw_wishlist').hasClass('woosw-loaded')) {
555                woosw_wishlist_show();
556            } else {
557                woosw_wishlist_load();
558            }
559        }
560    });
561
562    // link popup
563    $(document).on('click touch', '.woosw-link.woosw-link-popup a', function (e) {
564        e.preventDefault();
565
566        if ($('#woosw_wishlist').hasClass('woosw-loaded')) {
567            woosw_wishlist_show();
568        } else {
569            woosw_wishlist_load();
570        }
571    });
572
573    // account link
574    $(document).on('click touch', '.woocommerce-MyAccount-navigation-link--wishlist a', function (e) {
575        if (woosw_vars.page_myaccount === 'yes_popup') {
576            e.preventDefault();
577
578            if ($('#woosw_wishlist').hasClass('woosw-loaded')) {
579                woosw_wishlist_show();
580            } else {
581                woosw_wishlist_load();
582            }
583        }
584    });
585
586    // copy link
587    $(document).on('click touch', '#woosw_copy_url, #woosw_copy_btn', function (e) {
588        e.preventDefault();
589        let $link = $('#woosw_copy_url');
590        let link = $link.val();
591
592        navigator.clipboard.writeText(link).then(function () {
593            alert(woosw_vars.copied_text + ' ' + link);
594        }, function () {
595            alert('Failure to copy!');
596        });
597
598        $link.select();
599    });
600
601    // add note
602    $(document).on('click touch', '.woosw-item--note', function () {
603        if ($(this).closest('.woosw-item').find('.woosw-item--note-add').length) {
604            $(this).closest('.woosw-item').find('.woosw-item--note-add').show();
605            $(this).hide();
606        }
607    });
608
609    $(document).on('click touch', '.woosw_add_note', function (e) {
610        e.preventDefault();
611        woosw_popup_loading();
612
613        var $this = $(this);
614        var key = $this.closest('.woosw-items').data('key');
615        var product_id = $this.closest('.woosw-item').attr('data-id');
616        var note = $this.closest('.woosw-item').find('input[type="text"]').val();
617        var data = {
618            action: 'woosw_add_note',
619            key: key,
620            product_id: product_id,
621            note: woosw_html_entities(note),
622            nonce: woosw_vars.nonce,
623        };
624
625        $.post(woosw_vars.wc_ajax_url.toString().replace('%%endpoint%%', 'woosw_add_note'), data, function (response) {
626            $this.closest('.woosw-item').find('.woosw-item--note').html(response).show();
627            $this.closest('.woosw-item').find('.woosw-item--note-add').hide();
628            woosw_popup_loaded();
629        });
630    });
631
632    // resize
633    $(window).on('resize', function () {
634        woosw_fix_height();
635    });
636
637    function woosw_wishlist_load() {
638        var data = {
639            action: 'woosw_load', nonce: woosw_vars.nonce,
640        };
641
642        $.post(woosw_vars.wc_ajax_url.toString().replace('%%endpoint%%', 'woosw_load'), data, function (response) {
643            if (response.content != null) {
644                $('#woosw_wishlist').html(response.content);
645            }
646
647            if (response.count != null) {
648                if ($('#woosw_wishlist .woosw-items:not(.woosw-suggested-items) .woosw-item').length && ($('#woosw_wishlist .woosw-items:not(.woosw-suggested-items) .woosw-item').length != response.count)) {
649                    woosw_change_count($('#woosw_wishlist .woosw-items:not(.woosw-suggested-items) .woosw-item').length);
650                } else {
651                    woosw_change_count(response.count);
652                }
653            }
654
655            if (response.notice != null) {
656                woosw_notice(response.notice);
657            }
658
659            $('#woosw_wishlist').addClass('woosw-loaded');
660
661            woosw_perfect_scrollbar();
662            woosw_wishlist_show();
663        });
664    }
665
666    function woosw_load_count() {
667        var data = {
668            action: 'woosw_load_count', nonce: woosw_vars.nonce,
669        };
670
671        $.post(woosw_vars.wc_ajax_url.toString().replace('%%endpoint%%', 'woosw_load_count'), data, function (response) {
672            if (response.count != null) {
673                var count = response.count;
674
675                woosw_change_count(count);
676                $(document.body).trigger('woosw_load_count', [count]);
677            }
678        });
679    }
680
681    function woosw_load_list() {
682        var data = {
683            action: 'woosw_load_list', nonce: woosw_vars.nonce,
684        };
685
686        $.post(woosw_vars.wc_ajax_url.toString().replace('%%endpoint%%', 'woosw_load_list'), data, function (response) {
687            if (response.list != null) {
688                $('.woosw-list-ajax').replaceWith(response.list);
689            }
690        });
691    }
692
693    function woosw_wishlist_show() {
694        $('#woosw_wishlist').addClass('woosw-show');
695        woosw_fix_height();
696
697        $(document.body).trigger('woosw_wishlist_show');
698    }
699
700    function woosw_wishlist_hide() {
701        $('#woosw_wishlist').removeClass('woosw-show');
702        $(document.body).trigger('woosw_wishlist_hide');
703    }
704
705    function woosw_manage_show() {
706        $('#woosw_manage').addClass('woosw-show');
707        $(document.body).trigger('woosw_manage_show');
708    }
709
710    function woosw_manage_hide() {
711        $('#woosw_manage').removeClass('woosw-show');
712        $(document.body).trigger('woosw_manage_hide');
713    }
714
715    function woosw_popup_loading() {
716        $('.woosw-popup').addClass('woosw-loading');
717    }
718
719    function woosw_popup_loaded() {
720        $('.woosw-popup').removeClass('woosw-loading');
721    }
722
723    function woosw_change_count(count) {
724        $('#woosw_wishlist .woosw-count').html(count);
725        $('.woosw-link .woosw-link-inner').attr('data-count', count);
726
727        if (parseInt(count) > 0) {
728            $('.woosw-empty').show();
729        } else {
730            $('.woosw-empty').hide();
731        }
732
733        if ($('.woosw-menu-item .woosw-menu-item-inner').length) {
734            $('.woosw-menu-item .woosw-menu-item-inner').attr('data-count', count);
735        } else {
736            $('.woosw-menu-item a').html('<span class="woosw-menu-item-inner" data-count="' + count + '"><i class="woosw-icon"></i><span>' + woosw_vars.menu_text + '</span></span>');
737        }
738
739        $(document.body).trigger('woosw_change_count', [count]);
740    }
741
742    function woosw_notice(notice) {
743        $('.woosw-notice').html(notice);
744        woosw_notice_show();
745        setTimeout(function () {
746            woosw_notice_hide();
747        }, 3000);
748    }
749
750    function woosw_notice_show() {
751        $('#woosw_wishlist .woosw-notice').addClass('woosw-notice-show');
752    }
753
754    function woosw_notice_hide() {
755        $('#woosw_wishlist .woosw-notice').removeClass('woosw-notice-show');
756    }
757
758    function woosw_perfect_scrollbar() {
759        if (woosw_vars.perfect_scrollbar === 'yes') {
760            jQuery('#woosw_wishlist .woosw-popup-content-mid').perfectScrollbar({theme: 'wpc'});
761        }
762    }
763
764    function woosw_html_entities(str) {
765        return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
766    }
767
768    function woosw_get_key() {
769        var result = [];
770        var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
771        var charactersLength = characters.length;
772
773        for (var i = 0; i < 6; i++) {
774            result.push(characters.charAt(Math.floor(Math.random() * charactersLength)));
775        }
776
777        return result.join('');
778    }
779
780    function woosw_fix_height() {
781        // fix for center only
782        jQuery('.woosw-popup-center .woosw-popup-content').height(2 * Math.floor(jQuery('.woosw-popup-center .woosw-popup-content').height() / 2) + 2);
783    }
784
785    function woosw_load_data() {
786        if ($storage) {
787            try {
788                var data = JSON.parse(sessionStorage.getItem('woosw_data_' + key));
789
790                if (data.fragments) {
791                    woosw_refresh_fragments(data.fragments);
792                }
793
794                if (data.ids) {
795                    woosw_refresh_buttons(data.ids);
796                    woosw_refresh_ids(data.ids);
797                }
798
799                if (data.key && (key === null || key === undefined || key === '')) {
800                    Cookies.set('woosw_key', data.key, {expires: 7});
801                }
802            } catch (err) {
803                woosw_get_data();
804            }
805        } else {
806            woosw_get_data();
807        }
808    }
809
810    function woosw_get_data() {
811        var data = {
812            action: 'woosw_get_data', nonce: woosw_vars.nonce,
813        };
814
815        $.post(woosw_vars.wc_ajax_url.toString().replace('%%endpoint%%', 'woosw_get_data'), data, function (response) {
816            if (response) {
817                if ($storage) {
818                    sessionStorage.setItem('woosw_data_' + response.key, JSON.stringify(response));
819                }
820
821                if (response.fragments) {
822                    woosw_refresh_fragments(response.fragments);
823                }
824
825                if (response.ids) {
826                    woosw_refresh_buttons(response.ids);
827                    woosw_refresh_ids(response.ids);
828                }
829
830                if (response.key && (key === null || key === undefined || key === '' || key !== response.key)) {
831                    Cookies.set('woosw_key', response.key, {expires: 7});
832                }
833
834                $(document.body).trigger('woosw_data_refreshed', [response]);
835            }
836        });
837    }
838
839    function woosw_refresh_fragments(fragments) {
840        $.each(fragments, function (key, value) {
841            $(key).replaceWith(value);
842        });
843
844        $(document.body).trigger('woosw_fragments_refreshed', [fragments]);
845    }
846
847    function woosw_refresh_ids(ids) {
848        added_ids = ids;
849    }
850
851    function woosw_refresh_buttons(ids) {
852        $('.woosw-btn').removeClass('woosw-btn-added woosw-added');
853        $('.woosw-btn:not(.woosw-btn-has-icon)').text(woosw_vars.button_text);
854        $('.woosw-btn.woosw-btn-has-icon').find('.woosw-btn-icon').removeClass(woosw_vars.button_added_icon).addClass(woosw_vars.button_normal_icon);
855        $('.woosw-btn.woosw-btn-has-icon').find('.woosw-btn-text').text(woosw_vars.button_text);
856
857        $.each(ids, function (key, value) {
858            $('.woosw-btn-' + key).addClass('woosw-btn-added woosw-added');
859            $('.woosw-btn-' + key + ':not(.woosw-btn-has-icon)').text(woosw_vars.button_text_added);
860            $('.woosw-btn-has-icon.woosw-btn-' + key).find('.woosw-btn-icon').removeClass(woosw_vars.button_normal_icon).addClass(woosw_vars.button_added_icon);
861            $('.woosw-btn-has-icon.woosw-btn-' + key).find('.woosw-btn-text').text(woosw_vars.button_text_added);
862
863            if (value.parent !== undefined) {
864                $('.woosw-btn-' + value.parent).addClass('woosw-btn-added woosw-added');
865                $('.woosw-btn-' + value.parent + ':not(.woosw-btn-has-icon)').text(woosw_vars.button_text_added);
866                $('.woosw-btn-has-icon.woosw-btn-' + value.parent).find('.woosw-btn-icon').removeClass(woosw_vars.button_normal_icon).addClass(woosw_vars.button_added_icon);
867                $('.woosw-btn-has-icon.woosw-btn-' + value.parent).find('.woosw-btn-text').text(woosw_vars.button_text_added);
868            }
869        });
870
871        $(document.body).trigger('woosw_buttons_refreshed', [ids]);
872    }
873
874    function woosw_refresh_button_id(id) {
875        $('.woosw-btn[data-id="' + id + '"]').removeClass('woosw-btn-added woosw-added');
876        $('.woosw-btn[data-id="' + id + '"]:not(.woosw-btn-has-icon)').text(woosw_vars.button_text);
877        $('.woosw-btn-has-icon.woosw-btn[data-id="' + id + '"]').find('.woosw-btn-icon').removeClass(woosw_vars.button_added_icon).addClass(woosw_vars.button_normal_icon);
878        $('.woosw-btn-has-icon.woosw-btn[data-id="' + id + '"]').find('.woosw-btn-text').text(woosw_vars.button_text);
879
880        $.each(added_ids, function (key) {
881            if (parseInt(key) === parseInt(id)) {
882                $('.woosw-btn[data-id="' + id + '"]').addClass('woosw-btn-added woosw-added');
883                $('.woosw-btn[data-id="' + id + '"]:not(.woosw-btn-has-icon)').text(woosw_vars.button_text_added);
884                $('.woosw-btn-has-icon.woosw-btn[data-id="' + id + '"]').find('.woosw-btn-icon').removeClass(woosw_vars.button_normal_icon).addClass(woosw_vars.button_added_icon);
885                $('.woosw-btn-has-icon.woosw-btn[data-id="' + id + '"]').find('.woosw-btn-text').text(woosw_vars.button_text_added);
886            }
887        });
888
889        $(document.body).trigger('woosw_refresh_button_id', [id, added_ids]);
890    }
891})(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.