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