1'use strict'; 2 3(function ($) { 4 var woosc_timer = 0; 5 6 // ready 7 $(function () { 8 woosc_color(); 9 woosc_change_count('first'); 10 woosc_check_buttons(); 11 woosc_hide_empty(); 12 woosc_hide_similarities(); 13 woosc_highlight_differences(); 14 15 if (woosc_vars.reload_count === 'yes') { 16 // reload the count 17 woosc_load_data('count'); 18 } 19 20 if (woosc_vars.open_bar === 'yes') { 21 woosc_load_data('bar'); 22 woosc_open_bar(); 23 } 24 25 $('.woosc-settings-fields').sortable({ 26 handle: '.move', update: function (event, ui) { 27 woosc_save_settings(); 28 }, 29 }); 30 31 if (woosc_vars.button_action === 'show_message') { 32 $.notiny.addTheme('woosc', { 33 notification_class: 'notiny-theme-woosc', 34 }); 35 } 36 37 woosc_quick_table(); 38 }); 39 40 // resize 41 $(window).on('resize', function () { 42 woosc_quick_table(); 43 }); 44 45 // quick view 46 $(document).on('click touch', '.woosc_table .woosq-btn, .woosc_table .woosq-link', function (e) { 47 e.preventDefault(); 48 woosc_close(); 49 }); 50 51 $(document).on('click touch', '.woosc-sidebar .woosq-btn, .woosc-sidebar .woosq-link', function (e) { 52 e.preventDefault(); 53 woosc_close_sidebar(); 54 }); 55 56 // settings 57 $(document).on('click touch', '.woosc-table-settings', function (e) { 58 e.preventDefault(); 59 $('.woosc-settings').toggleClass('open'); 60 }); 61 62 $(document).on('click touch', '.woosc-bar-print', function (e) { 63 e.preventDefault(); 64 $.print('#woosc-area'); 65 }); 66 67 $(document).on('change', '#woosc-filter', function (e) { 68 e.preventDefault(); 69 woosc_filter(); 70 }); 71 72 $(document).on('keydown', function (e) { 73 if ((e.ctrlKey == true || e.metaKey == true) && (e.which == '80')) { 74 //ctrl+p or command+p 75 if ($('.woosc-area').hasClass('woosc-area-open-table')) { 76 e.preventDefault(); 77 $.print('#woosc-area'); 78 } 79 } 80 }); 81 82 $(document).on('click touch', '.woosc-bar-share', function (e) { 83 e.preventDefault(); 84 $('.woosc-share').toggleClass('open'); 85 $('.woosc-share-content').addClass('woosc-loading'); 86 87 var data = { 88 action: 'woosc_share', nonce: woosc_vars.nonce, 89 }; 90 91 jQuery.post(woosc_vars.wc_ajax_url.toString().replace('%%endpoint%%', 'woosc_share'), data, function (response) { 92 $('.woosc-share-content').html(response).removeClass('woosc-loading'); 93 }); 94 }); 95 96 // copy link 97 $(document).on('click touch', '#woosc_copy_url, #woosc_copy_btn', function (e) { 98 e.preventDefault(); 99 let $link = $('#woosc_copy_url'); 100 let link = $link.val(); 101 102 navigator.clipboard.writeText(link).then(function () { 103 alert(woosc_vars.copied_text.replace('%s', link)); 104 }, function () { 105 alert('Failure to copy!'); 106 }); 107 108 $link.select(); 109 }); 110 111 // search 112 $(document).on('click touch', '.woosc-bar-search', function (e) { 113 e.preventDefault(); 114 $('.woosc-search').toggleClass('open'); 115 116 if ($('.woosc-search-result').text() === '') { 117 if (woosc_timer != null) { 118 clearTimeout(woosc_timer); 119 } 120 121 woosc_timer = setTimeout(woosc_search, 300); 122 return false; 123 } 124 }); 125 126 // popup 127 $(document).on('click touch', '.woosc-popup', function (e) { 128 if ($(e.target).closest('.woosc-popup-content').length === 0) { 129 $(this).toggleClass('open'); 130 } 131 }); 132 133 $(document).on('keyup', '#woosc_search_input', function () { 134 if ($('#woosc_search_input').val() !== '') { 135 if (woosc_timer != null) { 136 clearTimeout(woosc_timer); 137 } 138 139 woosc_timer = setTimeout(woosc_search, 300); 140 return false; 141 } 142 }); 143
144 $(document).on('click touch', '.woosc-item-add', function (e) { 145 e.preventDefault(); 146 var product_id = $(this).attr('data-id'); 147 148 $('.woosc-search').toggleClass('open'); 149 woosc_add_product(product_id); 150 woosc_load_data('table'); 151 woosc_open_table(); 152 }); 153 154 $(document).on('click touch', '.woosc-popup-close', function (e) { 155 e.preventDefault(); 156 $(this).closest('.woosc-popup').toggleClass('open'); 157 }); 158 159 // woovr 160 $(document).on('woovr_selected', function (e, selected) { 161 if (woosc_vars.variations === 'yes') { 162 var id = selected.attr('data-id'); 163 var pid = selected.attr('data-pid'); 164 165 if (id > 0) { 166 $('.woosc-btn-' + pid).removeClass('woosc-btn-added woosc-added').attr('data-id', id).attr('data-product_id', id); 167 } else { 168 $('.woosc-btn-' + pid).removeClass('woosc-btn-added woosc-added').attr('data-id', pid).attr('data-product_id', pid); 169 } 170 } 171 }); 172 173 // found variation 174 $(document).on('found_variation', function (e, t) { 175 if (woosc_vars.variations === 'yes') { 176 var product_id = $(e['target']).attr('data-product_id'); 177 178 $('.woosc-btn-' + product_id).each(function () { 179 let $btn = $(this); 180 let text = $btn.data('text') !== undefined && $btn.data('text') !== '' ? $btn.data('text') : woosc_vars.button_text; 181 182 $btn.removeClass('woosc-btn-added woosc-added').attr('data-id', t.variation_id).attr('data-product_id', t.variation_id); 183 184 if ($btn.hasClass('woosc-btn-has-icon')) { 185 $btn.find('.woosc-btn-icon').removeClass(woosc_vars.button_added_icon).addClass(woosc_vars.button_normal_icon); 186 $btn.find('.woosc-btn-text').text(text); 187 } else { 188 $btn.text(text); 189 } 190 }); 191 } 192 }); 193 194 // reset data 195 $(document).on('reset_data', function (e) { 196 if (woosc_vars.variations === 'yes') { 197 var product_id = $(e['target']).attr('data-product_id'); 198 199 $('.woosc-btn-' + product_id).each(function () { 200 let $btn = $(this); 201 let text = $btn.data('text') !== undefined && $btn.data('text') !== '' ? $btn.data('text') : woosc_vars.button_text; 202 203 $btn.removeClass('woosc-btn-added woosc-added').attr('data-id', product_id).attr('data-product_id', product_id); 204 205 if ($btn.hasClass('woosc-btn-has-icon')) { 206 $btn.find('.woosc-btn-icon').removeClass(woosc_vars.button_added_icon).addClass(woosc_vars.button_normal_icon); 207 $btn.find('.woosc-btn-text').text(text); 208 } else { 209 $btn.text(text); 210 } 211 }); 212 } 213 }); 214 215 // remove all 216 $(document).on('click touch', '.woosc-bar-remove', function (e) { 217 e.preventDefault(); 218 var r = confirm(woosc_vars.remove_all); 219 220 if (r == true) { 221 woosc_remove_product('all'); 222 woosc_load_data('table'); 223 } 224 }); 225 226 // add 227 $(document).on('click touch', '.woosc-btn', function (e) { 228 e.preventDefault(); 229 var $btn = $(this); 230 var id = $btn.attr('data-id'); 231 var pid = $btn.attr('data-pid'); 232 var product_id = $btn.attr('data-product_id'); 233 var product_name = $btn.attr('data-product_name'); 234 var product_image = $btn.attr('data-product_image'); 235 236 if (typeof pid !== typeof undefined && pid !== false) { 237 id = pid; 238 } 239 240 if (typeof product_id !== typeof undefined && product_id !== false) { 241 id = product_id; 242 } 243 244 if ($btn.hasClass('woosc-btn-added woosc-added')) { 245 if (woosc_vars.click_again === 'yes') { 246 // remove 247 woosc_remove_product(id); 248 249 if (woosc_vars.button_action === 'show_message') { 250 $.notiny({ 251 theme: 'woosc', 252 position: woosc_vars.message_position, 253 image: product_image, 254 text: woosc_vars.message_removed.replace('{name}', '<strong>' + product_name + '</strong>'),
255 }); 256 } 257 } else { 258 if (woosc_vars.button_action === 'show_message') { 259 $.notiny({ 260 theme: 'woosc', 261 position: woosc_vars.message_position, 262 image: product_image, 263 text: woosc_vars.message_exists.replace('{name}', '<strong>' + product_name + '</strong>'), 264 }); 265 } 266 } 267 } else { 268 $btn.addClass('woosc-btn-adding woosc-adding'); 269 woosc_add_product(id, $btn); 270 } 271 272 if (woosc_vars.button_action === 'show_bar') { 273 // show bar only 274 woosc_load_data('bar'); 275 woosc_open_bar(); 276 } 277 278 if (woosc_vars.button_action === 'show_table') { 279 // show bar & table 280 woosc_load_data('table'); 281 woosc_open_bar(); 282 woosc_open_table(); 283 } 284 285 if ((woosc_vars.button_action === 'show_message') || (woosc_vars.button_action === 'none')) { 286 // load bar again 287 if ($('.woosc-bar').hasClass('woosc-bar-open')) { 288 woosc_load_data('bar'); 289 } 290 } 291 292 if (woosc_vars.button_action === 'show_sidebar') { 293 woosc_load_data('sidebar'); 294 woosc_open_sidebar(); 295 } 296 }); 297 298 // remove on popup 299 $(document).on('click touch', '#woosc-area .woosc-bar-item-remove, #woosc-area .woosc-remove', function (e) { 300 e.preventDefault(); 301 var product_id = $(this).attr('data-id'); 302 303 $(this).parent().addClass('removing'); 304 woosc_remove_product(product_id); 305 woosc_load_data('table'); 306 woosc_check_buttons(); 307 }); 308 309 // remove on page 310 $(document).on('click touch', '.woosc-page .woosc-remove', function (e) { 311 e.preventDefault(); 312 var product_id = $(this).attr('data-id'); 313 314 woosc_remove_product(product_id); 315 location.reload(); 316 }); 317 318 // remove all on page 319 $(document).on('click touch', '.woosc-page .woosc-remove-all', function (e) { 320 e.preventDefault(); 321 var r = confirm(woosc_vars.remove_all); 322 323 if (r == true) { 324 woosc_remove_product('all'); 325 } 326 327 location.reload(); 328 }); 329 330 // remove on sidebar 331 $(document).on('click touch', '.woosc-sidebar-item-remove', function (e) { 332 e.preventDefault(); 333 var product_id = $(this).closest('.woosc-sidebar-item').attr('data-id'); 334 335 woosc_remove_product(product_id); 336 $(this).closest('.woosc-sidebar-item').slideUp(); 337 woosc_check_buttons(); 338 }); 339 340 // bar button 341 $(document).on('click touch', '.woosc-bar-btn', function (e) { 342 e.preventDefault(); 343 344 if (!$('.woosc-table-items').hasClass('woosc-table-items-loaded')) { 345 woosc_load_data('table'); 346 } 347 348 woosc_toggle_table(); 349 }); 350 351 // close 352 $(document).on('click touch', function (e) { 353 if (((woosc_vars.click_outside === 'yes') || ((woosc_vars.click_outside === 'yes_empty') && (parseInt($('.woosc-bar').attr('data-count')) === 0))) && ($(e.target).closest('.wpc_compare_count').length === 0) && ($(e.target).closest('.woosc-popup').length === 0) && ($(e.target).closest('.woosc-btn').length === 0) && ($(e.target).closest('.woosc-table').length === 0) && ($(e.target).closest('.woosc-bar').length === 0) && ($(e.target).closest('.woosc-menu-item a').length === 0) && ($(e.target).closest('.woosc-link a').length === 0) && ($(e.target).closest('.woosc-menu a').length === 0) && ($(e.target).closest('.woosc-sidebar-btn').length === 0) && ((woosc_vars.open_button === '') || ($(e.target).closest(woosc_vars.open_button).length === 0))) { 354 woosc_close(); 355 } 356 }); 357 358 // close sidebar 359 $(document).on('click touch', '.woosc-area-open-sidebar', function (e) { 360 if (($(e.target).closest('.woosc-sidebar').length === 0)) { 361 woosc_close_sidebar(); 362 363 if (woosc_vars.open_bar === 'yes') { 364 woosc_load_data('bar'); 365 woosc_open_bar(); 366 } 367 } 368 }); 369 370 $(document).on('click touch', '.woosc-sidebar-close, .woosc-sidebar-continue', function (e) { 371 woosc_close_sidebar(); 372 373 if (woosc_vars.open_bar === 'yes') { 374 woosc_load_data('bar'); 375 woosc_open_bar(); 376 } 377 }); 378 379 // let compare 380 $(document).on('click touch', '.woosc-sidebar-btn', function (e) { 381 e.preventDefault(); 382 woosc_close_sidebar();
383 woosc_toggle(); 384 }); 385 386 // close 387 $(document).on('click touch', '#woosc-table-close', function (e) { 388 e.preventDefault(); 389 woosc_close_table(); 390 }); 391 392 // change settings 393 $(document).on('change', '.woosc-settings-field, .woosc-settings-tool', function () { 394 woosc_save_settings(); 395 }); 396 397 // open button 398 if (woosc_vars.open_button !== '') { 399 $(document).on('click touch', woosc_vars.open_button, function (e) { 400 e.preventDefault(); 401 402 if (woosc_vars.open_button_action === 'open_page') { 403 // open page 404 if ((woosc_vars.page_url !== '') && (woosc_vars.page_url !== '#')) { 405 window.location.href = woosc_vars.page_url; 406 } 407 } else { 408 if (woosc_vars.open_button_action === 'open_popup') { 409 // open compare popup 410 if (!$('.woosc-table-items').hasClass('woosc-table-items-loaded')) { 411 woosc_load_data('table'); 412 } 413 414 woosc_open_bar(); 415 woosc_open_table(); 416 } 417 418 if (woosc_vars.open_button_action === 'open_sidebar') { 419 // open sidebar 420 if (!$('.woosc-sidebar-items').hasClass('woosc-sidebar-items-loaded')) { 421 woosc_load_data('sidebar'); 422 } 423 424 woosc_open_sidebar(); 425 } 426 } 427 }); 428 } 429 430 // menu item 431 $(document).on('click touch', '.woosc-menu-item a, .woosc-menu a, .woosc-link a', function (e) { 432 if (woosc_vars.menu_action === 'open_popup') { 433 e.preventDefault(); 434 435 // open compare popup 436 if (!$('.woosc-table-items').hasClass('woosc-table-items-loaded')) { 437 woosc_load_data('table'); 438 } 439 440 woosc_open_bar(); 441 woosc_open_table(); 442 } 443 444 if (woosc_vars.menu_action === 'open_sidebar') { 445 e.preventDefault(); 446 447 // open sidebar 448 if (!$('.woosc-sidebar-items').hasClass('woosc-sidebar-items-loaded')) { 449 woosc_load_data('sidebar'); 450 } 451 452 woosc_open_sidebar(); 453 } 454 }); 455 456 function woosc_search() { 457 $('.woosc-search-result').html('').addClass('woosc-loading'); 458 // ajax search product 459 woosc_timer = null; 460 461 var data = { 462 action: 'woosc_search', keyword: $('#woosc_search_input').val(), nonce: woosc_vars.nonce, 463 }; 464 465 $.post(woosc_vars.wc_ajax_url.toString().replace('%%endpoint%%', 'woosc_search'), data, function (response) { 466 $('.woosc-search-result').html(response).removeClass('woosc-loading'); 467 }); 468 } 469 470 function woosc_set_cookie(cname, cvalue, exdays) { 471 var d = new Date(); 472 473 d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000)); 474 475 var expires = 'expires=' + d.toUTCString(); 476 477 document.cookie = cname + '=' + cvalue + '; ' + expires + '; path=/'; 478 } 479 480 function woosc_get_cookie(cname) { 481 var name = cname + '='; 482 var ca = document.cookie.split(';'); 483 484 for (var i = 0; i < ca.length; i++) { 485 var c = ca[i]; 486 487 while (c.charAt(0) == ' ') { 488 c = c.substring(1); 489 } 490 491 if (c.indexOf(name) == 0) { 492 return decodeURIComponent(c.substring(name.length, c.length)); 493 } 494 } 495 496 return ''; 497 } 498 499 function woosc_get_products() { 500 var cookie_products = woosc_get_cookie_products(); 501 502 if (woosc_get_cookie(cookie_products) != '') { 503 return woosc_get_cookie(cookie_products); 504 } else { 505 return ''; 506 } 507 } 508 509 function woosc_save_products() { 510 var cookie_products = woosc_get_cookie_products(); 511 var products = []; 512 513 $('.woosc-bar-item').each(function () { 514 var pid = $(this).attr('data-id'); 515 516 if (pid !== '') { 517 products.push(pid); 518 } 519 }); 520 521 var products_str = products.join(); 522 523 woosc_set_cookie(cookie_products, products_str, 7); 524 woosc_load_data('table'); 525 } 526 527 function woosc_save_settings() { 528 var fields = []; 529 var settings = []; 530 var cookie_fields = 'woosc_fields_' + woosc_vars.hash; 531 var cookie_settings = 'woosc_settings_' + woosc_vars.hash; 532 533 if (woosc_vars.user_id !== '') { 534 cookie_fields += '_' + woosc_vars.user_id; 535 cookie_settings += '_' + woosc_vars.user_id; 536 } 537 538 // fields 539 $('.woosc-settings-field').each(function () { 540 var _val = $(this).val(); 541 542 if ($(this).prop('checked')) { 543 fields.push(_val); 544 $('.woosc_table .tr-' + _val).removeClass('tr-hide'); 545 } else { 546 $('.woosc_table .tr-' + _val).addClass('tr-hide'); 547 } 548 }); 549 550 // tools 551 $('.woosc-settings-tool').each(function () { 552 var _val = $(this).val(); 553 554 if ($(this).prop('checked')) { 555 settings.push(_val); 556 } 557 }); 558 559 woosc_set_cookie(cookie_fields, fields.join(','), 7); 560 woosc_set_cookie(cookie_settings, settings.join(','), 7); 561 woosc_load_data('table'); 562 } 563 564 function woosc_add_product(product_id, $btn = null) { 565 var count; 566 var limit = false;
567 var limit_notice = woosc_vars.limit_notice; 568 var cookie_products = woosc_get_cookie_products(); 569 570 if (woosc_get_cookie(cookie_products) !== '') { 571 var products = woosc_get_cookie(cookie_products).split(','); 572 573 if (products.length < woosc_vars.limit) { 574 products = $.grep(products, function (value) { 575 return value != product_id; 576 }); 577 578 if (woosc_vars.adding === 'append') { 579 products.push(product_id); 580 } else { 581 products.unshift(product_id); 582 } 583 584 var products_str = products.join(); 585 586 woosc_set_cookie(cookie_products, products_str, 7); 587 } else { 588 limit = true; 589 limit_notice = limit_notice.replace('{limit}', woosc_vars.limit); 590 } 591 592 count = products.length; 593 } else { 594 woosc_set_cookie(cookie_products, product_id, 7); 595 count = 1; 596 } 597 598 woosc_change_count(count); 599 $(document.body).trigger('woosc_added', [count]); 600 601 if (limit) { 602 $('.woosc-btn[data-id="' + product_id + '"]').removeClass('woosc-btn-adding woosc-adding'); 603 alert(limit_notice); 604 } else { 605 $('.woosc-btn[data-id="' + product_id + '"]').each(function () { 606 let $btn = $(this); 607 let text_added = $btn.data('text_added') !== undefined && $btn.data('text_added') !== '' ? $btn.data('text_added') : woosc_vars.button_text_added; 608 609 $btn.removeClass('woosc-btn-adding woosc-adding').addClass('woosc-btn-added woosc-added'); 610 611 if ($btn.hasClass('woosc-btn-has-icon')) { 612 $btn.find('.woosc-btn-icon').removeClass(woosc_vars.button_normal_icon).addClass(woosc_vars.button_added_icon); 613 $btn.find('.woosc-btn-text').text(text_added); 614 } else { 615 $btn.text(text_added); 616 } 617 }); 618 619 if (woosc_vars.button_action === 'show_message') { 620 if ($btn !== null && $btn.data('product_name') !== undefined && $btn.data('product_name') !== '' && ($btn.data('product_image') !== undefined && $btn.data('product_image') !== '')) { 621 $.notiny({ 622 theme: 'woosc', 623 position: woosc_vars.message_position, 624 image: $btn.data('product_image'), 625 text: woosc_vars.message_added.replace('{name}', '<strong>' + $btn.data('product_name') + '</strong>'), 626 }); 627 } 628 } 629 } 630 } 631 632 function woosc_remove_product(product_id) { 633 var count = 0; 634 var cookie_products = woosc_get_cookie_products(); 635 636 if (product_id !== 'all') { 637 // remove one 638 if (woosc_get_cookie(cookie_products) !== '') { 639 var products = woosc_get_cookie(cookie_products).split(','); 640 641 products = $.grep(products, function (value) { 642 return value !== product_id; 643 }); 644 645 var products_str = products.join(); 646 647 woosc_set_cookie(cookie_products, products_str, 7); 648 count = products.length; 649 } 650 651 $('.woosc-btn[data-id="' + product_id + '"]').each(function () { 652 let $btn = $(this); 653 let text = $btn.data('text') !== undefined && $btn.data('text') !== '' ? $btn.data('text') : woosc_vars.button_text; 654 655 $btn.removeClass('woosc-btn-added woosc-added'); 656 657 if ($btn.hasClass('woosc-btn-has-icon')) { 658 $btn.find('.woosc-btn-icon').removeClass(woosc_vars.button_added_icon).addClass(woosc_vars.button_normal_icon); 659 $btn.find('.woosc-btn-text').text(text); 660 } else { 661 $btn.text(text); 662 } 663 }); 664 } else { 665 // remove all 666 if (woosc_get_cookie(cookie_products) !== '') { 667 woosc_set_cookie(cookie_products, '', 7); 668 count = 0; 669 } 670 671 $('.woosc-btn').each(function () { 672 let $btn = $(this); 673 let text = $btn.data('text') !== undefined && $btn.data('text') !== '' ? $btn.data('text') : woosc_vars.button_text; 674 675 $btn.removeClass('woosc-btn-added woosc-added'); 676 677 if ($btn.hasClass('woosc-btn-has-icon')) { 678 $btn.find('.woosc-btn-icon').removeClass(woosc_vars.button_added_icon).addClass(woosc_vars.button_normal_icon); 679 $btn.find('.woosc-btn-text').text(text); 680 } else { 681 $btn.text(text); 682 } 683 }); 684 } 685 686 woosc_change_count(count); 687 $(document.body).trigger('woosc_removed', [count]); 688 } 689 690 function woosc_check_buttons() { 691 var cookie_products = woosc_get_cookie_products(); 692 693 if (woosc_get_cookie(cookie_products) !== '') { 694 var products = woosc_get_cookie(cookie_products).split(','); 695 696 $('.woosc-btn').each(function () { 697 let $btn = $(this); 698 let text = $btn.data('text') !== undefined && $btn.data('text') !== '' ? $btn.data('text') : woosc_vars.button_text; 699 700 $btn.removeClass('woosc-btn-added woosc-added'); 701 702 if ($btn.hasClass('woosc-btn-has-icon')) { 703 $btn.find('.woosc-btn-icon').removeClass(woosc_vars.button_added_icon).addClass(woosc_vars.button_normal_icon); 704 $btn.find('.woosc-btn-text').text(text); 705 } else { 706 $btn.text(text); 707 } 708 }); 709
710 products.forEach(function (product_id) { 711 $('.woosc-btn[data-id="' + product_id + '"]').each(function () { 712 let $btn = $(this); 713 let text_added = $btn.data('text_added') !== undefined && $btn.data('text_added') !== '' ? $btn.data('text_added') : woosc_vars.button_text_added; 714 715 $btn.addClass('woosc-btn-added woosc-added'); 716 717 if ($btn.hasClass('woosc-btn-has-icon')) { 718 $btn.find('.woosc-btn-icon').removeClass(woosc_vars.button_normal_icon).addClass(woosc_vars.button_added_icon); 719 $btn.find('.woosc-btn-text').text(text_added); 720 } else { 721 $btn.text(text_added); 722 } 723 }); 724 }); 725 } 726 } 727 728 function woosc_load_data(get_data) { 729 var data = { 730 action: 'woosc_load', get_data: get_data, nonce: woosc_vars.nonce, 731 }; 732 733 if (get_data === 'table') { 734 $('.woosc-table-inner').addClass('woosc-loading'); 735 } 736 737 if (get_data === 'sidebar') { 738 $('.woosc-sidebar').addClass('woosc-loading'); 739 } 740 741 $.post(woosc_vars.wc_ajax_url.toString().replace('%%endpoint%%', 'woosc_load'), data, function (response) { 742 if (get_data === 'bar' || get_data === 'table') { 743 // load bar items 744 $('.woosc-bar-items').html(response.bar).addClass('woosc-bar-items-loaded'); 745 746 $(document.body).trigger('woosc_bar_loaded'); 747 } 748 749 if (get_data === 'table') { 750 // load table 751 $('.woosc-table-items').html(response.table).addClass('woosc-table-items-loaded'); 752 753 if ($(window).width() >= 768) { 754 if ((woosc_vars.freeze_column === 'yes') && (woosc_vars.freeze_row === 'yes')) { 755 // freeze row and column 756 $('#woosc_table').tableHeadFixer({'head': true, left: 1}); 757 } else if (woosc_vars.freeze_column === 'yes') { 758 // freeze column 759 $('#woosc_table').tableHeadFixer({'head': false, left: 1}); 760 } else if (woosc_vars.freeze_row === 'yes') { 761 // freeze row 762 $('#woosc_table').tableHeadFixer({'head': true}); 763 } 764 } else { 765 if (woosc_vars.freeze_row === 'yes') { 766 // freeze row 767 $('#woosc_table').tableHeadFixer({'head': true}); 768 } 769 } 770 771 if (woosc_vars.scrollbar === 'yes') { 772 $('.woosc-table-items').perfectScrollbar({theme: 'wpc'}); 773 } 774 775 $('.woosc-table-inner').removeClass('woosc-loading'); 776 woosc_hide_empty(); 777 woosc_hide_similarities(); 778 woosc_highlight_differences(); 779 780 $(document.body).trigger('woosc_table_loaded'); 781 } 782 783 if (get_data === 'sidebar') { 784 // load sidebar 785 $('.woosc-sidebar-items').html(response.sidebar).addClass('woosc-sidebar-items-loaded'); 786 $('.woosc-sidebar').removeClass('woosc-loading'); 787 788 if (woosc_vars.scrollbar === 'yes') { 789 $('.woosc-sidebar-items').perfectScrollbar({theme: 'wpc'}); 790 } 791 792 $(document.body).trigger('woosc_sidebar_loaded'); 793 } 794 795 if (get_data === 'bar' || get_data === 'table' || get_data === 'sidebar') { 796 // load bar filter 797 $('.woosc-bar-filter').html(response.filter); 798 woosc_filter(); 799 800 $(document.body).trigger('woosc_filter_loaded'); 801 } 802 803 if (get_data === 'count') { 804 // load count 805 if (response.count != null) { 806 var count = parseInt(response.count); 807 808 woosc_change_count(count); 809 $(document.body).trigger('woosc_count_loaded', [count]); 810 } 811 } 812 }); 813 } 814 815 function woosc_quick_table() { 816 let ww = $(window).width(); 817 let fixed = JSON.parse(woosc_vars.quick_table_fixed); 818 819 if (ww >= 1024) { 820 $('.woosc-quick-table .woosc_table').tableHeadFixer({'head': false, left: fixed.pc}); 821 } 822 823 if (ww >= 768 && ww < 1024) { 824 $('.woosc-quick-table .woosc_table').tableHeadFixer({'head': false, left: fixed.ta}); 825 } 826 827 if (ww < 768) { 828 $('.woosc-quick-table .woosc_table').tableHeadFixer({'head': false, left: fixed.mo}); 829 } 830 } 831 832 function woosc_open_bar() { 833 woosc_close_sidebar(); 834 835 $('#woosc-area').addClass('woosc-area-open-bar'); 836 $('.woosc-bar').addClass('woosc-bar-open'); 837 838 $('.woosc-bar-items').sortable({ 839 handle: 'img', update: function (event, ui) { 840 woosc_save_products(); 841 }, 842 }); 843 844 $(document.body).trigger('woosc_bar_open'); 845 } 846 847 function woosc_close_bar() { 848 $('#woosc-area').removeClass('woosc-area-open-bar'); 849 $('.woosc-bar').removeClass('woosc-bar-open'); 850 851 $(document.body).trigger('woosc_bar_close'); 852 } 853 854 function woosc_open_sidebar() { 855 woosc_close_bar(); 856 woosc_close_table(); 857 858 $('#woosc-area').addClass('woosc-area-open-sidebar'); 859 $('.woosc-sidebar').addClass('woosc-sidebar-open'); 860 861 $(document.body).trigger('woosc_sidebar_open'); 862 } 863 864 function woosc_close_sidebar() { 865 $('#woosc-area').removeClass('woosc-area-open-sidebar'); 866 $('.woosc-sidebar').removeClass('woosc-sidebar-open'); 867 868 $(document.body).trigger('woosc_sidebar_close'); 869 } 870 871 function woosc_open_table() { 872 woosc_close_sidebar(); 873 874 $('#woosc-area').addClass('woosc-area-open-table'); 875 $('.woosc-table').addClass('woosc-table-open'); 876 $('.woosc-bar-btn').addClass('woosc-bar-btn-open'); 877 878 if (woosc_vars.bar_bubble === 'yes') { 879 $('.woosc-bar').removeClass('woosc-bar-bubble'); 880 } 881 882 $(document.body).trigger('woosc_table_open'); 883 } 884 885 function woosc_close_table() { 886 $('#woosc-area').removeClass('woosc-area-open woosc-area-open-table'); 887 $('.woosc-table').removeClass('woosc-table-open'); 888 $('.woosc-bar-btn').removeClass('woosc-bar-btn-open'); 889 890 if (woosc_vars.bar_bubble === 'yes') { 891 $('.woosc-bar').addClass('woosc-bar-bubble'); 892 } 893 894 if (woosc_vars.hide_closed === 'yes') { 895 woosc_close_bar(); 896 } 897 898 $(document.body).trigger('woosc_table_close'); 899 } 900 901 function woosc_toggle_table() { 902 if ($('.woosc-table').hasClass('woosc-table-open')) { 903 woosc_close_table(); 904 } else { 905 woosc_open_table(); 906 } 907 } 908 909 function woosc_open() { 910 $('#woosc-area').addClass('woosc-area-open'); 911 woosc_load_data('table'); 912 woosc_open_bar(); 913 woosc_open_table(); 914 915 $(document.body).trigger('woosc_open'); 916 } 917 918 function woosc_close() { 919 $('#woosc-area').removeClass('woosc-area-open'); 920 woosc_close_bar(); 921 woosc_close_table(); 922 923 $(document.body).trigger('woosc_close'); 924 } 925
926 function woosc_toggle() { 927 if ($('#woosc-area').hasClass('woosc-area-open')) { 928 woosc_close(); 929 } else { 930 woosc_open(); 931 } 932 933 $(document.body).trigger('woosc_toggle'); 934 } 935 936 function woosc_color() { 937 var bg_color = $('#woosc-area').attr('data-bg-color'); 938 var btn_color = $('#woosc-area').attr('data-btn-color'); 939 940 $('.woosc-table').css('background-color', bg_color); 941 $('.woosc-bar').css('background-color', bg_color); 942 $('.woosc-bar-btn').css('background-color', btn_color); 943 $('.woosc-sidebar-btn').css('background-color', btn_color); 944 } 945 946 function woosc_filter() { 947 if (woosc_vars.bar_filter !== 'no' && $('#woosc-filter').length) { 948 var filter = $('#woosc-filter').val().toLowerCase(); 949 950 if (filter !== '_all_') { 951 $('.woosc_table .col').addClass('col-hide').hide(); 952 $('.woosc_table .col-' + filter).removeClass('col-hide').show(); 953 954 $('.woosc-bar-item').addClass('woosc-bar-item-hidden'); 955 $('.woosc-bar-item-' + filter).removeClass('woosc-bar-item-hidden'); 956 } else { 957 $('.woosc_table .col').removeClass('col-hide').show(); 958 $('.woosc-bar-item').removeClass('woosc-bar-item-hidden'); 959 } 960 961 if (woosc_vars.hide_empty_row === 'yes') { 962 $('.woosc_table > tbody > tr:not(.tr-print)').each(function () { 963 var $tr = $(this); 964 var _td = 0; 965 var _empty = true; 966 967 $tr.removeClass('tr-empty').show(); 968 969 $tr.children('.col:not(.col-hide)').each(function () { 970 if ($(this).html().length > 0) { 971 _empty = false; 972 return false; 973 } 974 }); 975 976 if (_empty) { 977 $tr.addClass('tr-empty').hide(); 978 } 979 }); 980 } 981 } 982 } 983 984 function woosc_change_count(count) { 985 if (count === 'first') { 986 var products = woosc_get_products(); 987 988 if (products != '') { 989 var products_arr = products.split(','); 990 991 count = products_arr.length; 992 } else { 993 count = 0; 994 } 995 } 996 997 $('.woosc-menu-item').each(function () { 998 if ($(this).hasClass('menu-item-type-woosc')) { 999 $(this).find('.woosc-menu-item-inner').attr('data-count', count); 1000 } else { 1001 $(this).addClass('menu-item-type-woosc').find('a').wrapInner('<span class="woosc-menu-item-inner" data-count="' + count + '"></span>'); 1002 } 1003 }); 1004 1005 $('#woosc-area').attr('data-count', count); 1006 $('.woosc-bar').attr('data-count', count); 1007 $('.woosc-sidebar-count').text(' (' + count + ')'); 1008 $('.woosc-link .woosc-link-inner').attr('data-count', count); 1009 1010 $('.woosc-bar-items').removeClass('woosc-bar-items-loaded'); 1011 $('.woosc-sidebar-items').removeClass('woosc-sidebar-items-loaded'); 1012 $('.woosc-table-items').removeClass('woosc-table-items-loaded'); 1013 1014 $(document.body).trigger('woosc_change_count', [count]); 1015 } 1016 1017 function woosc_hide_empty() { 1018 if (woosc_vars.hide_empty_row === 'yes') { 1019 $('.woosc_table > tbody > tr').each(function () { 1020 var $tr = $(this); 1021 var _td = 0; 1022 var _empty = true; 1023 1024 $tr.children('td').each(function () { 1025 if ((_td > 0) && ($(this).html().length > 0)) { 1026 _empty = false; 1027 return false; 1028 } 1029 1030 _td++; 1031 }); 1032 1033 if (_empty) { 1034 $tr.addClass('tr-empty').remove(); 1035 } 1036 }); 1037 } 1038 } 1039 1040 function woosc_highlight_differences() { 1041 if ($('#woosc_highlight_differences').prop('checked')) { 1042 $('.woosc_table > tbody > tr').each(function () { 1043 var $tr = $(this); 1044 var _td = 0; 1045 var _val = $(this).children('td').eq(1).html(); 1046 var _differences = false;
1047 1048 $tr.children('td:not(.td-placeholder)').each(function () { 1049 if ((_td > 1) && ($(this).html() !== _val)) { 1050 _differences = true; 1051 return false; 1052 } 1053 _td++; 1054 }); 1055 1056 if (_differences) { 1057 $tr.addClass('tr-highlight'); 1058 } 1059 }); 1060 } else { 1061 $('.woosc_table tr').removeClass('tr-highlight'); 1062 } 1063 } 1064 1065 function woosc_hide_similarities() { 1066 if ($('#woosc_hide_similarities').prop('checked')) { 1067 $('.woosc_table > tbody > tr').each(function () { 1068 var $tr = $(this); 1069 var _td = 0; 1070 var _val = $(this).children('td').eq(1).html(); 1071 var _similarities = true; 1072 1073 $tr.children('td:not(.td-placeholder)').each(function () { 1074 if ((_td > 1) && ($(this).html() !== _val)) { 1075 _similarities = false; 1076 return false; 1077 } 1078 _td++; 1079 }); 1080 1081 if (_similarities) { 1082 $tr.addClass('tr-similar'); 1083 } 1084 }); 1085 } else { 1086 $('.woosc_table tr').removeClass('tr-similar'); 1087 } 1088 } 1089 1090 function woosc_get_cookie_products() { 1091 return woosc_vars.user_id !== '' ? 'woosc_products_' + woosc_vars.user_id : 'woosc_products'; 1092 } 1093})(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.