(function() { jQuery(document).ready(function($) { // initial resize of [cusrev_reviews_grid] and Trust Badges crResizeAllGridItems(); crResizeTrustBadges(); //enable attachment of images to comments jQuery("form#commentform").attr( "enctype", "multipart/form-data" ).attr( "encoding", "multipart/form-data" ); //prevent review submission if captcha is not solved jQuery("#commentform").on( "submit", function(event) { if( cr_ajax_object.ivole_recaptcha === '1' ) { var recaptcha = jQuery("#g-recaptcha-response").val(); if (recaptcha === "") { event.preventDefault(); alert("Please confirm that you are not a robot"); } } } ); //show lightbox when click on images attached to reviews jQuery("ol.commentlist").on("click", ".cr-comment-a", function(t) { if(cr_ajax_object.disable_lightbox === '0') { //only if lightbox is not disabled in settings of the plugin t.preventDefault(); const oo = jQuery(".pswp"); if ( 0 < oo.length ) { const o = oo[0]; var pics = jQuery(this).parent().parent().find(".cr-comment-a img"); var this_pic = jQuery(this).find("img"); var inx = 0; if (pics.length > 0 && this_pic.length > 0) { var a = []; for (i = 0; i < pics.length; i++) { a.push({ src: pics[i].src, w: pics[i].naturalWidth, h: pics[i].naturalHeight, title: pics[i].alt }); if (this_pic[0].src == pics[i].src) { inx = i; } } var r = { index: inx }; new PhotoSwipe(o, PhotoSwipeUI_Default, a, r).init(); } } } }); // play a video when a user clicks on it in the reviews grid jQuery(".cr-reviews-grid").on("click", ".image-row-vid, .cr-comment-videoicon", function(t) { if( ! jQuery(this).closest(".image-row").hasClass( "cr-vid-playing" ) ) { jQuery(this).closest(".image-row").addClass( "cr-vid-playing" ); jQuery(this).closest(".image-row").find(".image-row-vid").prop( "controls", true ); jQuery(this).closest(".image-row").find(".image-row-vid").get(0).play(); } else { jQuery(this).closest(".image-row").find(".image-row-vid").get(0).pause(); jQuery(this).closest(".image-row").find(".image-row-vid").prop( "controls", false ); jQuery(this).closest(".image-row").removeClass( "cr-vid-playing" ); } return false; } ); // play a video when a user clicks on it in the media pop-up window jQuery(".cr-ajax-reviews-cus-images-modal").on("click", ".cr-ajax-reviews-video, .cr-ajax-reviews-video .cr-comment-videoicon", function(t) { if( ! jQuery(this).closest(".cr-ajax-reviews-video").hasClass( "cr-vid-playing" ) ) { jQuery(this).closest(".cr-ajax-reviews-video").addClass( "cr-vid-playing" ); jQuery(this).closest(".cr-ajax-reviews-video").find("video").prop( "controls", true ); jQuery(this).closest(".cr-ajax-reviews-video").find("video").get(0).play(); } else { jQuery(this).closest(".cr-ajax-reviews-video").find("video").get(0).pause(); jQuery(this).closest(".cr-ajax-reviews-video").find("video").prop( "controls", false ); jQuery(this).closest(".cr-ajax-reviews-video").removeClass( "cr-vid-playing" ); } return false; } ); // open a gallery with media files in the reviews grid jQuery(".cr-reviews-grid").on("click", ".media-row-count", function(t) { if ( cr_ajax_object.disable_lightbox === '0' ) { // only if lightbox is not disabled in settings of the plugin t.preventDefault(); const oo = jQuery(".pswp"); let media = jQuery(this).parent().find(".image-row-vid,.image-row-img"), this_media = jQuery(this), inx = 0; if (media.length > 0 && this_media.length > 0) { const o = oo[0]; var a = []; for (i = 0; i < media.length; i++) { if ( "vid" === media[i].dataset.crmedia ) { a.push({ html: '
', title: media[i].dataset.crtitle }); } else { a.push({ src: media[i].src, w: media[i].naturalWidth, h: media[i].naturalHeight, title: media[i].alt }); } if (this_media[0].src == media[i].src) { inx = i; } } var r = { index: inx }; new PhotoSwipe(o, PhotoSwipeUI_Default, a, r).init(); } } } ); // play or pause a video in the gallery jQuery(document).on("click", ".cr-video-wrapper .cr-media-video", function(t) { const vid = jQuery(this).get(0); if ( vid ) { const isVideoPlaying = !!( vid.currentTime > 0 && !vid.paused && !vid.ended && vid.readyState > 2 ); if ( isVideoPlaying ) { vid.pause(); } else { vid.play(); } } return false; } ); // show a lightbox when a user clicks on images in the reviews grid jQuery(".cr-reviews-grid").on("click", ".image-row-img, .image-row-count", function(t) { if(cr_ajax_object.disable_lightbox === '0') { // only if lightbox is not disabled in settings of the plugin t.preventDefault(); const oo = jQuery(".pswp"); if ( 0 < oo.length ) { const o = oo[0]; var pics = jQuery(this).parent().find("img.image-row-img"); var this_pic = jQuery(this); var inx = 0; if (pics.length > 0 && this_pic.length > 0) { var a = []; for (i = 0; i < pics.length; i++) { a.push({ src: pics[i].src, w: pics[i].naturalWidth, h: pics[i].naturalHeight, title: pics[i].alt }); if (this_pic[0].src == pics[i].src) { inx = i; } } var r = { index: inx }; new PhotoSwipe(o, PhotoSwipeUI_Default, a, r).init(); } } } }); //register a listener for votes on for reviews initVoteClick("ol.commentlist", ".cr-voting-a", "cr_vote_review"); //register a listener for the voting buttons on modal initVoteClick(".cr-ajax-reviews-cus-images-modal", ".cr-voting-a", "cr_vote_review"); //register a listener for the voting buttons on Q & A initVoteClick(".cr-qna-block .cr-qna-list-block", ".cr-voting-a", "cr_vote_question"); //show a lightbox when click on videos attached to reviews jQuery("ol.commentlist").on("click", ".cr-video-a, .cr-comment-videoicon", function(t) { if( ! jQuery(this).closest(".cr-comment-videos").hasClass( "cr-comment-videos-modal" ) ) { let tt = jQuery(this).closest("[class*='cr-comment-video-']"); jQuery(this).closest(".cr-comment-videos").addClass( "cr-comment-videos-modal" ); tt.addClass( "cr-comment-video-modal" ); tt.find( "video" ).prop( "controls", true ); tt.find( ".cr-comment-videoicon" ).hide(); tt.find( "video" ).get(0).play(); return false; } return false; } ); //close a video lightbox jQuery("ol.commentlist").on( "click", ".cr-comment-videos", function(t) { if( jQuery(this).hasClass( "cr-comment-videos-modal" ) ) { jQuery(this).removeClass( "cr-comment-videos-modal" ); jQuery(this).find("[class*='cr-comment-video-']").each(function(index, element){ if( jQuery(element).hasClass( "cr-comment-video-modal" ) ) { jQuery(element).removeClass( "cr-comment-video-modal" ); jQuery(element).find( "video").get(0).pause(); jQuery(element).find( "video" ).prop( "controls", false ); jQuery(element).find( ".cr-comment-videoicon" ).show(); jQuery(element).removeAttr("style"); } }); return false; } } ); //show more ajax reviews jQuery(".cr-show-more-reviews-prd").on( "click", function(t) { t.preventDefault(); crShowMoreReviewsPrd( jQuery(this) ); } ); // ajax sorting of reviews jQuery(".cr-ajax-reviews-sort").on( "change", function(t) { t.preventDefault(); if ( jQuery(this).parents(".cr-all-reviews-shortcode").length ) { // sorting in the all reviews block cr_filter_all_reviews( jQuery(this) ); } else { // sorting on a product page var cr_product_id = jQuery(this).parents(".cr-reviews-ajax-comments").find(".commentlist.cr-ajax-reviews-list").attr("data-product"); var cr_sort = jQuery(this).children("option:selected").val(); var cr_rating = jQuery(this).parents(".cr-reviews-ajax-comments").find(".cr-summaryBox-ajax tr.ivole-histogramRow.ivole-histogramRow-s .ivole-histogram-a").attr("data-rating"); if(!cr_rating){ cr_rating = 0; } var cr_data = { "action": "cr_sort_reviews", "productID": cr_product_id, "sort": cr_sort, "rating": cr_rating }; jQuery(this).parents(".cr-reviews-ajax-comments").find(".cr-search-no-reviews").hide(); jQuery(this).parents(".cr-reviews-ajax-comments").find('.cr-ajax-search input').val("").trigger("change"); jQuery(this).parents(".cr-reviews-ajax-comments").find(".cr-show-more-reviews-prd").hide(); jQuery(this).parents(".cr-reviews-ajax-comments").find(".commentlist.cr-ajax-reviews-list").hide(); jQuery(this).parents(".cr-reviews-ajax-comments").find(".cr-show-more-review-spinner").show(); jQuery(this).parents(".cr-reviews-ajax-comments").find(".cr-summaryBox-ajax").addClass("cr-summaryBar-updating"); jQuery(this).addClass("cr-sort-updating"); jQuery.post( { url: cr_ajax_object.ajax_url, data: cr_data, context: this, success: function(response) { jQuery(this).parents(".cr-reviews-ajax-comments").find(".cr-show-more-review-spinner").hide(); jQuery(this).parents(".cr-reviews-ajax-comments").find(".cr-summaryBox-ajax").removeClass("cr-summaryBar-updating"); jQuery(this).removeClass("cr-sort-updating"); if(response.page > 0){ jQuery(this).parents(".cr-reviews-ajax-comments").find(".commentlist.cr-ajax-reviews-list").empty(); jQuery(this).parents(".cr-reviews-ajax-comments").find(".commentlist.cr-ajax-reviews-list").append(response.html); jQuery(this).parents(".cr-reviews-ajax-comments").find(".commentlist.cr-ajax-reviews-list").show(); jQuery(this).parents(".cr-reviews-ajax-comments").attr("data-page",response.page); if( response.show_more_label ) { jQuery(this).parents(".cr-reviews-ajax-comments").find(".cr-show-more-reviews-prd").text( response.show_more_label ); } if ( response.count_row ) { jQuery(this).parents(".cr-reviews-ajax-comments").find(".cr-count-row .cr-count-row-count").html( response.count_row ); } if(!response.last_page){ jQuery(this).parents(".cr-reviews-ajax-comments").find(".cr-show-more-reviews-prd").show(); } } }, dataType: "json" } ); } } ); // non-ajax filtering of reviews jQuery(".cr-noAjax").on( "click", ".ivole-histogram-a", function (t) { t.preventDefault(); const parser = new URL(window.location); parser.searchParams.set(cr_ajax_object.rating_filter, jQuery(this).data("rating")); parser.hash = cr_ajax_object.reviews_tab; window.location = parser.href; } ); // ajax filtering of reviews jQuery(".cr-reviews-ajax-comments").on("click", ".ivole-histogram-a, .cr-seeAllReviews", function(t){ t.preventDefault(); let tmpParent = jQuery(this).parents(".cr-reviews-ajax-comments"); let cr_product_id = tmpParent.find(".commentlist.cr-ajax-reviews-list").attr("data-product"); let cr_nonce = tmpParent.find(".cr-summaryBox-ajax").attr("data-nonce"); let cr_rating = jQuery(this).attr("data-rating"); let cr_sort = tmpParent.find(".cr-ajax-reviews-sort").children("option:selected").val(); let cr_data = { "action": "cr_filter_reviews", "productID": cr_product_id, "rating": cr_rating, "sort": cr_sort, "security": cr_nonce }; tmpParent.find(".cr-summaryBox-ajax tr.ivole-histogramRow.ivole-histogramRow-s").removeClass("ivole-histogramRow-s"); if( cr_rating > 0 ) { jQuery(this).closest("tr.ivole-histogramRow").addClass("ivole-histogramRow-s"); } tmpParent.find(".cr-search-no-reviews").hide(); tmpParent.find('.cr-ajax-search input').val("").trigger("change"); tmpParent.find(".cr-show-more-reviews-prd").hide(); tmpParent.find(".commentlist.cr-ajax-reviews-list").hide(); tmpParent.find(".cr-show-more-review-spinner").show(); tmpParent.find(".cr-summaryBox-ajax").addClass("cr-summaryBar-updating"); tmpParent.find(".cr-ajax-reviews-sort").addClass("cr-sort-updating"); jQuery.post( { url: cr_ajax_object.ajax_url, data: cr_data, context: tmpParent, success: function(response) { this.find(".cr-show-more-review-spinner").hide(); this.find(".cr-summaryBox-ajax").removeClass("cr-summaryBar-updating"); this.find(".cr-ajax-reviews-sort").removeClass("cr-sort-updating"); if(response.page > 0) { this.find(".commentlist.cr-ajax-reviews-list").empty(); this.find(".commentlist.cr-ajax-reviews-list").append(response.html); this.find(".commentlist.cr-ajax-reviews-list").show(); this.attr("data-page",response.page); if( response.show_more_label ) { this.find( ".cr-show-more-reviews-prd" ).text( response.show_more_label ); } if ( response.count_row ) { this.find(".cr-count-row .cr-count-row-count").html( response.count_row ); } if(!response.last_page){ this.find(".cr-show-more-reviews-prd").show(); } } }, dataType: "json" } ); } ); // ajax search typing jQuery('.cr-ajax-search input').on("keyup", function(e){ if(e.keyCode == 13){ jQuery(this).parents(".cr-ajax-search").find("button").trigger("click"); } // show clear icon if(jQuery(this).val() !== "") { jQuery(this).parents(".cr-ajax-search").find(".cr-clear-input").css("display", "inline-block"); } else { jQuery(this).parents(".cr-ajax-search").find(".cr-clear-input").css("display", "none"); } }).on("change", function(){ if(jQuery(this).val() === "") jQuery(this).parents(".cr-ajax-search").find(".cr-clear-input").hide(); }); // jQuery('.cr-reviews-ajax-reviews .cr-ajax-search input').on( 'keyup', crDebounce( ( ref ) => { jQuery(ref.target).parents(".cr-reviews-ajax-comments").attr("data-page", 0); jQuery(ref.target).parents(".cr-reviews-ajax-reviews").find(".cr-ajax-reviews-list").empty(); crShowMoreReviewsPrd( jQuery(ref.target) ); }, 1000 ) ); // clear search field jQuery(".cr-ajax-search .cr-clear-input").on("click", function () { jQuery(this).prev("input").val(""); jQuery(this).parents(".cr-ajax-search").find(".cr-clear-input").hide(); jQuery(this).parents(".cr-ajax-search").find("button").trigger("click"); // if( jQuery(this).parents(".cr-reviews-ajax-reviews").length ) { // clear search in the case of product pages jQuery(this).parents(".cr-reviews-ajax-comments").attr("data-page", 0); jQuery(this).parents(".cr-reviews-ajax-reviews").find(".cr-ajax-reviews-list").empty(); crShowMoreReviewsPrd( jQuery(this) ); } }); // ajax search of reviews jQuery(".cr-ajax-search button").on("click", function (e) { e.preventDefault(); //search in the all reviews block if( jQuery(this).parents(".cr-all-reviews-shortcode").length ){ // search in ajax version of the All Reviews block / shortcode cr_filter_all_reviews( jQuery(this) ); } else { jQuery(this).parents(".cr-reviews-ajax-comments").attr("data-page", 0); jQuery(this).parents(".cr-reviews-ajax-comments").find(".cr-ajax-reviews-list").empty(); crShowMoreReviewsPrd( jQuery(this) ); } }); jQuery(".cr-ajax-reviews-add-review, .cr-nosummary-add").on( "click", function(t) { t.preventDefault(); jQuery(this).closest(".cr-reviews-ajax-reviews").find(".cr-reviews-ajax-comments").hide(); jQuery(this).closest(".cr-reviews-ajax-reviews").find(".cr-ajax-reviews-review-form").show(); } ); // click to filter reviews by tags jQuery(".cr-review-tags-filter span.cr-tags-filter").on( "click", function (e) { e.preventDefault(); if(jQuery(this).hasClass("cr-tag-selected")) { jQuery(this).removeClass("cr-tag-selected"); } else { jQuery(this).addClass("cr-tag-selected"); } if ( jQuery(this).parents(".cr-all-reviews-shortcode").length ) { // tags filtering in the all reviews shortcode cr_filter_all_reviews( jQuery(this) ); } else { // tags filtering on a product page jQuery(this).parents(".cr-reviews-ajax-comments").attr("data-page", 0); jQuery(this).parents(".cr-reviews-ajax-comments").find(".cr-ajax-reviews-list").empty(); crShowMoreReviewsPrd( jQuery(this) ); } } ); //open popup window with pictures jQuery(".cr-comment-image-top .cr-comment-image-top-item").on( "click", function(t) { t.preventDefault(); jQuery("body").addClass("cr-noscroll"); let slide_no = jQuery(this).data("slide"); let imgParent = jQuery(this).closest(".cr-ajax-reviews-cus-images-div").parent(); imgParent.find(".cr-ajax-reviews-cus-images-modal-cont").addClass("cr-mask-active"); imgParent.find(".cr-ajax-reviews-cus-images-modal .cr-ajax-reviews-cus-images-slider-main").slickk('setPosition'); imgParent.find(".cr-ajax-reviews-cus-images-modal .cr-ajax-reviews-cus-images-slider-nav").slickk('setPosition'); if ( typeof slide_no !== 'undefined' ) { imgParent.find(".cr-ajax-reviews-cus-images-modal .cr-ajax-reviews-cus-images-slider-main").slickk('slickGoTo', slide_no, true); imgParent.find(".cr-ajax-reviews-cus-images-modal .cr-ajax-reviews-cus-images-slider-nav").slickk('slickGoTo', slide_no, true); } } ); jQuery(".cr-comment-image-top .cr-comment-videoicon").on( "click", function(t) { jQuery(this).closest( ".cr-comment-image-top" ).find( ".cr-comment-image-top-item" ).trigger( "click" ); } ); //close popup window with pictures jQuery(".cr-ajax-reviews-cus-images-modal-cont, .cr-ajax-reviews-cus-images-modal .cr-ajax-reviews-cus-images-close").on( "click", function(t) { t.preventDefault(); let closeParent = jQuery(this).closest(".cr-ajax-reviews-cus-images-modal-cont.cr-mask-active"); closeParent.find(".cr-ajax-reviews-cus-images-modal .cr-ajax-reviews-cus-images-slider-main").slickk('slickGoTo',0,true); closeParent.find(".cr-ajax-reviews-cus-images-modal .cr-ajax-reviews-cus-images-slider-nav").slickk('slickGoTo',0,true); closeParent.removeClass("cr-mask-active"); jQuery("body").removeClass("cr-noscroll"); } ); jQuery(".cr-ajax-reviews-cus-images-modal-cont .cr-ajax-reviews-cus-images-modal").on( "click", function(t) { t.stopPropagation(); } ); //Product variations jQuery(".single_variation_wrap").on( "show_variation", function ( event, variation ) { if(jQuery(".cr_gtin").length){ jQuery(".cr_gtin_val").text(variation._cr_gtin); } if(jQuery(".cr_mpn").length){ jQuery(".cr_mpn_val").text(variation._cr_mpn); } if(jQuery(".cr_brand").length){ jQuery(".cr_brand_val").text(variation._cr_brand); } }); //Reset Product variations jQuery(document).on('reset_data', function () { var cr_gtin = jQuery(".cr_gtin"), cr_mpn = jQuery(".cr_mpn"), cr_brand = jQuery(".cr_brand"); if(cr_gtin.length){ jQuery(".cr_gtin_val").text(cr_gtin.data("o_content")); } if(cr_mpn.length){ jQuery(".cr_mpn_val").text(cr_mpn.data("o_content")); } if(cr_brand.length){ jQuery(".cr_brand_val").text(cr_brand.data("o_content")); } }); // show more ajax reviews in the all reviews block jQuery('.cr-all-reviews-shortcode .cr-show-more-button').on("click", function (e) { e.preventDefault(); cr_filter_all_reviews( jQuery(this), true ); }); jQuery('.cr-all-reviews-shortcode').on("click", ".cr-page-numbers-a", function (e) { e.preventDefault(); cr_filter_all_reviews( jQuery(this), true ); }); // filter ajax reviews in the all reviews block jQuery(".cr-all-reviews-shortcode").on("click", ".cr-histogram-a, .cr-seeAllReviews", function(t){ t.preventDefault(); let cr_rating = jQuery(this).data("rating"); jQuery("div.ivole-summaryBox tr.ivole-histogramRow.ivole-histogramRow-s").removeClass("ivole-histogramRow-s"); if ( cr_rating > 0 ) { jQuery(this).closest("tr.ivole-histogramRow").addClass("ivole-histogramRow-s"); } jQuery(this).parents(".cr-all-reviews-shortcode").find(".cr-review-tags-filter .cr-tag-selected").removeClass("cr-tag-selected"); cr_filter_all_reviews( jQuery(this) ); }); // show more ajax reviews in the grid jQuery( ".cr-reviews-grid .cr-show-more-button" ).on( "click", function (e) { e.preventDefault(); let $this = jQuery(this), $spinner = $this.next(".cr-show-more-spinner"), cr_rating = $this.parents(".cr-reviews-grid").find(".ivole-summaryBox.cr-grid-reviews-ajax tr.ivole-histogramRow.ivole-histogramRow-s .cr-histogram-a").attr("data-rating"), attributes = $this.parents(".cr-reviews-grid").data("attributes"); attributes.comment__not_in = $this.parents(".cr-reviews-grid").find(".cr-review-card.cr-card-product").map( function() { return jQuery(this).data("reviewid"); } ).get(); attributes.comment__not_in = attributes.comment__not_in.concat( $this.parents(".cr-reviews-grid").find(".cr-review-card.cr-card-shop").map(function(){ return jQuery(this).data("reviewid"); }).get() ); var grid_data = { 'action': "ivole_show_more_grid_reviews", 'rating': cr_rating, 'attributes': attributes }; $this.hide(); $spinner.show(); jQuery.post(cr_ajax_object.ajax_url, grid_data, function(response) { $spinner.hide(); $reviews = jQuery(response.html).find(".cr-review-card"); if($reviews.length){ $this.parents(".cr-reviews-grid").find(".cr-reviews-grid-inner").colcade("append", $reviews); $this.show(); } else { $this.hide(); } }).fail(function(response) { $spinner.hide(); $this.show(); $this.parent().append('
'+response.responseText+'
'); }); }); jQuery(".cr-reviews-grid .cr-summaryBox-wrap").on("click", ".cr-histogram-a, .cr-seeAllReviews", function(e){ e.preventDefault(); let $this = jQuery(this), $grid = $this.parents(".cr-reviews-grid"), $spinner = $grid.find(".cr-show-more-spinner"), cr_rating = $this.attr("data-rating"), attributes = $grid.data("attributes"); attributes.show_more = attributes.count + attributes.count_shop_reviews; attributes.comment__not_in = []; if(!cr_rating) cr_rating = 0; var grid_data = { 'action': "ivole_show_more_grid_reviews", 'rating': cr_rating, 'attributes': attributes }; $grid.find("div.ivole-summaryBox tr.ivole-histogramRow.ivole-histogramRow-s").removeClass("ivole-histogramRow-s"); if( cr_rating > 0 ) { $this.closest("tr.ivole-histogramRow").addClass("ivole-histogramRow-s"); } $grid.find(".cr-reviews-grid-inner").hide(); $grid.find(".cr-show-more-button").hide(); $spinner.show(); $grid.find("div.ivole-summaryBox").addClass("cr-summaryBar-updating"); jQuery.post(cr_ajax_object.ajax_url, grid_data, function(response) { $spinner.hide(); $grid.find(".cr-show-more-button").show(); $grid.find(".cr-summaryBox-wrap .cr-count-filtered-reviews").empty(); $reviews = jQuery(response.html).find(".cr-review-card"); if($reviews.length){ $grid.find(".cr-reviews-grid-inner").colcade("empty"); $grid.find(".cr-reviews-grid-inner").show(); $grid.find(".cr-reviews-grid-inner").colcade("append", $reviews); $grid.find("div.ivole-summaryBox").removeClass("cr-summaryBar-updating"); $grid.find(".cr-summaryBox-wrap .cr-count-filtered-reviews").append(jQuery(response.html).find(".cr-count-filtered-reviews").html()); } }).fail(function(response) { $spinner.hide(); $this.parent().append('
'+response.responseText+'
'); }); }); jQuery('#cr_floatingtrustbadge').on( "click", function() { if( !jQuery(this).hasClass( 'cr-floatingbadge-big' ) ) { jQuery(this).find('div.cr-badge.badge_size_compact').hide(); jQuery(this).find('div.cr-badge.badge--wide-mobile').css( 'display', 'block' ); jQuery(this).find('div.cr-floatingbadge-close').css( 'display', 'block' ); jQuery(this).addClass( 'cr-floatingbadge-big' ); //update colors var crcolors = jQuery(this).data('crcolors'); if (typeof crcolors !== 'undefined') { jQuery(this).css( 'border-color', crcolors['big']['border'] ); jQuery(this).find('div.cr-floatingbadge-background-top').css( 'background-color', crcolors['big']['top'] ); jQuery(this).find('div.cr-floatingbadge-background-middle').css( 'background-color', crcolors['big']['middle'] ); jQuery(this).find('div.cr-floatingbadge-background-bottom').css( 'background-color', crcolors['big']['bottom'] ); jQuery(this).find('div.cr-floatingbadge-background-bottom').css( 'border-color', crcolors['big']['border'] ); } } } ); jQuery('#cr_floatingtrustbadge .cr-floatingbadge-close').on( "click", function(event) { if( jQuery('#cr_floatingtrustbadge').hasClass( 'cr-floatingbadge-big' ) ) { jQuery(this).closest('#cr_floatingtrustbadge').find('div.cr-badge.badge--wide-mobile').hide(); jQuery(this).closest('#cr_floatingtrustbadge').find('div.cr-badge.badge_size_compact').css( 'display', 'block' ); jQuery(this).closest('#cr_floatingtrustbadge').removeClass( 'cr-floatingbadge-big' ); //update colors var crcolors = jQuery(this).closest('#cr_floatingtrustbadge').data('crcolors'); if (typeof crcolors !== 'undefined') { jQuery(this).closest('#cr_floatingtrustbadge').css( 'border-color', crcolors['small']['border'] ); jQuery(this).closest('#cr_floatingtrustbadge').find('div.cr-floatingbadge-background-top').css( 'background-color', crcolors['small']['top'] ); jQuery(this).closest('#cr_floatingtrustbadge').find('div.cr-floatingbadge-background-middle').css( 'background-color', crcolors['small']['middle'] ); jQuery(this).closest('#cr_floatingtrustbadge').find('div.cr-floatingbadge-background-bottom').css( 'background-color', crcolors['small']['bottom'] ); jQuery(this).closest('#cr_floatingtrustbadge').find('div.cr-floatingbadge-background-bottom').css( 'border-color', crcolors['small']['border'] ); } } else { jQuery('#cr_floatingtrustbadge').hide(); document.cookie = 'cr_hide_trustbadge=true; path=/; max-age='+60*60*24+';'; } event.stopPropagation(); } ); jQuery( '.cr-reviews-slider' ).on( 'click', '.cr-slider-read-more a', function (e) { e.preventDefault(); let parent = jQuery(this).parents(".review-text"); parent.find(".cr-slider-read-more").hide(); parent.find(".cr-slider-details").css("display", "inline"); jQuery(this).parents(".cr-reviews-slider").slickk('setPosition'); } ); jQuery( '.cr-reviews-slider' ).on( 'click', '.cr-slider-read-less a', function (e) { e.preventDefault(); let parent = jQuery(this).parents(".review-text"); parent.find(".cr-slider-details").hide(); parent.find(".cr-slider-read-more").css("display", "inline"); jQuery(this).parents(".cr-reviews-slider").slickk('setPosition'); } ); jQuery('.cr-qna-block .cr-qna-search-block .cr-qna-ask-button').on( 'click', function (e) { e.preventDefault(); jQuery( this ).closest( '.cr-qna-block' ).addClass( 'cr-qna-new-q-form-open' ); } ); jQuery(".cr-qna-block .cr-qna-list-block").on( "click", ".cr-qna-ans-button", function (e) { e.preventDefault(); let nameField = jQuery( this ).closest( '.cr-qna-block' ).find( ".cr-qna-new-q-form .cr-review-form-name" ); let nameValue = nameField.find( ".cr-review-form-txt" ).data("defval"); jQuery( this ).closest( '.cr-qna-list-q-b' ).find( ".cr-qna-list-inl-answ .cr-review-form-name .cr-review-form-txt" ).val( nameValue ); let emailField = jQuery( this ).closest( '.cr-qna-block' ).find( ".cr-qna-new-q-form .cr-review-form-email" ); let emailValue = emailField.find( ".cr-review-form-txt" ).data("defval"); jQuery( this ).closest( '.cr-qna-list-q-b' ).find( ".cr-qna-list-inl-answ .cr-review-form-email .cr-review-form-txt" ).val( emailValue ); jQuery( this ).closest( '.cr-qna-list-q-b' ).addClass( 'cr-qna-ans-form-open' ); } ); //show more questions and answers jQuery(".cr-qna-block").on( "click", ".cr-show-more-que", function(t) { t.preventDefault(); let qna_block = jQuery(this).parents(".cr-qna-block").eq(0); let cr_product_id = jQuery(this).attr("data-product"); let cr_page = jQuery(this).attr("data-page"); let cr_attributes = qna_block.data("attributes"); let cr_search = qna_block.find(".cr-ajax-qna-search input").val(); let cr_permalink = jQuery(this).attr("data-permalink"); let cr_data = { "action": "cr_show_more_qna", "productID": cr_product_id, "page": cr_page, "permalink": cr_permalink, "search": cr_search, "cr_attributes": cr_attributes }; qna_block.find(".cr-search-no-qna").hide(); jQuery(this).hide(); qna_block.find("#cr-show-more-q-spinner").show(); jQuery.post(cr_ajax_object.ajax_url, cr_data, function(response) { jQuery(".cr-qna-block #cr-show-more-q-spinner").hide(); if(response.page >= 0){ jQuery(".cr-qna-block .cr-qna-list-block .cr-qna-list-block-inner").append(response.html); jQuery(".cr-qna-block #cr-show-more-q-id").attr("data-page",response.page); if(!response.last_page){ jQuery(".cr-qna-block #cr-show-more-q-id").show(); } } if(response.html === "" && response.page === 0){ jQuery(".cr-qna-block .cr-search-no-qna").show(); } }, "json"); } ); //search questions and answers jQuery(".cr-qna-block .cr-ajax-qna-search input").on("keyup", cr_keyup_delay(function(e) { // do nothing if it's an arrow key var code = (e.keyCode || e.which); if(code == 37 || code == 38 || code == 39 || code == 40) { return; } jQuery(".cr-qna-block #cr-show-more-q-id").attr("data-page", -1); jQuery(".cr-qna-block .cr-qna-list-block .cr-qna-list-block-inner").empty(); jQuery(".cr-qna-block #cr-show-more-q-id").trigger("click"); }, 500)); jQuery(".cr-qna-block .cr-ajax-qna-search input").on("keyup", function(e){ //show clear icon if(jQuery(this).val() !== "") { jQuery(".cr-qna-block .cr-ajax-qna-search .cr-clear-input").css("display", "inline-block"); } else { if(jQuery(this).val() === "") jQuery(".cr-qna-block .cr-ajax-qna-search .cr-clear-input").hide(); } }).on("change", function(){ if(jQuery(this).val() === "") jQuery(".cr-qna-block .cr-ajax-qna-search .cr-clear-input").hide(); }); jQuery(".cr-qna-block .cr-ajax-qna-search .cr-clear-input").on("click", function () { jQuery(this).prev("input").val(""); jQuery(".cr-qna-block .cr-ajax-qna-search .cr-clear-input").hide(); jQuery(".cr-qna-block #cr-show-more-q-id").attr("data-page", -1); jQuery(".cr-qna-block .cr-qna-list-block .cr-qna-list-block-inner").empty(); jQuery(".cr-qna-block #cr-show-more-q-id").trigger("click"); }); //show QnA tab jQuery("body").on("click", "a.cr-qna-link", function () { const cr_qna_tab = jQuery( '.cr_qna_tab a' ); if( cr_qna_tab.length ) { cr_qna_tab.trigger( "click" ); } else { jQuery( '.cr-qna-block' ).parents( ':hidden' ).show(); } return true; }); // show Reviews tab jQuery("body").on("click", ".cr-review-link", function () { const wc_reviews_tab = jQuery( '.reviews_tab a' ); if( wc_reviews_tab.length ) { wc_reviews_tab.trigger( "click" ); return true; } }); // upload images with a review jQuery("#cr_review_image").on("change", function () { jQuery(".cr-upload-images-status").removeClass("cr-upload-images-status-error"); jQuery(".cr-upload-images-status").text(cr_ajax_object.cr_upload_initial); let allowedTypes = ['image/jpeg', 'image/png', 'image/jpg', 'image/gif', 'video/mp4', 'video/mpeg', 'video/ogg', 'video/webm', 'video/quicktime', 'video/x-msvideo']; let uploadFiles = jQuery("#cr_review_image"); let countFiles = uploadFiles[0].files.length; let countUploaded = jQuery(".cr-upload-images-preview .cr-upload-images-containers").length; let lastIndex = 1; let cr_captcha = ""; if(jQuery(this).attr("data-lastindex")) { lastIndex = parseInt(jQuery(this).attr("data-lastindex")); } if( countFiles + countUploaded > cr_ajax_object.cr_images_upload_limit ) { jQuery(".cr-upload-images-status").addClass("cr-upload-images-status-error"); jQuery(".cr-upload-images-status").text(cr_ajax_object.cr_upload_error_too_many); jQuery(".cr-upload-images-preview .cr-upload-images-containers").not(".cr-upload-ok").remove(); uploadFiles.val(""); return; } for(let i = 0; i < countFiles; i++) { if(!allowedTypes.includes(uploadFiles[0].files[i].type) ) { jQuery(".cr-upload-images-status").addClass("cr-upload-images-status-error"); jQuery(".cr-upload-images-status").text(cr_ajax_object.cr_upload_error_file_type); jQuery(".cr-upload-images-preview .cr-upload-images-containers").not(".cr-upload-ok").remove(); uploadFiles.val(""); return; } else if(uploadFiles[0].files[i].size && uploadFiles[0].files[i].size > cr_ajax_object.cr_images_upload_max_size) { jQuery(".cr-upload-images-status").addClass("cr-upload-images-status-error"); jQuery(".cr-upload-images-status").text(cr_ajax_object.cr_upload_error_file_size); jQuery(".cr-upload-images-preview .cr-upload-images-containers").not(".cr-upload-ok").remove(); uploadFiles.val(""); return; } else { let container = jQuery("
", {class:"cr-upload-images-containers cr-upload-images-container-" + (lastIndex + i)}); let progressBar = jQuery("
", {class:"cr-upload-images-pbar"}); progressBar.append( jQuery("
", {class:"cr-upload-images-pbarin"}) ); if( -1 === uploadFiles[0].files[i].type.indexOf( 'image' ) ) { container.append( jQuery( "" ) ); } else{ container.append( jQuery("", {class:"cr-upload-images-thumbnail",src:URL.createObjectURL(uploadFiles[0].files[i])}) ); } container.append( progressBar ); let removeButton = jQuery("