1(function( $, window, document ) { 2 'use strict'; 3 4 /*======================================== 5 * Start pagination defination 6 *========================================*/ 7 var Paginator = function(element, options) { 8 this.el = $(element); 9 this.options = $.extend({}, $.fn.paginathing.defaults, options); 10 if( this.options.page != '' && this.options.page != undefined ) { 11 this.currentPage = this.options.page; 12 } else { 13 this.currentPage = 1; 14 } 15 this.startPage = 1; 16 //this.totalItems = this.el.children().length; 17 this.totalItems = this.options.totalItems; 18 this.totalPages = Math.max(Math.ceil(this.options.totalItems / this.options.perPage), this.options.limitPagination); 19 this.container = $('<div></div>').addClass(this.options.containerClass); 20 this.ul = $('<ul></ul>').addClass(this.options.ulClass); 21 this.show(this.startPage); 22 return this; 23 }; 24 25 Paginator.prototype = { 26 pagination: function(type, page) { 27 var _self = this; 28 var li = $('<li></li>'); 29 var a = $('<a></a>').attr('href', '#'); 30 var cssClass = type === 'number' ? _self.options.liClass : type; 31 var text = ''; 32 if (type === 'number') { 33 text = page; 34 } else if (type === 'pageNumbers') { 35 //get the page numbers text 36 //text = _self.paginationNumbersText(); 37 } else { 38 text = _self.paginationText(type); 39 } 40 li.addClass(cssClass); 41 li.data('pagination-type', type); 42 li.data('page', page); 43 li.append(a.html(text)); 44 return li; 45 }, 46 47 paginationText: function(type) { 48 return this.options[type + 'Text']; 49 }, 50 51 paginationNumbersText: function() { 52 var _self = this; 53 return 'Page ' + _self.currentPage + '/' + _self.totalPages; 54 }, 55 56 buildPagination: function() { 57 var _self = this; 58 var pagination = []; 59 var prev = 60 _self.currentPage - 1 < _self.startPage 61 ? _self.startPage 62 : _self.currentPage - 1; 63 var next = 64 _self.currentPage + 1 > _self.totalPages 65 ? _self.totalPages 66 : _self.currentPage + 1; 67 68 var start, end; 69 var limit = _self.options.limitPagination; 70 71 if (limit) { 72 if (_self.currentPage <= Math.ceil(limit / 2) + 1) { 73 start = 1; 74 end = limit; 75 } else if ( 76 _self.currentPage + Math.floor(limit / 2) >= 77 _self.totalPages 78 ) { 79 start = _self.totalPages + 1 - limit; 80 end = _self.totalPages; 81 } else { 82 start = _self.currentPage - Math.ceil(limit / 2); 83 // end = _self.currentPage + Math.floor(limit / 2); 84 end = this.options.page 85 } 86 } else { 87 start = _self.startPage; 88 end = _self.totalPages; 89 } 90 // "First" button 91 if (_self.options.firstLast) { 92 pagination.push(_self.pagination('first', _self.startPage)); 93 } 94 // "Prev" button 95 if (_self.options.prevNext) { 96 pagination.push(_self.pagination('prev', prev)); 97 } 98 99 // Pagination 100 for (var i = start; i <= end; i++) { 101 pagination.push(_self.pagination('number', i)); 102 } 103 // "Next" button 104 if (_self.options.prevNext) { 105 pagination.push(_self.pagination('next', next)); 106 } 107 // "Last" button 108 if (_self.options.firstLast) { 109 pagination.push(_self.pagination('last', _self.totalPages)); 110 } 111 112 return pagination; 113 }, 114 115 render: function(page) { 116 var _self = this; 117 var options = _self.options; 118 var pagination = _self.buildPagination(); 119 // Remove children before re-render (prevent duplicate) 120 _self.ul.children().remove(); 121 _self.ul.append(pagination); 122 // Manage active DOM 123 var startAt = page === 1 ? 0 : (page - 1) * options.perPage; 124 var endAt = page * options.perPage; 125 _self.el.children().hide(); 126 _self.el 127 .children() 128 .slice(startAt, endAt) 129 .show(); 130 // Manage active state 131 _self.ul.children().each(function() { 132 var _li = $(this); 133 var type = _li.data('pagination-type'); 134 135 switch (type) { 136 case 'number': 137 if ( _li.data('page') === _self.options.page ) { 138 _li.addClass(options.activeClass); 139 } 140 break; 141 case 'first': 142 page === _self.startPage && _li.toggleClass(options.disabledClass); 143 break; 144 case 'last': 145 page === _self.totalPages && _li.toggleClass(options.disabledClass); 146 break; 147 case 'prev': 148 page - 1 < _self.startPage && 149 _li.toggleClass(options.disabledClass); 150 break; 151 case 'next': 152 page + 1 > _self.totalPages && 153 _li.toggleClass(options.disabledClass); 154 break; 155 default: 156 break; 157 } 158 }); 159 160 // If insertAfter is defined 161 if (options.insertAfter) {
162 _self.container.append(_self.ul).insertAfter($(options.insertAfter)); 163 } else { 164 _self.el.after(_self.container.append(_self.ul)); 165 } 166 }, 167 168 handle: function() { 169 var _self = this; 170 _self.container.find('li').each(function() { 171 var _li = $(this); 172 _li.click(function(e) { 173 e.preventDefault(); 174 var page = _li.data('page'); 175 _self.currentPage = page; 176 _self.review(page); 177 }); 178 }); 179 }, 180 review: function(page) { 181 $('.rx_double_spinner').show(); 182 183 $.ajax({ 184 url: rx_ajax_data.ajax_url, 185 type: 'post', 186 data: { 187 action: 'rx_sorting', 188 selected: $('select.rx_shorting').children("option:selected").val(), 189 rx_product_id: $('.rx_product_id').val(), 190 security: $(".rx-sort-nonce").val(), 191 rx_post_type: $('#rx-sorting-post-type').val(), 192 rx_pagination: $('#rx-allow-shortcode-pagination').val(), 193 page: page, 194 per_page: $('#rx-pagination-limit').val(), 195 rx_rating: $('#rx-product-rating').val(), 196 user_id: $('#rx-user-id').val(), 197 rx_post_title: $("#rx-product-title").val(), 198 }, 199 success: function (data) { 200 $('.rx_listing .rx_double_spinner').hide(); 201 $('.rx_review_sort_list').html(data); 202 rx_image_popup(); //Popup image 203 }, 204 error:function (err) { 205 $('.rx_listing .rx_double_spinner').hide(); 206 console.log( err + 'Error....'); 207 } 208 }); 209 }, 210 show: function(page) { 211 var _self = this; 212 _self.render(page); 213 _self.handle(); 214 }, 215 }; 216 217 $.fn.paginathing = function(options) { 218 var _self = this; 219 return _self.each(function() { 220 return new Paginator(this, options); 221 }); 222 }; 223 224 $.fn.paginathing.defaults = { 225 limitPagination: true, 226 prevNext: true, 227 firstLast: true, 228 prevText: '«', 229 nextText: '»', 230 firstText: '<svg style="width: 7px; vertical-align: middle" aria-hidden="true" focusable="false" data-prefix="fas" data-icon="angle-left" class="svg-inline--fa fa-angle-left fa-w-8" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 512"><path fill="currentColor" d="M31.7 239l136-136c9.4-9.4 24.6-9.4 33.9 0l22.6 22.6c9.4 9.4 9.4 24.6 0 33.9L127.9 256l96.4 96.4c9.4 9.4 9.4 24.6 0 33.9L201.7 409c-9.4 9.4-24.6 9.4-33.9 0l-136-136c-9.5-9.4-9.5-24.6-.1-34z"></path></svg>', 231 lastText: '<svg style="width: 7px; vertical-align: middle" aria-hidden="true" focusable="false" data-prefix="fas" data-icon="angle-right" class="svg-inline--fa fa-angle-right fa-w-8" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 512"><path fill="currentColor" d="M224.3 273l-136 136c-9.4 9.4-24.6 9.4-33.9 0l-22.6-22.6c-9.4-9.4-9.4-24.6 0-33.9l96.4-96.4-96.4-96.4c-9.4-9.4-9.4-24.6 0-33.9L54.3 103c9.4-9.4 24.6-9.4 33.9 0l136 136c9.5 9.4 9.5 24.6.1 34z"></path></svg>', 232 containerClass: 'rx_pagination', 233 ulClass: 'rx-ul-pagination', 234 liClass: 'rx-page', 235 activeClass: 'active', 236 disabledClass: 'disabled', 237 insertAfter: null, 238 pageNumbers: true, 239 }; 240 /*======================================== 241 * End pagination defination 242 *========================================*/ 243 244 $(document).ready( function() { 245 let total_reviews = $('#rx-total-review').val(); 246 let rx_pagination_limit = $("#rx-pagination-limit").val(); 247 rx_pagination_limit = parseInt(rx_pagination_limit); 248 let perPage = Math.ceil(parseInt(total_reviews) / rx_pagination_limit); 249 let limitPagination = 5; 250 if( limitPagination > perPage ) { 251 limitPagination = perPage; 252 } 253 254 if(total_reviews > rx_pagination_limit ) { 255 $('#rx-commentlist').paginathing({ 256 totalItems: total_reviews, 257 perPage: rx_pagination_limit, 258 limitPagination: limitPagination, 259 page:1, 260 pageNumbers: true 261 }) 262 } 263 }); 264 265 /*======================================== 266 * Load add review form 267 *========================================*/ 268 $(".review-on").on('click', function(){ 269 270 $('#prod-link').attr('href', $(this).attr("data-product_url")); 271 $('#prod-url').attr('href', $(this).attr("data-product_url")); 272 $("#prod-order").text($(this).attr("data-order_id")); 273 $("#prod-order-status").text($(this).attr("data-order_status")); 274 $("#img-thumb").attr("src",$(this).attr("data-product_img")); 275 $("#prod-name").text($(this).attr("data-product_name")); 276 $("#prod-qty").text($(this).attr("data-product_quantity")); 277 $("#prod-price").text($(this).attr("data-product_price")); 278 $("#rx-order-id").val($(this).attr("data-order_id")); 279 $("#rx-product-id").val($(this).attr("data-product_id")); 280 281 $("#rx-order-table").hide(); 282 $("#rx-form").removeClass('rx-hide'); 283 $(".woocommerce-MyAccount-navigation").hide(); 284 $(".woocommerce-MyAccount-content").addClass('rx-full-width'); 285 $(".woocommerce-Pagination").hide(); 286 287 }); 288 289 $(".rx-cancel").on('click', function(){ 290 $("#rx-form").addClass('rx-hide'); 291 $(".woocommerce-MyAccount-navigation").show(); 292 $(".woocommerce-MyAccount-content").removeClass('rx-full-width'); 293 $("#rx-order-table").show(); 294 $(".woocommerce-Pagination").show(); 295 $("#reviewx_title").val(""); 296 $("#rx-text").val(""); 297 $("#rx-text-error").html(""); 298 $("#rx-rating-error").html(""); 299 }); 300 301 /*======================================== 302 * Call image uploader for add review 303 *========================================*/ 304 $(document).ready( function() { 305 let file_frame; // variable for the wp.media file_frame 306 let attachment; 307 // attach a click event (or whatever you want) to some element on your page 308 $( '#rx-upload-photo' ).on( 'click', function( event ) { 309 event.preventDefault(); 310 311 // if the file_frame has already been created, just reuse it 312 if ( file_frame ) { 313 file_frame.open(); 314 return; 315 } 316 317 file_frame = wp.media.frames.file_frame = wp.media({ 318 title: $( this ).data( 'uploader_title' ), 319 button: { 320 text: $( this ).data( 'uploader_button_text' ), 321 }, 322 multiple: $(this).data('multiple') // set this to true for multiple file selection 323 }); 324 325 file_frame.on( 'select', function() { 326 attachment = file_frame.state().get('selection').toJSON(); 327 let wrapper = $('#rx-images'); //Input image wrapper 328 $('#rx-images').removeClass('rx-hide'); 329 $.each(attachment, function(index, value){ 330 if( $('#rx-upload-photo').data('multiple') == true ) { 331 $(wrapper).prepend('<div class="rx-image"><img src="'+value.url+'" alt=""><a href="javascript:void(0);" class="remove_image" title="Remove Image"><svg style="width: 15px" aria-hidden="true" focusable="false" data-prefix="fas" data-icon="times-circle" class="svg-inline--fa fa-times-circle fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
331<path fill="currentColor" d="M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm121.6 313.1c4.7 4.7 4.7 12.3 0 17L338 377.6c-4.7 4.7-12.3 4.7-17 0L256 312l-65.1 65.6c-4.7 4.7-12.3 4.7-17 0L134.4 338c-4.7-4.7-4.7-12.3 0-17l65.6-65-65.6-65.1c-4.7-4.7-4.7-12.3 0-17l39.6-39.6c4.7-4.7 12.3-4.7 17 0l65 65.7 65.1-65.6c4.7-4.7 12.3-4.7 17 0l39.6 39.6c4.7 4.7 4.7 12.3 0 17L312 256l65.6 65.1z"></path></svg></a><input type="hidden" name="rx-image" value="'+value.id+'"></div>'); // display image 332 } else { 333 $(wrapper).find('.rx-image').remove(); 334 $(wrapper).prepend('<div class="rx-image"><img src="'+value.url+'" alt=""><a href="javascript:void(0);" class="remove_image" title="Remove Image"><svg style="width: 15px" aria-hidden="true" focusable="false" data-prefix="fas" data-icon="times-circle" class="svg-inline--fa fa-times-circle fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm121.6 313.1c4.7 4.7 4.7 12.3 0 17L338 377.6c-4.7 4.7-12.3 4.7-17 0L256 312l-65.1 65.6c-4.7 4.7-12.3 4.7-17 0L134.4 338c-4.7-4.7-4.7-12.3 0-17l65.6-65-65.6-65.1c-4.7-4.7-4.7-12.3 0-17l39.6-39.6c4.7-4.7 12.3-4.7 17 0l65 65.7 65.1-65.6c4.7-4.7 12.3-4.7 17 0l39.6 39.6c4.7 4.7 4.7 12.3 0 17L312 256l65.6 65.1z"></path></svg></a><input type="hidden" name="rx-image" value="'+value.id+'"></div>'); // display image 335 } 336 337 }); 338 }); 339 340 file_frame.open(); 341 }); 342 343 let wrapper = $('#rx-images'); //Input image wrapper 344 $(wrapper).on('click', '.remove_image', function(e){ //Once remove button is clicked 345 e.preventDefault(); 346 $(this).parent().remove(); //Remove image 347 }); 348 349 // Edit review 350 let edit_file_frame; // variable for the wp.media file_frame 351 let edit_attachment; 352 // attach a click event (or whatever you want) to some element on your page 353 $( '#rx-edit-photo' ).on( 'click', function( event ) { 354 event.preventDefault(); 355 356 // if the file_frame has already been created, just reuse it 357 if ( edit_file_frame ) { 358 edit_file_frame.open(); 359 return; 360 } 361 362 edit_file_frame = wp.media.frames.edit_file_frame = wp.media({ 363 title: $(this).data( 'uploader_title' ), 364 button: { 365 text: $(this).data( 'uploader_button_text' ), 366 }, 367 multiple: $(this).data('multiple') // set this to true for multiple file selection 368 }); 369 370 edit_file_frame.on( 'select', function() { 371 edit_attachment = edit_file_frame.state().get('selection').toJSON(); 372 let wrapper = $('#rx-edit-images'); //Input image wrapper 373 $('#rx-edit-images').removeClass('rx-hide'); 374 $.each(edit_attachment, function(index, value){ 375 if( $('#rx-edit-photo').data('multiple') == true ){ 376 $(wrapper).prepend('<div class="rx-edit-image"><img src="'+value.url+'" alt=""><a href="javascript:void(0);" class="remove_edit_image" title="Remove Image"><svg style="width: 15px" aria-hidden="true" focusable="false" data-prefix="fas" data-icon="times-circle" class="svg-inline--fa fa-times-circle fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm121.6 313.1c4.7 4.7 4.7 12.3 0 17L338 377.6c-4.7 4.7-12.3 4.7-17 0L256 312l-65.1 65.6c-4.7 4.7-12.3 4.7-17 0L134.4 338c-4.7-4.7-4.7-12.3 0-17l65.6-65-65.6-65.1c-4.7-4.7-4.7-12.3 0-17l39.6-39.6c4.7-4.7 12.3-4.7 17 0l65 65.7 65.1-65.6c4.7-4.7 12.3-4.7 17 0l39.6 39.6c4.7 4.7 4.7 12.3 0 17L312 256l65.6 65.1z"></path></svg></a><input type="hidden" name="rx-edit-image" value="'+value.id+'"></div>'); // display image 377 } else { 378 $(wrapper).html(""); 379 $(wrapper).prepend('<div class="rx-edit-image"><img src="'+value.url+'" alt=""><a href="javascript:void(0);" class="remove_edit_image" title="Remove Image"><svg style="width: 15px" aria-hidden="true" focusable="false" data-prefix="fas" data-icon="times-circle" class="svg-inline--fa fa-times-circle fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm121.6 313.1c4.7 4.7 4.7 12.3 0 17L338 377.6c-4.7 4.7-12.3 4.7-17 0L256 312l-65.1 65.6c-4.7 4.7-12.3 4.7-17 0L134.4 338c-4.7-4.7-4.7-12.3 0-17l65.6-65-65.6-65.1c-4.7-4.7-4.7-12.3 0-17l39.6-39.6c4.7-4.7 12.3-4.7 17 0l65 65.7 65.1-65.6c4.7-4.7 12.3-4.7 17 0l39.6 39.6c4.7 4.7 4.7 12.3 0 17L312 256l65.6 65.1z"></path></svg></a><input type="hidden" name="rx-edit-image" value="'+value.id+'"></div>'); // display image 380 } 381 }); 382 }); 383 384 edit_file_frame.open(); 385 }); 386 387 let edit_wrapper = $('#rx-edit-images'); //Input image wrapper 388 $(edit_wrapper).on('click', '.remove_edit_image', function(e){ //Once remove button is clicked 389 e.preventDefault(); 390 $(this).parent().remove(); //Remove image 391 }); 392 }); 393 394 /*======================================== 395 * Review submit from my account 396 *========================================*/ 397 398 $("#rx-submit").on('click', function(){ 399 400 let formInput = $("#rx-form input"); // grab all input field 401 let review_title = $("#reviewx_title").val(); // grab review text 402 let review_text = $("#rx_text").val(); // grab review text 403 let media_compliance = $("#rx_allow_media_compliance"); 404 405 if( review_title == "" ){ 406 $("#rx-review-title-error").html(rx_ajax_data.rx_review_title_error); 407 } else if( review_text == "" ){ 408 $("#rx_text").focus(); 409 $("#rx-review-text-error").html(rx_ajax_data.rx_review_text_error); 410 } else if( media_compliance.length != 0 && media_compliance.prop('checked') == false ){ 411 $("#rx-media-compliance-error").html(rx_ajax_data.please_accept_agreement); 412 } else { 413 414 $("#rx-submit").attr("disabled", true); 415 $("#rx-cancel").attr("disabled", true); 416 $(".rx-lds-css").show(); 417 418 let data = formInput.serializeArray(); 419 data.push({ 420 name: 'rx-video-source-control', 421 value: $('#rx-video-source-control').val() 422 }); 423 424 $.ajax({ 425 url: rx_ajax_data.ajax_url, 426 type: 'post', 427 data: { 428 action: 'review_submit_from_myorder', 429 forminput: data, 430 rx_review_text: $("#rx_text").val(), 431 security: $("#rx-nonce").val() 432 }, 433 success: function (data) { 434 $(".rx-lds-css").hide(); 435 $("#rx-submit").attr("disabled", false); 436 $(".rx-cancel").attr("disabled", false); 437 438 if( data.success == true ) { 439 $("#rx-submit").parent().siblings().closest('.rx-form-submit-status').fadeIn().addClass('success').text(rx_ajax_data.review_success_msg); 440 if( data.status == 0 ){ 441 $("#rx-submit").parent().siblings().closest('.rx-form-submit-notice').fadeIn().addClass('rx-notice').html(rx_ajax_data.review_status_msg); 442 } 443 setTimeout(function() { 444 window.location.reload(); 445 }, 1800); 446 } else if( data.success == false ) { 447 $("#rx-submit").parent().siblings().closest('.rx-form-submit-status').fadeIn().addClass('error').text(rx_ajax_data.review_failed_msg); 448 } else { 449 $("#rx-submit").parent().siblings().closest('.rx-form-submit-status').fadeIn().addClass('error').html(data).text(); 450 } 451 }, 452 error:function(err) { 453 $(".rx-lds-css").hide(); 454 $("#rx-submit").attr("disabled", false); 455 $(".rx-cancel").attr("disabled", false); 456 } 457 }); 458 } 459 460 }); 461 462 /*======================================== 463 * Function for default review open image 464 *========================================*/ 465 function rx_image_popup(){ 466 //if( rx_ajax_data.theme_name != 'porto' ){ 467 $('.popup-link').magnificPopup({ 468 delegate: 'a', 469 type: 'image', 470 tLoading: 'Loading image #%curr%...', 471 mainClass: 'mfp-img-mobile', 472 gallery: { 473 enabled: true, 474 navigateByImgClick: true, 475 preload: [0,1] 476 }, 477 image: { 478 tError: '<a href="%url%">The image #%curr%</a> could not be loaded.', 479 } 480 }); 481 //} 482 } 483
484 $(document).ready( function() { 485 if($(".rx_review_sort_list").hasClass("popup-link")){ 486 $('.popup-link').magnificPopup({ 487 delegate: 'a', 488 type: 'image', 489 tLoading: 'Loading image #%curr%...', 490 mainClass: 'mfp-img-mobile', 491 gallery: { 492 enabled: true, 493 navigateByImgClick: true, 494 preload: [0,1] 495 }, 496 image: { 497 tError: '<a href="%url%">The image #%curr%</a> could not be loaded.', 498 } 499 }); 500 } 501 }); 502 /*======================================== 503 * Horizontal bar 504 *========================================*/ 505 $('.rx-horizontal .progress-fill span').each(function(){ 506 var percent = $(this).html(); 507 $(this).parent().css('width', percent); 508 }); 509 510 /*======================================== 511 * Review ordering filter 512 *========================================*/ 513 $(document).ready( function() { 514 $(document).on('change', "select.rx_shorting", function () { 515 $('.rx_double_spinner').show(); 516 $.ajax({ 517 url: rx_ajax_data.ajax_url, 518 type: 'post', 519 data: { 520 action: 'rx_sorting', 521 selected: $(this).children("option:selected").val(), 522 rx_product_id: $('.rx_product_id').val(), 523 security: $(".rx-sort-nonce").val(), 524 rx_post_type: $('#rx-sorting-post-type').val(), 525 rx_pagination: $('#rx-allow-shortcode-pagination').val(), 526 page: 1, 527 per_page: $('#rx-pagination-limit').val(), 528 rx_rating: $('#rx-product-rating').val(), 529 user_id: $('#rx-user-id').val(), 530 rx_post_title: $("#rx-product-title").val(), 531 }, 532 success: function (data) { 533 534 $('.rx_listing .rx_double_spinner').hide(); 535 $('.rx_review_sort_list').html( data ); 536 rx_image_popup(); //Popup image 537 }, 538 error:function (err) { 539 $('.rx_listing .rx_double_spinner').hide(); 540 console.log( err + 'Error....'); 541 } 542 }); 543 }); 544 545 $(document).on('click', ".rx-tooltip", function () { 546 $('.rx_double_spinner').show(); 547 let rating = $(this).data('rating'); 548 $('#rx-product-rating').val(rating); 549 $.ajax({ 550 url: rx_ajax_data.ajax_url, 551 type: 'post', 552 data: { 553 action: 'rx_sorting', 554 selected: 'tooltip_filter', 555 rx_product_id: $('.rx_product_id').val(), 556 security: $(".rx-sort-nonce").val(), 557 rx_post_type: $('#rx-sorting-post-type').val(), 558 rx_pagination: $('#rx-allow-shortcode-pagination').val(), 559 page: 1, 560 per_page: $('#rx-pagination-limit').val(), 561 rx_rating: rating, 562 user_id: $('#rx-user-id').val(), 563 rx_post_title: $("#rx-product-title").val(), 564 }, 565 success: function (data) { 566 $('.rx_listing .rx_double_spinner').hide(); 567 $('.rx_review_sort_list').html( data ); 568 rx_image_popup(); //Popup image 569 }, 570 error:function (err) { 571 $('.rx_listing .rx_double_spinner').hide(); 572 console.log( err + 'Error....'); 573 } 574 }); 575 }); 576 }); 577 578 /*======================================== 579 * Progress bar 580 *========================================*/ 581 $('.rx_style_one_progress-value > span').each(function(){ 582 $(this).prop('Counter',0).animate({ 583 Counter: $(this).text() 584 },{ 585 duration: 1500, 586 easing: 'swing', 587 step: function (now){ 588 $(this).text(Math.ceil(now)); 589 } 590 }); 591 }); 592 593 $(document).ready(function() { 594 595 /*======================================== 596 * Call image uploader 597 *========================================*/ 598 $('.rx-popup-video').magnificPopup({ 599 // disableOn: 700, 600 type: 'iframe', 601 mainClass: 'mfp-fade', 602 removalDelay: 160, 603 preloader: false, 604 fixedContentPos: false, 605 iframe: { 606 patterns: { 607 youtube_short: { 608 index: 'youtu.be/', 609 id: 'youtu.be/', 610 src: '//www.youtube.com/embed/%id%?autoplay=1' 611 } 612 } 613 } 614 }); 615 616 617 //Front-end review image upload 618 let file_frame; // variable for the wp.media file_frame 619 let attachment; 620 $(document).on('click', '#attachment', function(event) { 621 event.preventDefault(); 622 if ( file_frame ) { 623 file_frame.open(); 624 return; 625 } 626 627 file_frame = wp.media.frames.file_frame = wp.media({ 628 title: $( this ).data( 'uploader_title' ), 629 button: { 630 text: $( this ).data( 'uploader_button_text' ), 631 }, 632 multiple: $(this).data('multiple') // set this to true for multiple file selection 633 }); 634 635 file_frame.on( 'select', function() { 636 attachment = file_frame.state().get('selection').toJSON(); 637 let wrapper = $('#rx-images'); //Input image wrapper 638 $('#rx-images').removeClass('rx-hide'); 639 $.each(attachment, function(index, value) { 640 641 if( $('#attachment').data('multiple') == true ) { 642 $(wrapper).prepend('<div class="rx-image"><img src="'+value.url+'" alt=""><a href="javascript:void(0);" class="remove_image" title="Remove Image"><svg style="width: 15px" aria-hidden="true" focusable="false" data-prefix="fas" data-icon="times-circle" class="svg-inline--fa fa-times-circle fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
642<path fill="currentColor" d="M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm121.6 313.1c4.7 4.7 4.7 12.3 0 17L338 377.6c-4.7 4.7-12.3 4.7-17 0L256 312l-65.1 65.6c-4.7 4.7-12.3 4.7-17 0L134.4 338c-4.7-4.7-4.7-12.3 0-17l65.6-65-65.6-65.1c-4.7-4.7-4.7-12.3 0-17l39.6-39.6c4.7-4.7 12.3-4.7 17 0l65 65.7 65.1-65.6c4.7-4.7 12.3-4.7 17 0l39.6 39.6c4.7 4.7 4.7 12.3 0 17L312 256l65.6 65.1z"></path></svg></a><input type="hidden" name="rx-image[]" value="'+value.id+'"></div>'); // display image 643 } else { 644 $(wrapper).html(""); 645 $(wrapper).prepend('<div class="rx-image"><img src="'+value.url+'" alt=""><a href="javascript:void(0);" class="remove_image" title="Remove Image"><svg style="width: 15px" aria-hidden="true" focusable="false" data-prefix="fas" data-icon="times-circle" class="svg-inline--fa fa-times-circle fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm121.6 313.1c4.7 4.7 4.7 12.3 0 17L338 377.6c-4.7 4.7-12.3 4.7-17 0L256 312l-65.1 65.6c-4.7 4.7-12.3 4.7-17 0L134.4 338c-4.7-4.7-4.7-12.3 0-17l65.6-65-65.6-65.1c-4.7-4.7-4.7-12.3 0-17l39.6-39.6c4.7-4.7 12.3-4.7 17 0l65 65.7 65.1-65.6c4.7-4.7 12.3-4.7 17 0l39.6 39.6c4.7 4.7 4.7 12.3 0 17L312 256l65.6 65.1z"></path></svg></a><input type="hidden" name="rx-image[]" value="'+value.id+'"></div>'); // display image 646 } 647 }); 648 }); 649 650 file_frame.open(); 651 }); 652 653 /********************************* 654 * Review form validation 655 ********************************/ 656 $('#comment').attr('name', 'comment'); 657 $("#attachmentForm").validate({ 658 rules: { 659 author: "required", 660 email: { 661 required: true, 662 email: true, 663 regex: /^\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b$/i 664 }, 665 reviewx_title: "required", 666 comment: "required", 667 rx_allow_media_compliance: "required", 668 }, 669 messages: { 670 author: rx_ajax_data.please_enter_name, 671 email: rx_ajax_data.please_enter_email, 672 reviewx_title: rx_ajax_data.please_enter_title, 673 comment: rx_ajax_data.please_reave_message, 674 rx_allow_media_compliance: rx_ajax_data.please_accept_agreement 675 }, 676 submitHandler: function(form) {} 677 }); 678 679 $.validator.addMethod( 680 /* The value you can use inside the email object in the validator. */ 681 "regex", 682 683 /* The function that tests a given string against a given regEx. */ 684 function(value, element, regexp) { 685 /* Check if the value is truthy (avoid null.constructor) & if it's not a RegEx. (Edited: regex --> regexp)*/ 686 687 if (regexp && regexp.constructor != RegExp) { 688 /* Create a new regular expression using the regex argument. */ 689 regexp = new RegExp(regexp); 690 } 691 692 /* Check whether the argument is global and, if so set its last index to 0. */ 693 else if (regexp.global) regexp.lastIndex = 0; 694 695 /* Return whether the element is optional or the result of the validation. */ 696 return this.optional(element) || regexp.test(value); 697 } 698 ); 699 700 /********************************* 701 * Review form AJAX submission 702 *********************************/ 703 $(document).on('click', "#attachmentForm input[type=submit], #attachmentForm #submit", function (event) { 704 event.preventDefault(); 705 706 let reCaptcha = null; 707 708 if (parseInt($("#enable_recaptcha").val())) { 709 reCaptcha = window.grecaptcha.getResponse(); 710 if (reCaptcha.length === 0) { 711 $('.rx-form-submit-status.error').remove(); 712 $("#submit").parent().before("<div class='rx-form-submit-status error' style='display:block;'>re-Captcha required!</div>"); 713 return; 714 } 715 } 716 717 if ($('#attachmentForm').valid()) { 718 $(this).prop('disabled', true); 719 //AJAX form submit 720 let formInput = $("#attachmentForm input"); // grab all input field 721 let data = formInput.serializeArray(); 722 723 if (reCaptcha) { 724 data.push({ 725 name: 'recaptcha-token', 726 value: reCaptcha 727 }) 728 } 729 730 data.push({ 731 name: 'rx-video-source-control', 732 value: $('#rx-video-source-control').val() 733 }); 734 735 $.ajax({ 736 url: rx_ajax_data.ajax_url, 737 type: 'post', 738 data: { 739 action: 'rx_front_end_review_submit', 740 formInput: data, 741 rx_review_text: $("#comment").val(), 742 security: rx_ajax_data.ajax_nonce 743 }, 744 success: function (data) { 745 if(data.success == true) { 746 $("#attachmentForm input[type=submit]").parent().before("<div class='rx-form-submit-status success' style='display:block;'>"+rx_ajax_data.review_success_msg+"</div>"); 747 if( data.status == 0 ) { 748 $("#attachmentForm input[type=submit]").parent().before("<div class='rx-form-submit-status rx-notice' style='display:block;'>"+rx_ajax_data.review_status_msg+"</div>"); 749 } 750 $("#review_title").val(''); 751 $("#comment").val(''); 752 $("#author").val(''); 753 $("#email").val(''); 754 755 setTimeout(function(){ 756 window.location.reload(); 757 }, 2000); 758 } else if(data.success == false) { 759 $("#attachmentForm input[type=submit]").parent().before("<div class='rx-form-submit-status error' style='display:block;'>"+rx_ajax_data.review_failed_msg+"</div>"); 760 } else { 761 $("#attachmentForm input[type=submit]").parent().before("<div class='rx-form-submit-status error' style='display:block;'>"+data+"</div>"); 762 } 763 $("#attachmentForm input[type=submit]").prop('disabled', false); 764 765 }, 766 error:function(err) { 767 $("#attachmentForm input[type=submit]").parent().before("<div class='rx-form-submit-status error' style='display:block;'>Sorry something went wrong.</div>"); 768 } 769 }); 770 } 771 772 }); 773 }); 774 775 //OceanWP theme - lightbox 776 window.addEventListener('load', (event) => { 777 if($('.rx-popup-video').hasClass('oceanwp-lightbox')){ 778 $('.rx-popup-video').removeClass('oceanwp-lightbox'); 779 $('.rx-popup-video').magnificPopup({ 780 disableOn: 700, 781 type: 'iframe', 782 mainClass: 'mfp-fade', 783 removalDelay: 160, 784 preloader: false,
785 fixedContentPos: false, 786 iframe: { 787 patterns: { 788 youtube_short: { 789 index: 'youtu.be/', 790 id: 'youtu.be/', 791 src: '//www.youtube.com/embed/%id%?autoplay=1' 792 } 793 } 794 } 795 }); 796 } 797 798 if(!$('.popup-link a').hasClass('oceanwp-lightbox')){ 799 rx_image_popup(); 800 } 801 }); 802 803 /*======================================== 804 * Call for non logged in user 805 *========================================*/ 806 $(document).on('change', '#non-logged-attachment', function(){ 807 808 let wrapper = $('#rx-images'); //Input image wrapper 809 let rx_img = new FormData(); 810 var files_data = $(this); 811 $.each($(files_data), function(i, obj) { 812 $.each(obj.files,function(j,file){ 813 rx_img.append('files[' + j + ']', file); 814 }) 815 }); 816 rx_img.append('action', 'rx_guest_review_image_upload'); 817 rx_img.append('security', rx_ajax_data.ajax_nonce); 818 819 $('.rx_image_upload_spinner').show(); 820 $.ajax({ 821 url: rx_ajax_data.ajax_url, 822 contentType: false, 823 processData: false, 824 type: 'post', 825 data: rx_img, 826 success: function (data) { 827 $(wrapper).prepend(data.image); 828 if( data.message != null ) { 829 $('.rx-guest-attachment-error').text(data.message); 830 } 831 $('.rx_image_upload_spinner').hide(); 832 }, 833 error:function(error){ 834 $('.rx_image_upload_spinner').hide(); 835 } 836 }); 837 }); 838 839 let wrapper = $('#rx-images'); //Input image wrapper 840 $(wrapper).on('click', '.remove_guest_image', function(e){ //Once remove button is clicked 841 e.preventDefault(); 842 let $that = $(this); 843 let attach_id = $(this).siblings(".rx-image").val(); 844 jQuery.ajax({ 845 url: rx_ajax_data.ajax_url, 846 type: 'post', 847 data : { 848 action: 'rx_remove_guest_image', 849 attach_id: attach_id, 850 security: rx_ajax_data.ajax_nonce 851 }, 852 success: function( data ) { 853 $($that).parent().remove(); //Remove image 854 }, 855 error: function(err){ 856 console.log(err); 857 } 858 }); 859 }); 860 861 $(document).on('click', '.rx-media-upload-button', function(){ 862 var button = $( this ), 863 wrapper = button.parents('.rx-media-field-wrapper'), 864 removeButton = wrapper.find('.rx-media-remove-button'), 865 imgContainer = wrapper.find('.rx-thumb-container'), 866 idField = wrapper.find('.rx-media-id'), 867 urlField = wrapper.find('.rx-media-url'); 868 // Create a new media frame 869 var frame = wp.media({ 870 title: 'Upload Photo', 871 button: { 872 text: 'Use this photo' 873 }, 874 multiple: false // Set to true to allow multiple files to be selected 875 }); 876 877 // When an image is selected in the media frame... 878 frame.on( 'select', function() { 879 // Get media attachment details from the frame state 880 var attachment = frame.state().get('selection').first().toJSON(); 881 882 /** 883 * Set image to the image container 884 */ 885 imgContainer.addClass('rx-has-thumb').append( '<img src="'+attachment.url+'" alt="" style="max-width:100%;"/>' ); 886 idField.val( attachment.id ); // set image id 887 urlField.val( attachment.url ); // set image url 888 889 // Hide the upload button 890 button.addClass( 'rx-media-uploader-hidden' ); 891 892 // Show the remove button 893 removeButton.removeClass( 'rx-media-uploader-hidden' ); 894 }); 895 896 // Finally, open the modal on click 897 frame.open(); 898 }); 899 900 $(document).on( 'click', '.rx-media-remove-button', function(){ 901 var button = $( this ), 902 wrapper = button.parents('.rx-media-field-wrapper'), 903 uploadButton = wrapper.find('.rx-media-upload-button'), 904 imgContainer = wrapper.find('.rx-has-thumb'), 905 idField = wrapper.find('.rx-media-id'), 906 urlField = wrapper.find('.rx-media-url'); 907 908 imgContainer.removeClass('rx-has-thumb').find('img').remove(); 909 910 urlField.val(''); // URL field has to be empty 911 idField.val(''); // ID field has to empty as well 912 913 button.addClass('rx-media-uploader-hidden'); // Hide the remove button first 914 uploadButton.removeClass('rx-media-uploader-hidden'); // Show the uplaod button 915 }); 916})(jQuery, window, document);
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.