PageSourceSearch

https://techmkt.pro/wp-content/plugins/woo-smart-wishlist-premium/assets/js/frontend.js?ver=5.0.2

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