1jQuery('document').ready(function ($) { 2 function doPaginate() { 3 // Reset if set 4 $('.pagination').html(''); 5 $('.pagination').pagination({ 6 itemsToPaginate: ".reviewproduct", 7 activeClass: 'active' 8 }); 9 } 10 doPaginate(); 11 12 if ($('.offer_list_load_button').length) { 13 $('.offer_list_load_button').click(function (ev) { 14 ev.preventDefault(); 15 16 $('.offers .offer.hidden').removeClass('hidden'); 17 18 $('.offer_list_load_button').closest('.su-row').addClass('hidden'); 19 }); 20 } 21 22 $('.review_table_load_button').show(); 23 $('#pagination').hide(); 24 25 var bindInfiniteScroll = function () { 26 $('.review_table_load_button').click(function (e) { 27 e.preventDefault(); 28 loadReviews(this); 29 }) 30 } 31 32 var loadReviews = function (link) { 33 $(link).closest('.su-row').addClass("hidden").hide(); 34 $('.loader').show(); 35 36 var data = { 37 action: 'infinite_scroll', 38 category: $(link).data('category'), 39 count: $(link).data('count'), 40 page: $(link).data('paged'), 41 show_discontinued: $(link).data('showdiscontinued'), 42 start: $(link).data('start') 43 }; 44 45 if ($(link).hasClass("inspiration")) { 46 data['inspiration'] = 1; 47 } 48 49 $.ajax({ 50 url: '/wp-admin/admin-ajax.php', 51 data: data, 52 dataType: 'json', 53 method: 'POST', 54 success: function (response) { 55 $('#review_table .su-divider').last().hide(); 56 $('#review_table').append(response.content); 57 $('.loader').hide(); 58 $('.review_table_load_button').show(); 59 correctCounter(); 60 bindInfiniteScroll(); 61 62 executeFilters(); 63 if ($("#sorterselect").find("option:selected").val() != 1) { 64 checkSort(); 65 } 66 $('#review_table').attr("data-autoloaded", "1"); 67 }, 68 error: function () { 69 alert('Something failed, please reload the page and try again.'); 70 $('.loader').hide(); 71 } 72 }); 73 } 74 75 var correctCounter = function () { 76 var cnt = 1; 77 $("#review_table .su-row").each(function () { 78 $(this).find(".ranking").html("#" + cnt); 79 if (!$(this).hasClass("hidden")) { 80 cnt++; 81 } 82 }); 83 } 84 85 if ($('.recommendations').length) { 86 var height = 0; 87 88 var headlines = $('.recommendations .headline'); 89 90 headlines.each(function (index, item) { 91 if ($(item).height() > height) { 92 height = $(item).height(); 93 } 94 }); 95 96 headlines.height(height); 97 } 98 99 bindInfiniteScroll(); 100 101 if ($('select.product_info_chooser').length) { 102 // Regex to find any <br[ /]> 103 var regex = /<br\s*[\/]?>/gi; 104 105 $('select.product_info_chooser').change(function (e) { 106 var field = $(this).parent('.product_info_wrapper').find('textarea'); 107 var option = $(this).find(':selected'); 108 field.val(option.data('description').replace(regex, "\n")); 109 }); 110 } 111 112 if ($('.review_carousel').length) { 113 $('.review_carousel').slick({ 114 arrows: true, 115 infinite: false, 116 slidesToShow: 3, 117 slidesToScroll: 3, 118 dots: false, 119 responsive: [{ 120 breakpoint: 769, 121 settings: { 122 slidesToShow: 2, 123 slidesToScroll: 2, 124 } 125 }, 126 { 127 breakpoint: 620, 128 settings: { 129 slidesToShow: 1, 130 slidesToScroll: 1, 131 } 132 } 133 ] 134 }); 135 136 $('.review_carousel_item .review_item_body .expand_text').click(function (e) { 137 e.preventDefault(); 138 $(this).closest('.short_text').hide(); 139 $(this).closest('.review_item_body').find('.full_text').show(); 140 }); 141 142 $('.review_carousel_item .review_item_body .hide_text').click(function (e) { 143 e.preventDefault(); 144 $(this).closest('.full_text').hide(); 145 $(this).closest('.review_item_body').find('.short_text').show(); 146 }); 147 } 148 149 $('.testsite-price-table .expand').click(function (e) { 150 e.preventDefault(); 151 152 var parent = $(this).closest('.testsite-price-table'); 153 parent.find('.start-hidden').show(); 154 parent.find('.reduce').show(); 155 $(this).hide(); 156 }); 157 158 $('.testsite-price-table .reduce').click(function (e) { 159 e.preventDefault(); 160 161 var parent = $(this).closest('.testsite-price-table'); 162 parent.find('.start-hidden').hide(); 163 parent.find('.expand').show(); 164 $(this).hide(); 165 }); 166 167 /**Video review locked link */ 168 $(".man-revitem.video a").attr("target", "_blank"); 169 170 //mobile menu trigger 171 172 $("#custom-trigger,#custommobilemenu li.menu-item-has-children > a").click(function () { 173 event.preventDefault(); 174 $(this).next().slideToggle('fast'); 175 }); 176 177 //top 5 product bars 178 179 $(".js-compare-field-select").change(function () { 180 var $container = $(this).parent().parent(); 181 var slc = $(this).find(':selected').val(); 182 183 $container.find(".cbar").each(function () { 184 var wd = $(this).attr("data-" + slc); 185 var vl = $(this).attr("data-" + slc + "val"); 186 var un = $(this).attr("data-" + slc + "unit"); 187 if (slc == 'score') { 188 un = ''; 189 } 190 191 $(this).find(".darkbar").css("width", wd + "%").find("span").text(vl); 192 }) 193 }) 194 195 //thumbsup & down for inspiration
196 $(document).on('click', '.js-brandvote', function(e) { 197 e.preventDefault(); 198 199 var $this = $(this); 200 var id = $this.attr("data-id"); 201 var type = $this.attr('data-type'); 202 203 if ($this.attr("data-flag")) { 204 return false; 205 } 206 207 $.ajax({ 208 url: '/wp-admin/admin-ajax.php', 209 data: { 210 id: id, 211 type: type, 212 action: 'thumbscount', 213 brands: $this.hasClass("brands") ? 1 : 0, 214 brand_preset: $this.attr('data-brand-preset'), 215 }, 216 dataType: 'html', 217 method: 'POST', 218 success: function (response) { 219 if (!$this.hasClass("brands")) { 220 var prev = $this.find("strong").html(); 221 $this.find("strong").html(parseInt(prev) + 1); 222 $this.attr("data-flag", "1"); 223 } else if (response !== 'voted') { 224 $this.parent().find("strong").show(); 225 $this.closest(".brandrow").addClass("noborder"); 226 $this.closest(".brandrow").prev().addClass("active"); 227 if (type == 'increment') { 228 $this.closest(".brandrow").prev().find(".thumbsupagree").show(); 229 } else { 230 $this.closest(".brandrow").prev().find(".thumbsdownagree").show(); 231 } 232 233 $this.closest(".brandrow").find("u").addClass("active"); 234 } else if (response == 'voted') { 235 alert("You have already voted!"); 236 } 237 }, 238 error: function () { 239 alert('Something failed, please reload the page and try again.'); 240 } 241 }); 242 243 244 }) 245 246 247 /******************** 248 * FILTERS 249 */ 250 251 // $( ".styled" ).checkboxradio({ 252 // icon: true 253 // }); 254 255 var filters = {}; 256 257 //price range filter 258 $("#price-filters").each(function () { 259 var $this = $(this); 260 var minn = parseInt($this.attr("data-minn")); 261 var maxx = parseInt($this.attr("data-maxx")); 262 var mintext = $this.attr("data-mintext"); 263 var maxtext = $this.attr("data-maxtext"); 264 var unit = $this.attr("data-unit"); 265 266 $(this).slider({ 267 range: true, 268 min: minn, 269 max: maxx, 270 values: [minn, maxx], 271 slide: function (event, ui) { 272 $(".price-range").html(mintext + " " + ui.values[0] + " " + unit + ". - " + maxtext + " " + ui.values[1] + " " + unit + ".").attr("data-min", ui.values[0]).attr("data-max", ui.values[1]); 273 } 274 }); 275 276 ///filters['min'] = $( "#price-filters" ).slider("values", 0); //price values not populating here 277 ///filters['max'] = $( "#price-filters" ).slider("values", 1); 278 279 //$( "#amount" ).val( "$" + $( "#slider-range" ).slider( "values", 0 ) + " - $" + $( "#slider-range" ).slider( "values", 1 ) ); 280 }); 281 282 283 $(".goprice").click(function () { 284 285 filters['min'] = $("#price-filters").slider("values", 0); //price values not populating here 286 filters['max'] = $("#price-filters").slider("values", 1); 287 288 executeFilters(); 289 }); 290 291 $(document).on("click", ".goquick", function () { 292 var spec = $(this).attr("data-spec"); 293 294 filters[spec + 'min'] = $(".quick-filters." + spec).slider("values", 0); //price values not populating here 295 filters[spec + 'max'] = $(".quick-filters." + spec).slider("values", 1); 296 297 executeFilters(); 298 }); 299 300 $("#showdiscontinued").click(function () { 301 console.log('click funcktion show dis'); 302 $("#loadingwait").show(); 303 if ($(this).is(':checked')) { 304 var backup = filters; 305 filters = {}; //clear all filters except below filters 306 $.each(backup, function (index, value) { 307 if (index != 'discontinued') { 308 filters[index] = value; 309 } 310 }); 311 312 } else { 313 filters['discontinued'] = 1; //show discontinued 314 } 315 executeFilters(); 316 }) 317 318 /** 319 * Filtering mechanism starts 320 */ 321 // Load product types based on general type selection 322 $(document).on("click", "#gtype-filters li,#subgtype-filters li", function (e) { 323 var ID = $(this).attr("data-slug"); 324 var $this = $(this); 325 326 var data = { 327 gtype: ID, 328 hassubtype: 0, 329 nc: $this.parent().attr("data-nc"), 330 action: 'ptypefilters' 331 }; 332 333 if ($("#subgtype-filters").length && $this.hasClass("sgtype")) { 334 data["hassubtype"] = 1; //ajax call wont return any response 335 } 336 337 if ($this.parent().attr("data-flag") == 1) { 338 return false; 339 } 340 341 if ($("#review_table").attr("data-autoloaded") != 1) { 342 $(".review_table_load_button").trigger("click"); 343 $("#review_table").attr("data-autoloaded", "1"); 344 } 345 346 $.ajax({ 347 url: '/wp-admin/admin-ajax.php', 348 data: data, 349 dataType: 'html', 350 method: 'POST', 351 before: function () { 352 $this.parent().attr("data-flag", "1"); 353 $("#loadingwait").show(); 354 }, 355 success: function (response) { 356 $("#producttype-filters").html(response); 357 $this.parent().attr("data-flag", "0"); 358 359 var backup = filters; 360 filters = {}; //clear all filters except below filters 361 362 $.each(backup, function (index, value) { 363 if (index == 'subgtype') { 364 value = value.replace(/ \([0-9]+\)/, '') 365 } 366 367 if (index == 'min' || index == 'max' || index == 'brand' || index == "reviewmin" || index == "reviewmax" || index == "features" || index == "subgtype") { 368 filters[index] = value; 369 } 370 }); 371 372 if ($("#gtype-filters li.active").length) { 373 filters['gtype'] = $("#gtype-filters li.active").text(); 374 } else if (!$(".subgtype .autoclick").length) { 375 ///$("#producttype-filters").html(''); 376 } 377 378 executeFilters(); 379 380 //init range slider after gtype selection for numeric quickfacts 381 $(".quick-filters").each(function () { 382 var $this = $(this); 383 var minn = parseInt($this.attr("data-minn"));
384 var maxx = parseInt($this.attr("data-maxx")); 385 var step = $this.attr("data-step"); 386 var unit = $this.attr("data-unit"); 387 388 $(this).slider({ 389 range: true, 390 min: minn, 391 max: maxx, 392 step: step, 393 values: [minn, maxx], 394 slide: function (event, ui) { 395 $this.prev(".quick-range").html("<span class=\"qmin\">Min <b>" + ui.values[0] + " " + unit + "</b></span><span class=\"qmax\">Max <b>" + ui.values[1] + " " + unit + "</b></span>").attr("data-min", ui.values[0]).attr("data-max", ui.values[1]); 396 } 397 }); 398 }); 399 400 $("#review-filters ul:not(\"#gtype-filters\"):not(\"#reviewcount-filters\"):not(\"#brands-filter\"):not(\"#features-filter\"):not(\"#subgtype-filters\") li").removeClass("active"); 401 }, 402 error: function () { 403 $("#loadingwait").hide(); 404 alert('Something failed, please reload the page and try again.'); 405 } 406 }); 407 408 return false; 409 }); 410 411 $(document).on("click", "#review-filters ul:not(\".reviewcount\") li", function () { 412 $("#loadingwait").show(); 413 if ($(this).hasClass("active")) { 414 $(this).removeClass("active"); 415 $(this).siblings("li").removeClass("active"); 416 } else { 417 $(this).addClass("active"); 418 $(this).siblings("li").removeClass("active"); 419 } 420 }); 421 422 $("#reviewcount-filter li").click(function () { 423 $("#loadingwait").show(); 424 if ($(this).hasClass("active")) { 425 filters['reviewmin'] = 0; 426 filters['reviewmax'] = 999999999999999999; 427 $(this).removeClass("active"); 428 } else { 429 filters['reviewmin'] = parseInt($(this).attr("data-min")); 430 filters['reviewmax'] = parseInt($(this).attr("data-max")); 431 $(this).addClass("active"); 432 $(this).siblings("li").removeClass("active"); 433 } 434 435 executeFilters(); 436 }); 437 438 $("#goodprice-filter li").click(function () { 439 $("#loadingwait").show(); 440 if ($(this).hasClass("goodprice")) { 441 filters['gudprice'] = 1; 442 } else { 443 filters['gudprice'] = 0; 444 } 445 446 executeFilters(); 447 }); 448 449 $(document).on("click", ".customs li", function () { 450 $("#loadingwait").show(); 451 if ($(this).hasClass("clear")) { //remove this spec from stored object 452 var spec = $(this).parent("ul").attr("data-spec"); 453 //alert(spec); 454 var backup = filters; 455 filters = {}; 456 $.each(backup, function (index, value) { 457 if (index !== spec) { 458 filters[index] = value; 459 } 460 }); 461 462 $(this).removeClass("clear"); 463 464 //console.log(filters); 465 executeFilters(); 466 return false; 467 } else { 468 $(this).addClass("clear"); 469 $(this).siblings("li").removeClass("clear"); 470 } 471 472 var spec = $(this).parent("ul").attr("data-spec"); //spec4 473 var specval = $(this).text(); //1500 watt 474 475 if (spec == 'brand') { 476 specval = $(this).find("strong").text(); 477 } 478 479 if (spec == 'subgtype') { 480 specval = $(this).find("span").eq(0).text(); 481 } 482 483 if ($(this).find(".rating_arrow").length) { 484 specval = $(this).find(".rating_arrow").attr("data-rate"); 485 } 486 487 filters[spec] = specval; 488 489 executeFilters(); 490 }); 491 492 $(document).on("click", ".multiplecustoms li", function () { //product having multiple features as css class 493 $("#loadingwait").show(); 494 if ($(this).hasClass("clear")) { //remove this spec from stored object 495 var spec = $(this).parent("ul").attr("data-spec"); 496 //alert(spec); 497 var backup = filters; 498 filters = {}; 499 $.each(backup, function (index, value) { 500 if (index !== spec) { 501 filters[index] = value; 502 } 503 }); 504 505 $(this).removeClass("clear"); 506 507 //console.log(filters); 508 executeFilters(); 509 return false; 510 } else { 511 $(this).addClass("clear"); 512 $(this).siblings("li").removeClass("clear"); 513 } 514 515 var spec = $(this).parent("ul").attr("data-spec"); 516 var specval = $(this).find("strong").text(); 517 518 filters[spec] = specval; 519 520 executeFilters(); 521 522 }); 523 524 $(document).on("click", ".morefilters", function () { 525 $(this).prev(".hasmorefilters").addClass("active"); 526 $(this).hide().next(".lessfilters").show(); 527 }); 528 529 $(document).on("click", ".lessfilters", function () { 530 $(this).prev().prev(".hasmorefilters").removeClass("active"); 531 $(this).hide().prev(".morefilters").show(); 532 }); 533 534 $("#collapser").click(function () { 535 $("#collapsemobile .panel-grid-cell:first-child, #review-filters.collapsemobile").toggleClass("active"); 536 }); 537 538 $(document).on("click", "h3.folded", function () { 539 540 if ($(this).hasClass("opened")) { 541 $(this).next().next().next(".lessfilters").click(); 542 $(this).removeClass("opened"); 543 } else { 544 $(this).addClass("opened"); 545 } 546 547 $(this).next("ul,.rangeselector").slideToggle(500).delay(600).next(".morefilters").slideToggle(500); 548 549 }); 550 551 function testsetAutoClick() { 552 $("#loadingwait").show(); 553 var ct = $("#review_table").attr("data-cat"); 554 //ct = ct.toLowerCase(); 555 //ct = ct.replace(/\ /g,'_'); 556 //ct = ct.replace(/\-/g,'_'); 557 558 if ($("#gtype-filters li[data-slug=\"" + ct + "\"]").length) { 559 var $source = $("#gtype-filters li[data-slug=\"" + ct + "\"]"); 560 } else { 561 var $source = $('#subgtype-filters li:first-of-type'); 562 } 563 564 $source.addClass("autoclick").addClass("active").click().promise().done(function () { 565 $("#gtype-filters").prev('h3').remove(); 566 $("#gtype-filters").hide(); 567 }); 568 569 $("#loadingwait").hide(); 570 } 571 572 if ( 573 $("#review_table").hasClass("categorybased") 574 || 575 $('#subgtype-filters li').size() == 1 576 ) { 577 setTimeout(function() { 578 testsetAutoClick(); 579 }, 300) 580 } 581
582 $(document).on("click", ".cancelfilter", function () { 583 var ky = $(this).attr("data-key"); 584 585 var popfilter = {}; 586 $.each(filters, function (index, value) { 587 if (ky == 'min') { 588 if (index != 'min' && index != 'max') { 589 popfilter[index] = value; 590 } 591 592 $("#price-filters").each(function () { 593 var $this = $(this); 594 var minn = parseInt($this.attr("data-minn")); 595 var maxx = parseInt($this.attr("data-maxx")); 596 var unit = $this.attr("data-unit"); 597 598 $(".price-range").html(unit + " " + minn + " - " + unit + " " + maxx).attr("data-min", minn).attr("data-max", maxx); 599 600 $this.slider({ 601 range: true, 602 min: minn, 603 max: maxx, 604 values: [minn, maxx], 605 slide: function (event, ui) { 606 $(".price-range").html(unit + " " + ui.values[0] + " - " + unit + " " + ui.values[1]).attr("data-min", ui.values[0]).attr("data-max", ui.values[1]); 607 } 608 }); 609 }); 610 611 } else if (ky == 'reviewmin') { 612 if (index != 'reviewmin' && index != 'reviewmax') { 613 popfilter[index] = value; 614 } 615 616 $(".reviewcount li").removeClass("active clear"); 617 } else if (ky.indexOf("min") > 3) { //spec6min 618 var specname = ky.slice(0, -3); 619 620 if (index != specname + 'min' && index != specname + 'max') { 621 popfilter[index] = value; 622 } 623 624 //init range slider after gtype selection for numeric quickfacts 625 $(".quick-filters." + specname).each(function () { 626 var $this = $(this); 627 var minn = parseInt($this.attr("data-minn")); 628 var maxx = parseInt($this.attr("data-maxx")); 629 var step = $this.attr("data-step"); 630 var unit = $this.attr("data-unit"); 631 632 $this.prev(".quick-range").html("<span class=\"qmin\">Min <b>" + minn + " " + unit + "</b></span><span class=\"qmax\">Max <b>" + maxx + " " + unit + "</b></span>").attr("data-min", minn).attr("data-max", maxx); 633 634 $(this).slider({ 635 range: true, 636 min: minn, 637 max: maxx, 638 step: step, 639 values: [minn, maxx], 640 slide: function (event, ui) { 641 $this.prev(".quick-range").html("<span class=\"qmin\">Min <b>" + ui.values[0] + " " + unit + "</b></span><span class=\"qmax\">Max <b>" + ui.values[1] + " " + unit + "</b></span>").attr("data-min", ui.values[0]).attr("data-max", ui.values[1]); 642 } 643 }); 644 }); 645 646 } else if (ky != index) { 647 popfilter[index] = value; 648 } 649 }); 650 651 filters = popfilter; 652 653 if (ky.indexOf("spec") >= 0) { 654 $('ul[data-spec="' + ky + '"] li').removeClass("active clear"); 655 } else { 656 $("." + ky + " li").removeClass("active clear"); 657 } 658 659 executeFilters(); 660 }); 661 662 $(".visualexpander").click(function () { 663 $(this).hide(); 664 $(".visualbar.toexpand").fadeIn(500); 665 }); 666 667 $(".changeBarchart").change(function () { 668 var vl = $(this).find("option:selected").val(); 669 var id = vl.split("-"); 670 console.log("site: " + vl); 671 $(".chart-container-" + id[2]).fadeOut("fast"); 672 $("#" + vl).fadeIn("fast"); 673 }); 674 675 /** 676 * Main function responsible for filter execution 677 * Added Paginate call 10/7-18 <[email protected]> 678 */ 679 680 function executeFilters() { 681 $("#loadingwait").show(); 682 683 var attrs = '', 684 cnt = 0; 685 var activefilters = ''; 686 $.each(filters, function (index, value) { 687 if (index == 'min') { //price 688 689 var indexheading = $("#price-filters").prev('h3').find("span").text(); 690 //var unit = $("#price-filters").attr("data-unit"); 691 //var range = unit+'. '+value + ' - '+unit+'. ' + filters.max; 692 var range = $(".price-range").text(); 693 activefilters += '<div class="afilter rangefilter">' + indexheading + ': ' + range + '<i class="fa fa-close cancelfilter" data-key="' + index + '"></i></div>'; 694 695 } else if (index == "reviewmin") { //review count 696 697 var indexheading = $(".reviewcount").prev("h3").find("span").text(); 698 var range = $("#reviewcount-filter li.active").text(); 699 700 if ($(".reviewcount .active").length) { 701 activefilters += '<div class="afilter rangefilter">' + indexheading + ': ' + range + '<i class="fa fa-close cancelfilter" data-key="' + index + '"></i></div>'; 702 } 703 704 } else if (index.indexOf("min") >= 0) { 705 var specname = index.slice(0, -3); 706 var indexheading = $(".quick-filters." + specname).parent(".rangeselector").prev("h3").text(); 707 indexheading = indexheading.slice(1); 708 //var unit = $(".quick-filters."+specname).attr("data-unit"); 709 //var fspec = String(specname + "max"); 710 //var specmin = value; 711 //var specmax = filters[fspec]; 712 var qrange = $(".quick-filters." + specname).prev(".quick-range"); 713 714 var range = qrange.find(".qmin b").text() + ' - ' + qrange.find(".qmax b").text(); 715 activefilters += '<div class="afilter rangefilter">
715' + indexheading + ': ' + range + '<i class="fa fa-close cancelfilter" data-key="' + index + '"></i></div>'; 716 717 } else if (index.indexOf("max") < 0) { 718 if (index.indexOf('spec') >= 0) { 719 var indexheading = $('[data-spec="' + index + '"]').prev("h3").text(); 720 indexheading = indexheading.slice(1); 721 } else { 722 var indexheading = $("." + index).prev("h3").find("span").text(); 723 if (indexheading === '') { 724 indexheading = $("." + index).prev("h3").text(); 725 } 726 } 727 728 if ($("#review_table").hasClass("categorybased")) { 729 if (index != 'gtype') { 730 activefilters += '<div class="afilter">' + indexheading + ': ' + value + '<i class="fa fa-close cancelfilter" data-key="' + index + '"></i></div>'; 731 } 732 } else { 733 activefilters += '<div class="afilter">' + indexheading + ': ' + value + '<i class="fa fa-close cancelfilter" data-key="' + index + '"></i></div>'; 734 } 735 } 736 737 if (index != 'min' && index != 'max' && index != 'reviewmin' && index != 'reviewmax' && index != 'features' && index != 'discontinued' && index.indexOf('min') < 0 && index.indexOf('max') < 0) { 738 attrs += '[data-' + index + '="' + value + '"]'; 739 } 740 cnt++; 741 }); 742 $("#active-filters").html(activefilters); 743 744 745 if (cnt == 0) { //show all IF no filters are set 746 $(".reviewproduct, #collapsemobile .offer").fadeIn(500); 747 $(".reviewproduct.discontinued").hide(); 748 $("#loadingwait").fadeOut(500); 749 750 setTimeout(function () { 751 doPaginate(); 752 }, 600); 753 return false; 754 } 755 756 //identification 757 $(".reviewproduct, #collapsemobile .offer").removeClass("filtered"); //reset filtering 758 759 //data-attr based filtering - level one 760 var div = $(".reviewproduct" + attrs); 761 div.addClass("filtered"); 762 763 var div = $("#collapsemobile .offer" + attrs); 764 div.addClass("filtered"); 765 766 if (undefined !== filters.min) { 767 $(".reviewproduct").each(function () { //price range check in filtered items 768 if ($(this).hasClass("filtered")) { 769 770 if (undefined !== filters.min) { //price range check 771 var pryc = $(this).attr("data-price"); 772 if (pryc >= filters.min && pryc <= filters.max) { 773 774 if (undefined != filters.reviewmin) { //review count check after price range filter 775 var revs = $(this).attr("data-reviews"); 776 if (revs >= filters.reviewmin && revs <= filters.reviewmax) { 777 $(this).fadeIn(500); 778 } else { 779 $(this).removeClass("filtered"); 780 $(this).fadeOut(500); 781 } 782 } else { 783 $(this).fadeIn(500); 784 } 785 786 } else { 787 $(this).removeClass("filtered"); 788 $(this).fadeOut(500); 789 } 790 } else { 791 ///$(this).fadeIn(500); //default fadein as price & reviewcount filters are not set 792 } 793 794 } else { //first level data attr based filter fail 795 ///$(this).fadeOut(500); 796 } 797 }); 798 } 799 800 if (undefined != filters.reviewmin) { 801 $(".reviewproduct").each(function () { //review count check in filtered items 802 if ($(this).hasClass("filtered")) { 803 804 if (undefined != filters.reviewmin) { //review count check when price range is not selected 805 var revs = $(this).attr("data-reviews"); 806 if (revs >= filters.reviewmin && revs <= filters.reviewmax) { 807 $(this).fadeIn(500); 808 } else { 809 $(this).removeClass("filtered"); 810 } 811 } 812 } 813 }); 814 } 815 816 if (undefined != filters.features) { 817 $(".reviewproduct").each(function () { //features check in filtered items 818 if ($(this).hasClass("filtered")) { 819 820 if (undefined != filters.features) { //features filter 821 var feature = filters.features; 822 feature = feature.toLowerCase(); 823 feature = feature.replace(/\ /g, '-'); 824 825 if ($(this).hasClass(feature)) { 826 $(this).fadeIn(500); 827 } else { 828 $(this).removeClass("filtered"); 829 } 830 } 831 } 832 }); 833 } 834 835 //loop to check any quickfact ranges 836 var quickfactranges = {}; 837 $.each(filters, function (index, value) { 838 if (index != 'min' && index != 'max' && index != 'reviewmin' && index != 'reviewmax') { 839 if (index.indexOf("min") >= 0) { 840 quickfactranges[index] = value; 841 } 842 } 843 }); 844 ///console.log(quickfactranges); 845 846 $.each(quickfactranges, function (index, value) { 847 848 $(".reviewproduct").each(function () { //review count check in filtered items 849 if ($(this).hasClass("filtered")) { 850 851 var specname = index.slice(0, -3); 852 853 var fspec = String(specname + "max"); 854 855 var specval = $(this).attr("data-" + specname); 856 var specmin = value; 857 var specmax = filters[fspec]; 858 859 if (specval >= specmin && specval <= specmax) { 860 ///$(this).fadeIn(500); 861 } else { 862 $(this).removeClass("filtered"); 863 } 864 865 } 866 }); 867 868 }); 869 870 871 $(".reviewproduct, #collapsemobile .offer").each(function () { 872 if ($(this).hasClass("filtered")) { 873 $(this).fadeIn(500); 874 } else { 875 $(this).fadeOut(500); 876 } 877 }); 878 879 if (undefined != filters.discontinued) { //show/hide discontinued 880 $(".reviewproduct.filtered.discontinued").removeClass("hidden").css("display", "flex"); 881 } else { 882 $(".reviewproduct.filtered.discontinued").hide().addClass("hidden"); 883 } 884 885 886 setTimeout(function () { 887 $("#loadingwait").fadeOut(500); 888 }, 500); 889 890 setTimeout(function () { 891 doPaginate(); 892 }, 700); 893 894 } 895 896 /*function refreshproducts(){ 897 var ptype = $("#ptype-filters li.active").text(); 898 899 $(".reviewproduct").each(function(){ 900 if($(this).attr("data-ptype") != ptype){ 901 $(this).fadeOut("fast").addClass("hidden"); 902 } else { 903 $(this).fadeIn("fast").removeClass("hidden"); 904 } 905 }); 906 }*/ 907 908 909 //Review Table sorter 910 $("#sorterselect").change(function () { 911 $('.reviewproduct').show(); 912 checkSort(); 913 executeFilters(); 914 }); 915 916 $(".featmeta-expand").click(function () { 917 $(this).parent().toggleClass("expand"); 918 }); 919 920 $("#featcat-slider").anythingSlider({ 921 //mode: 'f', // fade mode - new in v1.8! 922 //expand: true, 923 theme: 'cs-portfolio', 924 resizeContents: false, 925 hashTags: false 926 }); 927 928 setTimeout(function () { 929 var wd = $("#didyouknow").width(); 930 $("#duk-slider,#duk-slider li").css("width", wd + "px"); 931 932 var mh = 100; 933 $("#duk-slider li").each(function () { 934 if ($(this).height() > mh) { 935 mh = $(this).height(); 936 } 937 }); 938 939 mh = mh + 40; 940 941 $("#duk-slider,#duk-slider li").css("max-height", mh + "px"); 942 943 $("#duk-slider").anythingSlider({ 944 //mode: 'f', // fade mode - new in v1.8! 945 expand: true, 946 theme: 'cs-portfolio', 947 resizeContents: true, 948 hashTags: false 949 }); 950 }, 100); 951 952 /** 953 * Tooltipster 954 */ 955 $('.tooltipster').each(function () { 956 957 if ($(this).hasClass("pscore-red") || $(this).hasClass("pscore-yellow") || $(this).hasClass("pscore-green")) { 958 $(this).tooltipster({ 959 theme: 'tooltipster-punk', 960 animation: 'grow', 961 content: $("#tooltip_content"), 962 contentCloning: true, 963 //delay:300, 964 side: 'top', 965 trigger: 'hover', 966 maxWidth: 300, 967 interactive: true 968 }); 969 } else { 970 $(this).tooltipster({ 971 theme: 'tooltipster-punk', 972 animation: 'grow', 973 delay: 300, 974 side: 'top', 975 trigger: 'hover', 976 maxWidth: 300, 977 interactive: true 978 }); 979 } 980 }); 981 982 /** 983 * jQuery.fn.sortElements 984 * -------------- 985 * @param Function comparator:
986 * Exactly the same behaviour as [1,2,3].sort(comparator) 987 * 988 * @param Function getSortable 989 * A function that should return the element that is 990 * to be sorted. The comparator will run on the 991 * current collection, but you may want the actual 992 * resulting sort to occur on a parent or another 993 * associated element. 994 * 995 * E.g. $('td').sortElements(comparator, function(){ 996 * return this.parentNode; 997 * }) 998 * 999 * The <td>'s parent (<tr>) will be sorted instead 1000 * of the <td> itself. 1001 */ 1002 jQuery.fn.sortElements = (function () { 1003 1004 var sort = [].sort; 1005 1006 return function (comparator, getSortable) { 1007 1008 getSortable = getSortable || function () { 1009 return this; 1010 }; 1011 1012 var placements = this.map(function () { 1013 1014 var sortElement = getSortable.call(this), 1015 parentNode = sortElement.parentNode, 1016 1017 // Since the element itself will change position, we have 1018 // to have some way of storing its original position in 1019 // the DOM. The easiest way is to have a 'flag' node: 1020 nextSibling = parentNode.insertBefore( 1021 document.createTextNode(''), 1022 sortElement.nextSibling 1023 ); 1024 1025 return function () { 1026 1027 if (parentNode === this) { 1028 throw new Error( 1029 "You can't sort elements if any one is a descendant of another." 1030 ); 1031 } 1032 1033 // Insert before flag: 1034 parentNode.insertBefore(this, nextSibling); 1035 // Remove flag: 1036 parentNode.removeChild(nextSibling); 1037 1038 }; 1039 1040 }); 1041 1042 return sort.call(this, comparator).each(function (i) { 1043 placements[i].call(getSortable.call(this)); 1044 }); 1045 1046 }; 1047 1048 })(); 1049 1050 function checkSort() { 1051 1052 1053 // TODO RESET PAGINATE OG SORTER 1054 var sel = $("#sorterselect").find("option:selected").val(); 1055 var r = $.Deferred(); 1056 var n = 0; 1057 if (sel == 1) { //score 1058 $(".reviewproduct").each(function () { 1059 $('.su-row.reviewproduct').sortElements(function (a, b) { 1060 aValue = $(a).find(".ranking strong").length ? parseInt($(a).find(".ranking strong").text()) : 999999; 1061 bValue = $(b).find(".ranking strong").length ? parseInt($(b).find(".ranking strong").text()) : 999999; 1062 return aValue > bValue ? 1 : -1; 1063 }); 1064 1065 //var order = $(this).find(".pscore").text(); 1066 //$(this).attr("data-order", order); 1067 }); 1068 } else if (sel == 2) { //price 1069 $(".reviewproduct").each(function () { 1070 $('.su-row.reviewproduct').sortElements(function (a, b) { 1071 return parseInt($(a).attr("data-price")) > parseInt($(b).attr("data-price")) ? 1 : -1; 1072 }); 1073 1074 //var order = $(this).attr("data-price"); 1075 //$(this).attr("data-order", order); 1076 }); 1077 } else { //gudscore 1078 $(".reviewproduct").each(function () { 1079 $('.su-row.reviewproduct').sortElements(function (a, b) { 1080 var aValue = parseInt($(a).attr("data-gudprice")); 1081 var bValue = parseInt($(b).attr("data-gudprice")); 1082 1083 if(aValue === bValue) { 1084 aValue = $(a).find(".ranking strong").length ? parseInt($(a).find(".ranking strong").text()) : 999999; 1085 bValue = $(b).find(".ranking strong").length ? parseInt($(b).find(".ranking strong").text()) : 999999; 1086 return aValue > bValue ? 1 : -1; 1087 } 1088 1089 return aValue < bValue ? 1 : -1; 1090 }); 1091 1092 //var order = $(this).attr("data-gudprice"); 1093 //$(this).attr("data-order", order); 1094 }); 1095 } 1096 1097 console.log('checksort'); 1098 /*$('.su-row.reviewproduct').sortElements(function (a, b) { 1099 return parseInt($(a).attr("data-order")) > parseInt($(b).attr("data-order")) ? 1 : -1; 1100 });*/ 1101 return r; 1102 } 1103 1104 $('.js-specification-feedback').on('click', function() { 1105 $('.specification-feedback-popup').toggle(); 1106 }); 1107 1108 $('.specification-feedback-popup').on('click', function() { 1109 $('.specification-feedback-popup').toggle(); 1110 }); 1111 1112 $('.specification-feedback-popup-content').on('click', function(e) { 1113 e.stopPropagation(); 1114 }); 1115 1116 $('.js-specification-feedback-submit').on('click', function() { 1117 $.ajax({ 1118 url: '/wp-admin/admin-ajax.php', 1119 data: { 1120 action: 'specification_feedback', 1121 content: $('#feedback-content').val(), 1122 email: $('#feedback-email').val() 1123 }, 1124 dataType: 'json', 1125 method: 'POST', 1126 success: function (response) { 1127 $('.specification-feedback-popup').toggle(); 1128 }, 1129 error: function () { 1130 $('.specification-feedback-popup').toggle(); 1131 } 1132 }); 1133 }); 1134 1135});
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.