1jQuery(window).on('elementor/frontend/init', () => { 2 'use strict'; 3 elementorFrontend.hooks.addAction('frontend/element_ready/woocommerce-photo-reviews.default', function ($scope) { 4 if (!window.elementor) { 5 return; 6 } 7 wcpr_helpful_button(); 8 }) 9}); 10jQuery(document).ready(function ($) { 11 'use strict'; 12 let image_caption_enable = woocommerce_photo_reviews_params.image_caption_enable == 1; 13 let i18n_image_caption = woocommerce_photo_reviews_params.i18n_image_caption; 14 15 function getSelectedImageHtml(src, name) { 16 let selectImageHtml; 17 if (image_caption_enable) { 18 selectImageHtml = `<div class="wcpr-selected-image"><img title="${name}" src="${src}" class="wcpr-selected-image-preview"><div class="wcpr-selected-image-info"><div class="wcpr-selected-image-name" title="${name}">${name}</div><input class="wcpr-selected-image-caption" type="text" name="wcpr_image_caption[]" placeholder="${i18n_image_caption}"></div></div>`; 19 } else { 20 selectImageHtml = `<div class="wcpr-selected-image"><img title="${name}" src="${src}" class="wcpr-selected-image-preview"><div class="wcpr-selected-image-info"><div class="wcpr-selected-image-name" title="${name}">${name}</div></div></div>`; 21 } 22 return selectImageHtml; 23 } 24 25 function readURL(input) { 26 for (let i = 0; i < input.files.length; i++) { 27 var reader = new FileReader(); 28 29 reader.onload = function (e) { 30 $(input).parent().find('.wcpr-selected-image-container').append(getSelectedImageHtml(e.target.result, input.files[i].name)) 31 }; 32 33 reader.readAsDataURL(input.files[i]); // convert to base64 string 34 } 35 } 36 37 /*helpful button*/ 38 wcpr_helpful_button(); 39 let max_files = woocommerce_photo_reviews_params.max_files; 40 $('#commentform').on('change', '.wcpr_image_upload', function (e) { 41 $(this).parent().find('.wcpr-selected-image-container').html(''); 42 if (this.files.length > max_files) { 43 alert(woocommerce_photo_reviews_params.warning_max_files); 44 $(this).val(''); 45 return false; 46 } else if (this.files.length > 0) { 47 readURL(this); 48 } 49 }); 50 51 $('#commentform').find('input[type="submit"]').on('click', function (e) { 52 let $container = $(this).closest('form'); 53 let $content = $container.find('textarea[id="comment"]')|| $container.find('textarea[name="comment"]'); 54 let $name = $container.find('input[name="author"]'); 55 let $email = $container.find('input[name="email"]'); 56 if ($content.length > 0 && !$content.val() && woocommerce_photo_reviews_params.allow_empty_comment != 1) { 57 alert(woocommerce_photo_reviews_params.i18n_required_comment_text); 58 e.preventDefault(); 59 $content.focus(); 60 return false; 61 } 62 if ('on' === woocommerce_photo_reviews_params.enable_photo) { 63 let $fileUpload = $container.find('.wcpr_image_upload'); 64 if ($fileUpload.length > 0) { 65 let imagesCount = parseInt($fileUpload.get(0).files.length); 66 if ('on' === woocommerce_photo_reviews_params.required_image && imagesCount === 0) { 67 alert(woocommerce_photo_reviews_params.warning_required_image); 68 e.preventDefault(); 69 return false; 70 } 71 if (imagesCount > max_files) { 72 alert(woocommerce_photo_reviews_params.warning_max_files); 73 e.preventDefault(); 74 return false; 75 } 76 } else if ('on' === woocommerce_photo_reviews_params.required_image) { 77 alert(woocommerce_photo_reviews_params.warning_required_image); 78 e.preventDefault(); 79 return false; 80 } 81 } 82 if ($name.length > 0 && !$name.val()) { 83 alert(woocommerce_photo_reviews_params.i18n_required_name_text); 84 e.preventDefault(); 85 $name.focus(); 86 return false;
87 } 88 if ($email.length > 0 && !$email.val()) { 89 alert(woocommerce_photo_reviews_params.i18n_required_email_text); 90 e.preventDefault(); 91 $email.focus(); 92 return false; 93 } 94 if ($container.find('input[name="wcpr_gdpr_checkbox"]').prop('checked') === false) { 95 alert(woocommerce_photo_reviews_params.warning_gdpr); 96 e.preventDefault(); 97 return false; 98 } 99 }); 100 let comments = woocommerce_photo_reviews_params.hasOwnProperty('comments_container_id') ? woocommerce_photo_reviews_params.comments_container_id : 'comments'; 101 let $comments = $('#' + comments); 102 $comments.prepend($('.wcpr-filter-container')).prepend($('.wcpr-overall-rating-and-rating-count')).prepend($('.woocommerce-Reviews-title').eq(0)); 103 let $pagination_container = $comments.find('.woocommerce-pagination'); 104 if ($('.wcpr-load-more-reviews-button-modal').length) { 105 $pagination_container.html($('.wcpr-load-more-reviews-button-modal').html()); 106 } 107 $(document).on('click', '.reviews_tab', function () { 108 $comments = $('#' + comments); 109 if (($('.wcpr-filter-container').length > 0 && $comments.find('.wcpr-filter-container').length === 0) || ($('.wcpr-overall-rating-and-rating-count').length > 0 && $comments.find('.wcpr-overall-rating-and-rating-count').length === 0)) { 110 $comments.prepend($('.wcpr-filter-container')).prepend($('.wcpr-overall-rating-and-rating-count')).prepend($('.woocommerce-Reviews-title').eq(0)); 111 } 112 }) 113}); 114 115function wcpr_helpful_button() { 116 'use strict'; 117 jQuery(document).on('click','.wcpr-comment-helpful-button', function (e) { 118 e.stopPropagation(); 119 let button = jQuery(this); 120 let vote = button.hasClass('wcpr-comment-helpful-button-up-vote') ? 'up' : 'down'; 121 let container = button.closest('.wcpr-comment-helpful-button-container'); 122 let comment_id = container.data('comment_id'); 123 if (vote === 'up' && container.hasClass('wcpr-comment-helpful-button-voted-up')) { 124 return; 125 } 126 if (vote === 'down' && container.hasClass('wcpr-comment-helpful-button-voted-down')) { 127 return; 128 } 129 if (container.hasClass('wcpr-comment-helpful-button-voting')) { 130 return; 131 } 132 container.addClass('wcpr-comment-helpful-button-voting'); 133 jQuery.ajax({ 134 url: woocommerce_photo_reviews_params.ajaxurl, // AJAX handler, declared before 135 data: { 136 'action': 'wcpr_helpful_button_handle', 137 'vote': vote, 138 'comment_id': comment_id, 139 // 'nonce': woocommerce_photo_reviews_params.nonce, 140 }, 141 type: 'POST', 142 success: function (response) { 143 if (response.status === 'success') { 144 container.find('.wcpr-comment-helpful-button-up-vote-count').html(parseInt(response.up)); 145 container.find('.wcpr-comment-helpful-button-down-vote-count').html(parseInt(response.down)); 146 if (vote === 'up') { 147 container.removeClass('wcpr-comment-helpful-button-voted-down').addClass('wcpr-comment-helpful-button-voted-up'); 148 } else { 149 container.removeClass('wcpr-comment-helpful-button-voted-up').addClass('wcpr-comment-helpful-button-voted-down'); 150 } 151 if (container.parent().hasClass('reviews-content-right-meta') || container.parent().hasClass('shortcode-reviews-content-right-meta')) { 152 let comment_container = jQuery('.wcpr-comment-helpful-button-container[data-comment_id="' + comment_id + '"]'); 153 comment_container.find('.wcpr-comment-helpful-button-up-vote-count').html(parseInt(response.up)); 154 comment_container.find('.wcpr-comment-helpful-button-down-vote-count').html(parseInt(response.down)); 155 if (vote === 'up') { 156 comment_container.removeClass('wcpr-comment-helpful-button-voted-down').addClass('wcpr-comment-helpful-button-voted-up'); 157 } else { 158 comment_container.removeClass('wcpr-comment-helpful-button-voted-up').addClass('wcpr-comment-helpful-button-voted-down'); 159 } 160 } 161 } 162 }, 163 error: function () { 164 165 }, 166 complete: function () { 167 container.removeClass('wcpr-comment-helpful-button-voting'); 168 } 169 }); 170 }); 171} 172 173function viSwipeDetect(el, callback) { 174 var touchsurface = el, 175 swipedir, 176 startX, 177 startY, 178 distX, 179 distY, 180 threshold = 150, //required min distance traveled to be considered swipe 181 restraint = 100, // maximum distance allowed at the same time in perpendicular direction 182 allowedTime = 300, // maximum time allowed to travel that distance 183 elapsedTime, 184 startTime, 185 handleswipe = callback || function (swipedir) { 186 }; 187 188 touchsurface.addEventListener( 189 "touchstart", 190 function (e) { 191 var touchobj = e.changedTouches[0]; 192 swipedir = "none"; 193 startX = touchobj.pageX; 194 startY = touchobj.pageY; 195 startTime = new Date().getTime(); // record time when finger first makes contact with surface 196 }, 197 false 198 ); 199 200 touchsurface.addEventListener( 201 "touchmove", 202 function (e) { 203 e.preventDefault(); // prevent scrolling when inside DIV 204 }, 205 false 206 ); 207 208 touchsurface.addEventListener( 209 "touchend", 210 function (e) { 211 var touchobj = e.changedTouches[0]; 212 distX = touchobj.pageX - startX; // get horizontal dist traveled by finger while in contact with surface 213 distY = touchobj.pageY - startY; // get vertical dist traveled by finger while in contact with surface 214 elapsedTime = new Date().getTime() - startTime; // get time elapsed 215 if (elapsedTime <= allowedTime) { 216 // first condition for awipe met 217 if (Math.abs(distX) >= threshold && Math.abs(distY) <= restraint) { 218 // 2nd condition for horizontal swipe met 219 swipedir = distX < 0 ? "left" : "right"; // if dist traveled is negative, it indicates left swipe 220 } else if ( 221 Math.abs(distY) >= threshold && 222 Math.abs(distX) <= restraint 223 ) { 224 // 2nd condition for vertical swipe met 225 swipedir = distY < 0 ? "up" : "down"; // if dist traveled is negative, it indicates up swipe 226 } 227 } 228 handleswipe(swipedir); 229 }, 230 false 231 ); 232}
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.