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