PageSourceSearch

https://www.metacenterchicago.com/wp-content/plugins/yith-woocomme…/assets/js/frontend.js?ver=1790590097

js metacenterchicago.com collected 2026-09-28 10:11:35 UTC 55,986 bytes, 1,799 lines download raw bytes

1/**
2 * Frontend review scripts
3 *
4 * @var jQuery
5 * @var ywar_frontend
6 * @package YITH\AdvancedReviews\Assets\JS
7 */
8
9(
10	function ( $, ywar ) {
11
12		const image_mime_types = [
13			'image/jpeg',
14			'image/gif',
15			'image/png',
16			'image/webp',
17		];
18
19		const video_mime_types = [
20			'video/mp4',
21			'video/ogg',
22			'video/webm',
23			'video/x-m4v',
24			'video/x-flv',
25		];
26
27		var ywar_init                        = false,
28			sb_instance,
29			file_uploads                     = {form: '', files: [], type_count: {image: 0, video: 0}},
30			load_reviews                     = function ( self, callback = null ) {
31				var review_id = 0;
32				if ( window.location.hash.indexOf( '#review-' ) !== -1 ) {
33					$( 'body' )
34						.find( 'li.reviews_tab a' )
35						.trigger( 'click' );
36
37					review_id = window.location.hash.replace( '#review-', '' );
38				}
39				ywar
40					.ajax(
41						{
42							review_id:  review_id,
43							product_id: self.element.data( 'product-id' ),
44							box_id:     self.element.data( 'review-box' ),
45							request:    'load_reviews',
46							page:       self.args.page,
47							rating:     self.args.rating,
48							sorting:    self.args.sorting,
49							helpful:    self.args.helpful,
50							popup:      self.popup ? 'yes' : 'no'
51						},
52						{block: self.element}
53					)
54					.done(
55						function ( response ) {
56							if ( callback ) {
57								callback( response, self );
58							}
59						}
60					);
61			},
62			validate_form_fields             = function ( self, fields, action ) {
63				var form_has_error = false;
64				$( '*' ).removeClass( 'has-error' );
65				if ( typeof fields.rating_field !== "undefined" ) {
66					if ( fields.rating_field.length > 1 ) {
67						fields.rating_field.each(
68							function () {
69								// Check if rating is zero.
70								if ( 0 === parseInt( $( this ).val() ) ) {
71									$( this ).parent().parent().addClass( 'has-error' ).attr( 'data-message', ywar_frontend.messages['required_rating'] );
72									$( this ).parent().prev().addClass( 'has-error' );
73									$( 'html, body' )
74										.animate(
75											{
76												scrollTop: $( this ).parent().parent().offset().top - ywar_frontend.scroll_offset
77											},
78											200
79										);
80
81									form_has_error = true;
82								}
83							}
84						);
85					} else {
86						// Check if rating is zero.
87						if ( 0 === parseInt( fields.rating_field.val() ) ) {
88							form_validation_error( fields.rating_field, 'required_rating', form_has_error );
89							form_has_error = true;
90						}
91					}
92				}
93
94				if ( 0 === fields.user_id && 'insert' === action ) {
95					// Check if username is empty.
96					if ( '' === fields.user_name.val() ) {
97						form_validation_error( fields.user_name, 'required_field', form_has_error );
98						form_has_error = true;
99					}
100
101					// Check if email is empty.
102					if ( '' === fields.user_email.val() ) {
103						form_validation_error( fields.user_email, 'required_field', form_has_error );
104						form_has_error = true;
105					}
106
107					/* https://stackoverflow.com/questions/2855865/jquery-validate-e-mail-address-regex */
108					var pattern = new RegExp( /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i );
109
110					if ( ! pattern.test( fields.user_email.val() ) ) {
111						form_validation_error( fields.user_email, 'mail_wrong', form_has_error );
112						form_has_error = true;
113					}
114				}
115
116				// Check if content is empty.
117				if ( '' === fields.content.val() ) {
118					form_validation_error( fields.content, 'required_field', form_has_error );
119					form_has_error = true;
120				}
121
122				if ( ywar_frontend.use_recaptcha && 'v2' === ywar_frontend.recaptcha_version && ('off' === fields.recaptcha_response || '' === fields.recaptcha_response) ) {
123					form_validation_error( fields.recaptcha_wrapper, 'required_captcha', form_has_error );
124					form_has_error = true;
125				}
126
127				return form_has_error;
128
129			},
130			form_validation_error            = function ( element, message, form_has_error ) {
131				element.parent().addClass( 'has-error' ).attr( 'data-message', ywar_frontend.messages[message] );
132
133				if ( 'required_rating' === message ) {
134					element.parent().prev().addClass( 'has-error' );
135				}
136
137				if ( ! form_has_error ) {
138					$( 'html, body' )
139						.animate(
140							{
141								scrollTop: element.parent().offset().top - ywar_frontend.scroll_offset
142							},
143							200
144						);
145				}
146			},
147			like_review                      = function ( button ) {
148				var review_wrapper = $( '.review-' + button.data( 'review-id' ) );
149				// Manage review like.
150				ywar
151					.ajax(
152						{
153							review_id: button.data( 'review-id' ),
154							request:   'like_review',
155							user_id:   button.data( 'user-id' ),
156						},
157						{block: button}
158					)
159					.done(
160						function ( response ) {
161							if ( response.data.selected ) {
162								review_wrapper.find( '.helpful-button' ).addClass( 'selected' );
163							} else {
164								review_wrapper.find( '.helpful-button' ).removeClass( 'selected' );
165							}
166							review_wrapper.find( '.helpful-count' ).html( response.data.message )
167						}
168					);
169			},
170			report_review                    = function ( button ) {
171				var review_wrapper = $( '.review-' + button.data( 'review-id' ) );
172
173				// Manage review report.
174				ywar
175					.ajax(
176						{
177							request:   'report_review',
178							review_id: button.data( 'review-id' ),
179							user_id:   button.data( 'user-id' ),
180						},
181						{block: button}
182					)
183					.done(
184						function ( response ) {
185							var wrapper = button.closest( '.review-actions' );
186							wrapper.find( '.reported-message' ).remove();
187							if ( response.data.selected ) {
188								review_wrapper.find( '.report-button' ).addClass( 'selected' );
189							} else {
190								review_wrapper.find( '.report-button' ).removeClass( 'selected' );
191							}
192							if ( response.data.message ) {
193								wrapper.append( '<span class="reported-message">' + response.data.message + '</span>' )
194							}
195						}
196					);
197			},
198			delete_review                    = function ( button ) {
199				var review_wrapper = $( '.yith-ywar-single-review.review-' + button.data( 'review-id' ) ),
200					context        = 'default';
201
202				switch ( true ) {
203					case review_wrapper.hasClass( 'in-shortcode' ):
204						context = 'shortcode';
205						break;
206					case review_wrapper.hasClass( 'in-popup' ):
207						context = 'popup';
208						break;
209				}
210
211				// Manage review delete.
212				ywar
213					.ajax(
214						{
215							review_id:      button.data( 'review-id' ),
216							request:        'delete_review',
217							button_context: context,
218						},
219						{block: button}
220					)
221					.done(
222						function ( response ) {
223							if ( response.data.message ) {
224								review_wrapper
225									.after( response.data.message )
226									.remove();
227							}
228						}
229					);
230			},
231			open_reply_review                = function ( self, button ) {
232				// Manage review reply.
233				var review_id   = button.data( 'review-id' ),
234					in_reply_of = button.data( 'reply-to' ),
235					container   = self.element.find( '#review-' + review_id );
236				ywar
237					.ajax(
238						{
239							review_id:   review_id,
240							in_reply_of: in_reply_of,
241							box_id:      self.element.data( 'review-box' ),
242							request:     'reply_review',
243						},
244						{block: container}
245					)
246					.done(
247						function ( response ) {
248							if ( response.data ) {
249								self.element.find( '.yith-ywar-edit-forms:not(.new-review)' ).remove();
250
251								if ( self.element.find( '.replies-review-' + review_id ).length === 0 ) {
252									container.after( '<div class="yith-ywar-replies-wrapper replies-review-' + review_id + '"></div>' )
253								}
254								self.element.find( '.replies-review-' + review_id ).append( response.data );
255
256								$( 'html, body' )
257									.animate(
258										{
259											scrollTop: self.element.find( '#yith-ywar-new-reply-' + review_id ).offset().top - ywar_frontend.scroll_offset
260										},
261										200
262									);
263								if ( ywar_frontend.use_recaptcha ) {
264									var recaptcha = $( '#yith-ywar-new-reply-' + review_id ).find( '.g-recaptcha' );
265									if ( typeof grecaptcha !== "undefined" && recaptcha.length > 0 ) {
266										ywar.captcha_edit = grecaptcha.render( 'yith-ywar-recaptcha-new-reply-' + review_id, {'sitekey': recaptcha.data( 'sitekey' )} );
267									}
268								}
269							}
270						}
271					);
272			},
273			open_edit_review                 = function ( self, review_id, type ) {
274				// Manage review editing.
275				var container = self.element.find( '#review-' + review_id );
276				ywar
277					.ajax(
278						{
279							review_id: review_id,
280							box_id:    self.element.data( 'review-box' ),
281							request:   'edit_review',
282						},
283						{block: container}
284					)
285					.done(
286						function ( response ) {
287							if ( response.data ) {
288								self.element.find( '.yith-ywar-edit-forms:not(.new-review)' ).remove();
289								container.append( response.data );
290								if ( ywar_frontend.use_recaptcha ) {
291									var recaptcha = $( '#yith-ywar-edit-' + type + '-' + review_id ).find( '.g-recaptcha' );
292									if ( typeof grecaptcha !== "undefined" && recaptcha.length > 0 ) {
293										ywar.captcha_edit = grecaptcha.render( 'yith-ywar-recaptcha-edit-' + type + '-' + review_id, {'sitekey': recaptcha.data( 'sitekey' )} );
294									}
295								}
296							}
297						}
298					);
299			},
300			init_swiper                      = function ( slide, type ) {
301				var loop           = true,
302					disabled_class = 'swiper-button-disabled',
303					lock_class     = 'swiper-button-lock';
304
305				var thumb_swiper = new ywar.Swiper(
306					'.thumbs-gallery-' + type,
307					{
308						spaceBetween:        10,
309						slidesPerView:       'auto',
310						freeMode:            true,
311						watchSlidesProgress: true,
312					}
313				);
314				var swiper       = new ywar.Swiper(
315					'.swiper-gallery-' + type,
316					{
317						on:           {
318							init:              function ( swiper ) {
319								var current_slide    = $( swiper.slides[swiper.activeIndex] ),
320									review_id        = current_slide.data( 'review-id' ),
321									review_container = $( '#gallery-review-' + review_id );
322
323								if ( slide === swiper.activeIndex && current_slide.find( '.wp-video-shortcode' ).length > 0 ) {
324									current_slide.find( '.wp-video-shortcode' ).get( 0 ).play();
325								}
326
327								$( '.review-data' ).addClass( 'inactive-review' );
328								review_container.removeClass( 'inactive-review' );
329							},
330							activeIndexChange: function ( swiper ) {
331								var current_slide    = $( swiper.slides[swiper.activeIndex] ),
332									review_id        = current_slide.data( 'review-id' ),
333									review_container = $( '#gallery-review-' + review_id );
334
335								if ( current_slide.find( '.wp-video-shortcode' ).length > 0 ) {
336									current_slide.find( '.wp-video-shortcode' ).get( 0 ).play();
337								} else {
338									$( '.wp-video-shortcode' ).each(
339										function () {
340											var video = $( this ).get( 0 );
341											video.pause();
342											video.currentTime = 0;
343										}
344									);
345								}
346
347								$( '.review-data' ).addClass( 'inactive-review' );
348								review_container.removeClass( 'inactive-review' );
349							}
350						},
351						spaceBetween: 0,
352						autoHeight:   false,
353						loop:         loop,
354						navigation:   {
355							nextEl:        '.swiper-button-next',
356							prevEl:        '.swiper-button-prev',
357							disabledClass: disabled_class,
358							lockClass:     lock_class,
359						},
360						thumbs:       {
361							swiper: thumb_swiper,
362						}
363					}
364				);
365
366				swiper.slideTo( slide )
367
368			},
369			init_buttons                     = function ( self ) {
370				var wrapper_id = `#${self.element.attr( 'id' )}`;
371				$( document )
372					.on(
373						'click',
374						wrapper_id + ' .action-buttons',
375						function () {
376							var button = $( this );
377							switch ( button.data( 'action' ) ) {
378								case 'like':
379									like_review( button );
380									break;
381								case 'report':
382									report_review( button );
383									break;
384								case 'delete':
385									delete_review( button );
386									break;
387								default:
388									open_reply_review( self, button );
389							}
390						}
391					)
392					.on(
393						'click',
394						wrapper_id + ' .edit-button',
395						function () {
396							open_edit_review( self, $( this ).data( 'review-id' ), $( this ).data( 'type' ) );
397						}
398					)
399					.on(
400						'click',
401						wrapper_id + ' .form-review-rating .stars span',
402						function () {
403							var star      = $( this ),
404								rating    = $( this ).closest( '.rating-wrapper' ).find( '.rating-value' ),
405								container = $( this ).closest( '.stars' );
406
407							rating.val( star.data( 'value' ) );
408							star.siblings( 'span' ).removeClass( 'active' );
409							star.addClass( 'active' );
410							container.addClass( 'selected' );
411						}
412					)
413					.on(
414						'click',
415						wrapper_id + ' .submit-button',
416						function () {
417
418							var element     = self,
419								review_id   = $( this ).data( 'review-id' ),
420								in_reply_of = $( this ).data( 'reply-to' );
421
422							switch ( $( this ).data( 'type' ) ) {
423								case 'edit-reply' :
424									if ( ywar_frontend.use_recaptcha && 'v3' === ywar_frontend.recaptcha_version ) {
425										grecaptcha.ready(
426											function () {
427												grecaptcha
428													.execute(
429														ywar_frontend.recaptcha_sitekey,
430														{action: 'submit'}
431													)
432													.then(
433														function ( token ) {
434															submit_edit_reply( element, review_id, token );
435														}
436													);
437											}
438										);
439									} else {
440										submit_edit_reply( element, review_id, 'off' );
441									}
442									break;
443								case 'edit-review':
444									if ( ywar_frontend.use_recaptcha && 'v3' === ywar_frontend.recaptcha_version ) {
445										grecaptcha.ready(
446											function () {
447												grecaptcha
448													.execute(
449														ywar_frontend.recaptcha_sitekey,
450														{action: 'submit'}
451													)
452													.then(
453														function ( token ) {
454															submit_edit_review( element, review_id, token );
455														}
456													);
457											}
458										);
459									} else {
460										submit_edit_review( element, review_id, 'off' );
461									}
462									break;
463								case 'create-reply':
464									if ( ywar_frontend.use_recaptcha && 'v3' === ywar_frontend.recaptcha_version ) {
465										grecaptcha.ready(
466											function () {
467												grecaptcha
468													.execute(
469														ywar_frontend.recaptcha_sitekey,
470														{action: 'submit'}
471													)
472													.then(
473														function ( token ) {
474															submit_new_reply( element, review_id, in_reply_of, token );
475														}
476													);
477											}
478										);
479									} else {
480										submit_new_reply( element, review_id, in_reply_of, 'off' );
481									}
482									break;
483								default:
484									if ( ywar_frontend.use_recaptcha && 'v3' === ywar_frontend.recaptcha_version ) {
485										grecaptcha.ready(
486											function () {
487												grecaptcha
488													.execute(
489														ywar_frontend.recaptcha_sitekey,
490														{action: 'submit'}
491													)
492													.then(
493														function ( token ) {
494															submit_new_review( element, token );
495														}
496													);
497											}
498										);
499									} else {
500										submit_new_review( element, 'off' );
501									}
502							}
503						}
504					)
505					.on(
506						'dragover',
507						wrapper_id + ' .yith-ywar-attachments',
508						function () {
509							$( this )
510								.closest( '.yith-ywar-attachments' )
511								.addClass( 'yith-ywar-is-dragging' );
512						}
513					)
514					.on(
515						'dragleave',
516						wrapper_id + ' .yith-ywar-attachments',
517						function () {
518							$( this )
519								.closest( '.yith-ywar-attachments' )
520								.removeClass( 'yith-ywar-is-dragging' );
521						}
522					)
523					.on(
524						'change',
525						wrapper_id + ' .yith-ywar-attachments .attachment-field',
526						function () {
527							var wrapper = $( this ).closest( '.yith-ywar-attachments' ),
528								list    = wrapper.find( '.attachments-list' ),
529								files   = this.files.length ? this.files : false,
530								form_id = $( this ).closest( '.yith-ywar-edit-forms' ).attr( 'id' );
531
532							wrapper.removeClass( 'yith-ywar-is-dragging' );
533							wrapper.find( '.messages' ).html( '' );
534							if ( files ) {
535								var files_count     = files.length,
536									exceeding_files = {'image': [], 'video': []},
537									exceeding_size  = {'image': [], 'video': []},
538									messages        = [];
539
540								if ( file_uploads.form !== form_id ) {
541									// Reset the upload data if the active form is changed.
542									reset_file_upload();
543								}
544
545								file_uploads.type_count.image = list.find( '.attachment-image' ).length;
546								file_uploads.type_count.video = list.find( '.attachment-video' ).length;
547								file_uploads.form             = form_id;
548
549								for ( let index = 0; index < files_count; index++ ) {
550									let file_type   = check_file_type( files[index].type ),
551										can_upload  = true,
552										count_check = file_uploads.type_count[file_type] < ywar_frontend.file_upload.allowed_quantity[file_type],
553										size_check  = files[index].size < ((ywar_frontend.file_upload.allowed_size[file_type] * 1024) * 1024);
554
555									if ( ! count_check ) {
556										can_upload = false;
557										exceeding_files[file_type].push( files[index].name );
558									} else if ( ! size_check ) {
559										can_upload = false;
560										exceeding_size[file_type].push( files[index].name );
561									}
562
563									if ( can_upload ) {
564										let reader    = new FileReader(),
565											new_index = file_uploads.files.push( files[index] ) - 1;
566
567										file_uploads.type_count[file_type] += 1;
568
569										reader.onload = function ( e ) {
570											let att_wrapper = $( '<div class="attachment temp-attachment attachment-' + file_type + '" data-item-id="' + new_index + '"></div>' ),
571												image       = file_type === 'video' ? ywar_frontend.file_upload.video_placeholder : e.target.result,
572												att_image   = $( '<img width="80" height="80" src="' + image 
572+ '" class="attachment-80x80 size-80x80" decoding="async" loading="lazy" />' );
573
574											att_wrapper.append( att_image );
575											list.append( att_wrapper )
576										};
577
578										reader.readAsDataURL( file_uploads.files[new_index] );
579										list.removeClass( 'empty' );
580									}
581								}
582
583								if ( exceeding_files.image.length > 0 ) {
584									messages.push( ywar_frontend.messages.too_many_images + exceeding_files.image.join( ', ' ) )
585								}
586								if ( exceeding_files.video.length > 0 ) {
587									messages.push( ywar_frontend.messages.too_many_videos + exceeding_files.video.join( ', ' ) );
588								}
589								if ( exceeding_size.image.length > 0 ) {
590									messages.push( ywar_frontend.messages.image_too_big + exceeding_size.image.join( ', ' ) );
591								}
592								if ( exceeding_size.video.length > 0 ) {
593									messages.push( ywar_frontend.messages.video_too_big + exceeding_size.video.join( ', ' ) );
594								}
595								if ( messages.length > 0 ) {
596									wrapper.find( '.messages' ).html( messages.join( '<br />' ) );
597								}
598							}
599						}
600					)
601					.on(
602						'click',
603						wrapper_id + ' .yith-ywar-attachments .attachment',
604						function () {
605							var item_id = $( this ).data( 'item-id' ),
606								wrapper = $( this ).closest( '.yith-ywar-attachments' );
607
608							if ( $( this ).hasClass( 'temp-attachment' ) ) {
609								file_uploads.files.splice( item_id, 1 );
610								$( this ).remove();
611							} else {
612								var attachments  = wrapper.find( 'input[name="yith-ywar-attachments"]' ),
613									values       = attachments.val().split( ',' ),
614									new_elements = [];
615
616								if ( item_id && $.inArray( item_id, values ) ) {
617									$( this ).remove();
618									new_elements = values.filter(
619										function ( val ) {
620											return parseInt( val ) !== parseInt( item_id );
621										}
622									);
623								}
624								attachments.val( new_elements.join( ',' ) );
625							}
626
627							if ( wrapper.find( '.attachments-list' ).children().length === 0 ) {
628								wrapper.find( '.attachments-list' ).addClass( 'empty' );
629							}
630						}
631					)
632					.on(
633						'click',
634						wrapper_id + ' .undo-delete-review',
635						function () {
636							var wrapper   = $( this ).parent().parent(),
637								review_id = wrapper.data( 'review-id' ),
638								context   = wrapper.data( 'context' );
639							// Manage review restore.
640							ywar
641								.ajax(
642									{
643										review_id:      review_id,
644										button_context: context,
645										request:        'restore_review',
646									},
647									{block: wrapper}
648								)
649								.done(
650									function ( response ) {
651										if ( response.data.message ) {
652											$( '.yith-ywar-review-form-message.review-' + review_id )
653												.after( response.data.message )
654												.remove();
655
656											if ( 'popup' === context ) {
657												$( '.yith-ywar-reviews-list .review-' + review_id ).removeClass( 'in-popup' );
658											}
659										}
660									}
661								);
662						}
663					);
664			},
665			submit_new_review                = function ( self, recaptcha_response ) {
666				var form_wrapper = self.element.find( '.yith-ywar-edit-forms.new-review' ),
667					form_has_error;
668
669				var fields = {
670					rating_field:       form_wrapper.find( 'input[name^="yith-ywar-rating"]' ),
671					multi_rating:       {},
672					rating:             0,
673					user_name:          form_wrapper.find( 'input[name="yith-ywar-user-name"]' ),
674					user_email:         form_wrapper.find( 'input[name="yith-ywar-user-email"]' ),
675					title:              form_wrapper.find( 'input[name="yith-ywar-title"]' ),
676					content:            form_wrapper.find( 'textarea[name="yith-ywar-content"]' ),
677					recaptcha_wrapper:  form_wrapper.find( '.g-recaptcha' ),
678					recaptcha_response: recaptcha_response,
679					user_id:            parseInt( ywar_frontend.user_id ),
680				};
681
682				if ( ywar_frontend.use_recaptcha && 'v2' === ywar_frontend.recaptcha_version ) {
683					fields.recaptcha_response = grecaptcha.getResponse();
684				}
685
686				if ( fields.rating_field.length > 1 ) {
687					fields.rating_field.each(
688						function () {
689							fields.multi_rating[$( this ).data( 'index' )] = parseInt( $( this ).val() );
690						}
691					);
692					fields.rating = 0;
693				} else {
694					fields.rating = fields.rating_field.val();
695				}
696
697				form_has_error = validate_form_fields( self, fields, 'insert' );
698
699				if ( ! form_has_error ) {
700
701					var formdata = new FormData();
702
703					formdata.append( 'request', 'submit_new_review' );
704					formdata.append( 'rating', fields.rating );
705					formdata.append( 'multi_rating', Object.keys( fields.multi_rating ).length === 0 ? '' : JSON.stringify( fields.multi_rating ) );
706					formdata.append( 'user_name', typeof fields.user_name.val() === 'undefined' ? '' : fields.user_name.val() );
707					formdata.append( 'user_email', typeof fields.user_email.val() === 'undefined' ? '' : fields.user_email.val() );
708					formdata.append( 'user_id', fields.user_id );
709					formdata.append( 'title', typeof fields.title.val() === 'undefined' ? '' : fields.title.val() );
710					formdata.append( 'content', fields.content.val() );
711					formdata.append( 'recaptcha_response', fields.recaptcha_response );
712					formdata.append( 'product_id', self.element.data( 'product-id' ) );
713
714					$.each(
715						file_uploads.files,
716						function ( j, file ) {
717							formdata.append( 'file-' + j, file );
718						}
719					);
720
721					// Manage review creation.
722					ywar
723						.ajax(
724							formdata,
725							{
726								block:       form_wrapper,
727								processData: false,
728								contentType: false
729							}
730						)
731						.done(
732							function ( response ) {
733								if ( response.success === true ) {
734									refresh_review_stats_attachments();
735									reset_file_upload();
736									if ( response.data.message ) {
737										form_wrapper.html( response.data.message );
738										$( 'html, body' )
739											.animate(
740												{
741													scrollTop: form_wrapper.offset().top - ywar_frontend.scroll_offset
742												},
743												200
744											);
745									} else {
746										window.location = '#review-' + response.data.review_id;
747										self.element.find( self.wrapper ).html( '' );
748										self.args = {
749											page:    1,
750											rating:  'all',
751											sorting: 'default',
752											helpful: 'no'
753										};
754										load_reviews( self, self.reviews_loaded );
755
756										if ( fields.rating_field.length > 1 ) {
757											fields.rating_field.each(
758												function () {
759													$( this ).val( '' );
760												}
761											);
762										} else {
763											fields.rating_field.val( '' );
764										}
765
766										form_wrapper.find( '.stars' ).removeClass( 'selected' );
767										form_wrapper.find( '.stars' ).find( 'span' ).removeClass( 'active' );
768										form_wrapper.find( '.temp-attachment' ).each(
769											function () {
770												$( this ).remove()
771											}
772										);
773										form_wrapper.find( '.attachments-list' ).addClass( 'empty' );
774
775										fields.user_name.val( '' );
776										fields.user_email.val( '' );
777										fields.content.val( '' );
778										fields.title.val( '' );
779
780										if ( ywar_frontend.use_recaptcha && 'v2' === ywar_frontend.recaptcha_version ) {
781											grecaptcha.reset();
782										}
783									}
784								} else {
785									validate_form_fields( self, fields, 'insert' )
786								}
787							}
788						);
789				}
790			},
791			submit_edit_review               = function ( self, review_id, recaptcha_response ) {
792				var form_wrapper = self.element.find( '#yith-ywar-edit-review-' + review_id ),
793					in_popup     = form_wrapper.closest( '.yith-ywar-single-review' ).hasClass( 'in-popup' ),
794					form_has_error;
795
796				var fields = {
797					rating_field:       form_wrapper.find( 'input[name^="yith-ywar-rating"]' ),
798					multi_rating:       {},
799					rating:             0,
800					title:              form_wrapper.find( 'input[name="yith-ywar-title"]' ),
801					content:            form_wrapper.find( 'textarea[name="yith-ywar-content"]' ),
802					attachments:        form_wrapper.find( 'input[name="yith-ywar-attachments"]' ),
803					recaptcha_wrapper:  form_wrapper.find( '.g-recaptcha' ),
804					recaptcha_response: recaptcha_response,
805					user_id:            parseInt( ywar_frontend.user_id ),
806				};
807
808				if ( ywar_frontend.use_recaptcha && 'v2' === ywar_frontend.recaptcha_version ) {
809					fields.recaptcha_response = grecaptcha.getResponse( ywar.captcha_edit );
810				}
811
812				if ( fields.rating_field.length > 1 ) {
813					fields.rating_field.each(
814						function () {
815							fields.multi_rating[$( this ).data( 'index' )] = parseInt( $( this ).val() );
816						}
817					);
818					fields.rating = 0;
819				} else {
820					fields.rating = fields.rating_field.val();
821				}
822
823				form_has_error = validate_form_fields( self, fields, 'edit' );
824
825				if ( ! form_has_error ) {
826
827					var formdata = new FormData();
828					formdata.append( 'request', 'submit_edit_review' );
829					formdata.append( 'rating', fields.rating );
830					formdata.append( 'multi_rating', Object.keys( fields.multi_rating ).length === 0 ? '' : JSON.stringify( fields.multi_rating ) );
831					formdata.append( 'title', typeof fields.title.val() === 'undefined' ? '' : fields.title.val() );
832					formdata.append( 'content', fields.content.val() );
833					formdata.append( 'attachments', (fields.attachments.length > 0 ? fields.attachments.val() : '') );
834					formdata.append( 'recaptcha_response', fields.recaptcha_response );
835					formdata.append( 'review_id', review_id );
836					formdata.append( 'box_id', self.element.data( 'review-box' ) );
837					formdata.append( 'popup', in_popup ? 'yes' : 'no' );
838
839					$.each(
840						file_uploads.files,
841						function ( j, file ) {
842							formdata.append( 'file-' + j, file );
843						}
844					);
845
846					// Manage review creation.
847					ywar
848						.ajax(
849							formdata,
850							{
851								block:       form_wrapper,
852								processData: false,
853								contentType: false
854							}
855						)
856						.done(
857							function ( response ) {
858								if ( response.success === true ) {
859									reset_file_upload();
860									var temp_content   = $( "<div></div>" ).html( response.data.html ),
861										updated_review = temp_content.find( response.data.review_id ).html();
862									self.element.find( response.data.review_id ).html( updated_review );
863									refresh_review_stats_attachments();
864									$( 'html, body' )
865										.animate(
866											{
867												scrollTop: self.element.find( response.data.review_id ).offset().top - ywar_frontend.scroll_offset
868											},
869											200
870										);
871								} else {
872									validate_form_fields( self, fields, 'edit' );
873								}
874							}
875						);
876				}
877			},
878			submit_edit_reply                = function ( self, review_id, recaptcha_response ) {
879				var form_wrapper = self.element.find( '#yith-ywar-edit-reply-' + review_id ),
880					in_popup     = form_wrapper.closest( '.yith-ywar-single-review' ).hasClass( 'in-popup' ),
881					form_has_error;
882
883				var fields = {
884					title:              form_wrapper.find( 'input[name="yith-ywar-title"]' ),
885					content:            form_wrapper.find( 'textarea[name="yith-ywar-content"]' ),
886					attachments:        form_wrapper.find( 'input[name="yith-ywar-attachments"]' ),
887					recaptcha_wrapper:  form_wrapper.find( '.g-recaptcha' ),
888					recaptcha_response: recaptcha_response,
889					user_id:            parseInt( ywar_frontend.user_id ),
890				};
891
892				if ( ywar_frontend.use_recaptcha && 'v2' === ywar_frontend.recaptcha_version ) {
893					fields.recaptcha_response = grecaptcha.getResponse( ywar.captcha_edit );
894				}
895
896				form_has_error = validate_form_fields( self, fields, 'edit' );
897
898				if ( ! form_has_error ) {
899
900					var formdata = new FormData();
901
902					formdata.append( 'request', 'submit_edit_reply' );
903					formdata.append( 'title', fields.title.val() );
904					formdata.append( 'content', fields.content.val() );
905					formdata.append( 'attachments', (fields.attachments.length > 0 ? fields.attachments.val() : '') );
906					formdata.append( 'recaptcha_response', fields.recaptcha_response );
907					formdata.append( 'review_id', review_id );
908					formdata.append( 'box_id', self.element.data( 'review-box' ) );
909					formdata.append( 'popup', in_popup ? 'yes' : 'no' );
910
911					$.each(
912						file_uploads.files,
913						function ( j, file ) {
914							formdata.append( 'file-' + j, file );
915						}
916					);
917					// Manage review creation.
918					ywar
919						.ajax(
920							formdata,
921							{
922								block:       form_wrapper,
923								processData: false,
924								contentType: false
925							}
926						)
927						.done(
928							function ( response ) {
929								if ( response.success === true ) {
930									reset_file_upload();
931									var temp_content   = $( "<div></div>" ).html( response.data.html ),
932										updated_review = temp_content.find( response.data.review_id ).html();
933									self.element.find( response.data.review_id ).html( updated_review );
934									refresh_review_stats_attachments();
935									$( 'html, body' )
936										.animate(
937											{
938												scrollTop: self.element.find( response.data.review_id ).offset().top - ywar_frontend.scroll_offset
939											},
940											200
941										);
942								} else {
943									validate_form_fields( self, fields, 'edit' );
944								}
945							}
946						);
947				}
948			},
949			submit_new_reply                 = function ( self, review_id, in_reply_of, recaptcha_response ) {
950				var form_wrapper = self.element.find( '#yith-ywar-new-reply-' + review_id ),
951					in_popup     = form_wrapper.closest( '.yith-ywar-single-review' ).hasClass( 'in-popup' ),
952					form_has_error;
953
954				var fields = {
955					user_name:          form_wrapper.find( 'input[name="yith-ywar-user-name"]' ),
956					user_email:         form_wrapper.find( 'input[name="yith-ywar-user-email"]' ),
957					title:              form_wrapper.find( 'input[name="yith-ywar-title"]' ),
958					content:            form_wrapper.find( 'textarea[name="yith-ywar-content"]' ),
959					recaptcha_wrapper:  form_wrapper.find( '.g-recaptcha' ),
960					recaptcha_response: recaptcha_response,
961					user_id:            parseInt( ywar_frontend.user_id ),
962				};
963
964				if ( ywar_frontend.use_recaptcha && 'v2' === ywar_frontend.recaptcha_version ) {
965					fields.recaptcha_response = grecaptcha.getResponse( ywar.captcha_edit );
966				}
967
968				form_has_error = validate_form_fields( self, fields, 'insert' );
969
970				if ( ! form_has_error ) {
971
972					var formdata = new FormData();
973
974					formdata.append( 'request', 'submit_new_reply' );
975					formdata.append( 'user_name', fields.user_name.val() );
976					formdata.append( 'user_email', fields.user_email.val() );
977					formdata.append( 'user_id', fields.user_id );
978					formdata.append( 'title', fields.title.val() );
979					formdata.append( 'content', fields.content.val() );
980					formdata.append( 'recaptcha_response', fields.recaptcha_response );
981					formdata.append( 'review_id', review_id );
982					formdata.append( 'in_reply_of', in_reply_of );
983					formdata.append( 'popup', in_popup ? 'yes' : 'no' );
984
985					$.each(
986						file_uploads.files,
987						function ( j, file ) {
988							formdata.append( 'file-' + j, file );
989						}
990					);
991
992					// Manage review creation.
993					ywar
994						.ajax(
995							formdata,
996							{
997								block:       form_wrapper,
998								processData: false,
999								contentType: false
1000							}
1001						)
1002						.done(
1003							function ( response ) {
1004								if ( response.success === true ) {
1005									reset_file_upload();
1006									form_wrapper.find( '.temp-attachment' ).each(
1007										function () {
1008											$( this ).remove()
1009										}
1010									);
1011									form_wrapper.find( '.attachments-list' ).addClass( 'empty' );
1012
1013									refresh_review_stats_attachments();
1014									if ( response.data.message ) {
1015										form_wrapper.html( response.data.message );
1016										$( 'html, body' )
1017											.animate(
1018												{
1019													scrollTop: form_wrapper.offset().top - ywar_frontend.scroll_offset
1020												},
1021												200
1022											);
1023									} else {
1024										self.element.find( '.yith-ywar-edit-forms:not(.new-review)' ).remove();
1025										self.element.find( '.replies-review-' + review_id ).append( response.data.html );
1026										$( 'html, body' )
1027											.animate(
1028												{
1029													scrollTop: self.element.find( response.data.review_id ).offset().top + self.element.find( response.data.review_id ).innerHeight() - 400
1030												},
1031												200
1032											);
1033									}
1034								} else {
1035									validate_form_fields( self, fields, 'insert' );
1036								}
1037							}
1038						);
1039				}
1040			},
1041			check_file_type                  = function ( file_type ) {
1042				if ( image_mime_types.includes( file_type ) ) {
1043					return 'image'
1044				} else if ( video_mime_types.includes( file_type ) ) {
1045					return 'video'
1046				}
1047				return false;
1048			},
1049			reset_file_upload                = function () {
1050				file_uploads = {form: '', files: [], type_count: {image: 0, video: 0}};
1051				$( '.messages' ).html( '' );
1052			},
1053			scroll_to_review_tab             = function () {
1054
1055				const wc_tabs = $( '.woocommerce-tabs' );
1056
1057				$( 'body' )
1058					.find( 'li.reviews_tab a' )
1059					.trigger( 'click' );
1060
1061				// Fix for Porto theme.
1062				$( 'body.theme-porto' )
1063					.find( 'li.reviews_tab' )
1064					.trigger( 'click' );
1065
1066				if ( wc_tabs.length > 0 ) {
1067					$( 'html, body' )
1068						.animate(
1069							{
1070								scrollTop: wc_tabs.offset().top - ywar_frontend.scroll_offset
1071							},
1072							500
1073						);
1074				}
1075
1076				$( document ).trigger( 'yith_ywar_review_tab' );
1077
1078			},
1079			refresh_review_stats_attachments = function () {
1080				if ( ywar_frontend.attachments_gallery || ywar_frontend.graph_bars ) {
1081					const stats_wrapper       = '.yith-ywar-stats-wrapper';
1082					const attachments_wrapper = '.yith-ywar-reviews-with-attachments';
1083					const tab_title           = '.yith-ywar-tab-title';
1084					const rating_wrapper      = '.yith-ywar-product-rating-wrapper';
1085
1086					$.ajax(
1087						{
1088							url:     window.location.href,
1089							success: function ( resp ) {
1090								if ( resp !== '' ) {
1091									const temp_content = $( '<div></div>' ).html( resp );
1092
1093									if ( $( stats_wrapper ).length > 0 ) {
1094										const stats_content = temp_content.find( stats_wrapper );
1095										$( stats_wrapper ).html( stats_content.html() );
1096									}
1097
1098									if ( $( tab_title ).length > 0 ) {
1099										const tab_title_content = temp_content.find( tab_title );
1100										$( tab_title ).html( tab_title_content.html() );
1101									}
1102
1103									if ( $( rating_wrapper ).length > 0 ) {
1104										const rating_wrapper_content = temp_content.find( rating_wrapper );
1105										$( rating_wrapper ).html( rating_wrapper_content.html() );
1106									}
1107
1108									if ( $( attachments_wrapper ).length > 0 ) {
1109										const attachments_content = temp_content.find( attachments_wrapper );
1110										if ( attachments_content.html().trim().length > 0 ) {
1111											$( attachments_wrapper ).html( attachments_content.html() ).removeClass( 'empty-gallery' );
1112										} else {
1113											$( attachments_wrapper ).addClass( 'empty-gallery' );
1114										}
1115										init_attachment_swiper();
1116									}
1117								}
1118							}
1119						}
1120					);
1121				}
1122			},
1123			init_attachment_swiper           = function () {
1124				var thumb_swiper = new ywar.Swiper(
1125					'.preview-gallery',
1126					{
1127						spaceBetween:        10,
1128						slidesPerView:       'auto',
1129						watchSlidesProgress: true,
1130						loop:                true,
1131						navigation:          {
1132							nextEl: '.swiper-button-next',
1133							prevEl: '.swiper-button-prev',
1134						},
1135					}
1136				);
1137			},
1138			yith_ywar_reviews                = function ( element ) {
1139				this.element = $( element );
1140				this.args    = {
1141					page:    1,
1142					rating:  'all',
1143					sorting: 'default',
1144					helpful: 'no'
1145				};
1146				this.popup   = false;
1147				this.wrapper = '.yith-ywar-reviews-list';
1148				this.init();
1149			},
1150			yith_ywar_reviews_shortcode      = function ( element ) {
1151				this.element = $( element );
1152				this.page    = 1;
1153				this.init();
1154			},
1155			yith_ywar_filtered_reviews       = function ( element, args ) {
1156				this.element = $( element );
1157				this.scroll  = $( '#yith-ywar-filter-popup-wrapper' );
1158				this.args    = {
1159					page:    1,
1160					rating:  args.rating,
1161					sorting: 'default',
1162					helpful: 'no'
1163				};
1164				this.popup   = true;
1165				this.wrapper = '.yith-ywar-reviews-list-popup';
1166				this.element.data( 'product-id', args.product_id );
1167				this.element.data( 'box-id', args.box_id );
1168				this.init();
1169			},
1170			yith_ywar_attachment_review      = function ( element, args ) {
1171				this.element   = $( element );
1172				this.scroll    = $( '#yith-ywar-attachments-popup-wrapper' );
1173				this.slide     = args.slide_index;
1174				this.review_id = args.review_id;
1175				this.parent    = args.parent;
1176				this.init();
1177			},
1178			yith_ywar_attachment_gallery     = function ( element, args ) {
1179				this.element   = $( element );
1180				this.scroll    = $( '#yith-ywar-gallery-popup-wrapper' );
1181				this.slide     = args.slide_index;
1182				this.review_id = args.review_id;
1183				this.parent    = args.parent;
1184				this.init();
1185			},
1186			yith_ywar_attachment_lightbox    = function ( element, args ) {
1187				this.element   = $( element );
1188				this.slide     = args.slide_index;
1189				this.review_id = args.review_id;
1190				this.parent    = args.parent;
1191				this.init();
1192			};
1193
1194		/**
1195		 * PROTOTYPES
1196		 */
1197		yith_ywar_reviews.prototype = {
1198			init:             function () {
1199				load_reviews( this, this.reviews_loaded );
1200				this.after_init();
1201			},
1202			after_init:       function () {
1203				const self = this;
1204
1205				self.element
1206					.on(
1207						'click',
1208						'.load-more-button',
1209						function () {
1210							self.args.page = $( this ).data( 'page' );
1211							load_reviews( self, self.reviews_loaded );
1212						}
1213					)
1214					.on(
1215						'click',
1216						'.yith-ywar-single-review:not(.in-popup) .single-attachment',
1217						function () {
1218							var args = {
1219								review_id:   $( this ).data( 'review-id' ),
1220								slide_index: $( this ).data( 'slide-index' ),
1221								parent:      self.element
1222							};
1223
1224							$( '#yith-ywar-attachments-popup' ).yith_ywar_attachment_review( args );
1225						}
1226					)
1227					.on(
1228						'click',
1229						'.yith-ywar-swiper.preview-gallery .swiper-slide',
1230						function () {
1231							var args = {
1232								review_id:   $( this ).data( 'review-id' ),
1233								slide_index: $( this ).data( 'slide-index' ),
1234								parent:      self.element
1235							};
1236
1237							$( '#yith-ywar-gallery-popup' ).yith_ywar_attachment_gallery( args );
1238						}
1239					)
1240					.on(
1241						'click',
1242						'.rating-group',
1243						function () {
1244							if ( 0 !== parseInt( $( this ).data( 'count' ) ) ) {
1245								if ( ywar_frontend.filter_dialog ) {
1246									var args = {
1247										rating:     $( this ).data( 'rating' ),
1248										product_id: self.element.data( 'product-id' ),
1249										box_id:     self.element.data( 'review-box' ),
1250									};
1251
1252									$( '#yith-ywar-filter-popup' ).yith_ywar_filtered_reviews( args );
1253
1254								} else {
1255									self.element.find( self.wrapper ).html( '' );
1256									self.args.page   = 1;
1257									self.args.rating = $( this ).data( 'rating' );
1258									load_reviews( self, self.reviews_loaded );
1259								}
1260							}
1261						}
1262					)
1263					.on(
1264						'click',
1265						'.filter-buttons .show-all-reviews, .filter-buttons .rating-label',
1266						function () {
1267							self.element.find( self.wrapper ).html( '' );
1268							self.args.page   = 1;
1269							self.args.rating = 'all';
1270							load_reviews( self, self.reviews_loaded );
1271						}
1272					)
1273					.on(
1274						'change',
1275						'.sorting-options',
1276						function () {
1277							self.element.find( self.wrapper ).html( '' );
1278							self.args.page    = 1;
1279							self.args.sorting = $( this ).val();
1280							load_reviews( self, self.reviews_loaded );
1281						}
1282					)
1283					.on(
1284						'click',
1285						'.tab-item',
1286						function () {
1287							self.element.find( '.tab-item' ).removeClass( 'selected' );
1288							$( this ).addClass( 'selected' );
1289							self.args             = {
1290								page:    1,
1291								rating:  'all',
1292								sorting: 'default',
1293								helpful: $( this ).data( 'filter' ) === 'helpful' ? 'yes' : 'no',
1294							};
1295							const sorting_options = self.element.find( '.sorting-options' );
1296							if ( sorting_options.length > 0 ) {
1297								sorting_options.val( 'default' ).trigger( 'change' );
1298							} else {
1299								self.element.find( self.wrapper ).html( '' );
1300								load_reviews( self, self.reviews_loaded );
1301							}
1302						}
1303					)
1304					.on(
1305						'click',
1306						'.yith-ywar-pending-reviews-list .wrapper-title',
1307						function () {
1308							$( this ).parent().find( '.wrapper-content' ).slideToggle();
1309						}
1310					);
1311
1312				init_buttons( self );
1313				init_attachment_swiper();
1314			},
1315			reviews_loaded:   function ( response, self ) {
1316				self.element.find( '.yith-ywar-filter-data' ).remove();
1317				self.element.find( '.load-more-reviews' ).remove();
1318				self.element.find( self.wrapper ).append( response.data.reviews );
1319				if ( response.data.message ) {
1320					$( response.data.message ).insertAfter( '.yith-ywar-stats-wrapper' );
1321				}
1322
1323				if ( window.location.hash.indexOf( '#review-' ) !== -1 || window.location.hash.indexOf( '#comment-' ) !== -1 ) {
1324					self.scroll_to_review( window.location.hash.replace( 'comment', 'review' ) );
1325				}
1326			},
1327			scroll_to_review: function ( review_id ) {
1328				if ( $( review_id ).length > 0 ) {
1329					$( 'html, body' )
1330						.animate(
1331							{
1332								scrollTop: $( review_id ).offset().top - ywar_frontend.scroll_offset
1333							},
1334							200
1335						);
1336					history.replaceState( "", document.title, window.location.pathname );
1337				}
1338			},
1339		};
1340
1341		yith_ywar_reviews_shortcode.prototype = {
1342			init:         function () {
1343				if ( ywar_frontend.is_block_editor ) {
1344					this.element.css( 'min-height', '400px' )
1345				}
1346				this.load_reviews();
1347				this.after_init();
1348			},
1349			load_reviews: function () {
1350				const self = this;
1351				ywar
1352					.ajax(
1353						{
1354							settings: self.element.data( 'settings' ),
1355							request:  'load_reviews_shortcode',
1356							page:     self.page,
1357						},
1358						{block: self.element}
1359					)
1360					.done(
1361						function ( response ) {
1362							self.element.find( '.load-more-reviews-shortcode' ).remove();
1363							self.element.append( response.data );
1364						}
1365					);
1366			},
1367			after_init:   function () {
1368				const self = this;
1369
1370				self.element
1371					.on(
1372						'click',
1373						'.load-more-button-shortcode',
1374						function () {
1375							self.page = $( this ).data( 'page' );
1376							self.load_reviews();
1377						}
1378					)
1379					.on(
1380						'click',
1381						'.yith-ywar-single-review:not(.in-popup) .single-attachment',
1382						function () {
1383							var args = {
1384								review_id:   $( this ).data( 'review-id' ),
1385								slide_index: $( this ).data( 'slide-index' ),
1386								parent:      self.element
1387							};
1388
1389							ywar
1390								.ajax(
1391									{
1392										request:   'load_attachment_popup',
1393										review_id: $( this ).data( 'review-id' ),
1394									},
1395									{block: self.element}
1396								)
1397								.done(
1398									function ( response ) {
1399										var popup = '#yith-ywar-attachments-popup';
1400										$( popup ).remove();
1401										$( 'body' ).append( response.data );
1402										$( popup ).yith_ywar_attachment_review( args );
1403									}
1404								);
1405						}
1406					);
1407
1408				init_buttons( self );
1409			}
1410		};
1411
1412		yith_ywar_filtered_reviews.prototype = {
1413			init:            function () {
1414				this.element.find( '.filter-options' ).val( this.args.rating );
1415				load_reviews( this, this.open_popup );
1416				this.after_load();
1417			},
1418			open_popup:      function ( content, self ) {
1419				self.init_scrollbar( self.scroll );
1420				// Add class to html for prevent page scroll on mobile device.
1421				$( 'html' ).addClass( 'yith-ywar-open-popup' );
1422				self.element.removeClass( 'closed' ).addClass( 'visible' );
1423				self.element.find( '.popup-content' ).html( '<div class="yith-ywar-reviews-list-popup">' + content.data.reviews + '</div>' );
1424			},
1425			init_scrollbar:  function ( scroller ) {
1426				sb_instance = new ywar.SimpleBar(
1427					scroller[0],
1428					{
1429						forceVisible: true,
1430						autoHide:     false
1431					}
1432				);
1433			},
1434			after_load_more: function ( response, self ) {
1435				wrapper = self.element.find( self.wrapper );
1436				wrapper.find( '.load-more-reviews-popup' ).remove();
1437				wrapper.append( response.data.reviews );
1438			},
1439			after_load:      function () {
1440				const self = this;
1441
1442				self.element
1443					.on(
1444						'click',
1445						'.load-more-button-popup',
1446						function () {
1447							self.args.page = $( this ).data( 'page' );
1448							load_reviews( self, self.after_load_more );
1449						}
1450					)
1451					.on(
1452						'change',
1453						'.filter-options',
1454						function () {
1455							self.args.page   = 1;
1456							self.args.rating = $( this ).val();
1457							load_reviews(
1458								self,
1459								function ( response ) {
1460									self.scroll.scrollTop( 0 );
1461									self.element.find( self.wrapper ).html( response.data.reviews );
1462								}
1463							);
1464						}
1465					)
1466					.on(
1467						'click',
1468						'.popup-close, .popup-close-link',
1469						function ( e ) {
1470							e.preventDefault();
1471							self.close_popup();
1472						}
1473					)
1474					.on(
1475						'click',
1476						'.yith-ywar-single-review.in-popup .single-attachment',
1477						function () {
1478							var args = {
1479								review_id:   $( this ).data( 'review-id' ),
1480								slide_index: $( this ).data( 'slide-index' ),
1481								parent:      self.element
1482							};
1483							$( '#yith-ywar-gallery-lightbox' ).yith_ywar_attachment_lightbox( args );
1484						}
1485					);
1486				init_buttons( self );
1487
1488				// Init selectWoo on sorting dropdown.
1489				$( '.filter-options' )
1490					.selectWoo(
1491						{
1492							dropdownCssClass:        'yith-ywar-select2-stars',
1493							minimumResultsForSearch: Infinity,
1494							templateResult:          function ( state ) {
1495								if ( ! state.id ) {
1496									return state.text;
1497								}
1498
1499								return $( '<span class="select2-star-rating" title="' + state.id + '">' + state.text + '</span>' );
1500							},
1501						}
1502					);
1503			},
1504			close_popup:     function () {
1505
1506				// Popup close actions.
1507				this.element.addClass( 'closed' ).removeClass( 'visible' );
1508				// Remove class to html.
1509				$( 'html' ).removeClass( 'yith-ywar-open-popup' );
1510				$( document )
1511					.off(
1512						'click',
1513						'.load-more-button-popup'
1514					);
1515				this.scroll.scrollTop( 0 );
1516				sb_instance = null;
1517			},
1518		};
1519
1520		yith_ywar_attachment_review.prototype = {
1521			init:           function () {
1522				const self = this;
1523				ywar
1524					.ajax(
1525						{
1526							review_id: self.review_id,
1527							request:   'load_single_review',
1528						},
1529						{block: self.parent}
1530					)
1531					.done(
1532						function ( response ) {
1533							self.open_popup( response, self );
1534						}
1535					);
1536
1537			},
1538			open_popup:     function ( content, self ) {
1539				self.init_scrollbar( self.scroll );
1540				// Add class to html for prevent page scroll on mobile device.
1541				$( 'html' ).addClass( 'yith-ywar-open-popup' );
1542				self.element.removeClass( 'closed' ).addClass( 'visible' );
1543				self.element.find( '.popup-content' ).html( content.data );
1544				self.after_load( self );
1545			},
1546			init_scrollbar: function ( scroller ) {
1547				sb_instance = new ywar.SimpleBar(
1548					scroller[0],
1549					{
1550						forceVisible: true,
1551						autoHide:     false
1552					}
1553				);
1554			},
1555			after_load:     function ( self ) {
1556
1557				$( document )
1558					.on(
1559						'click',
1560						'.popup-close, .popup-close-link',
1561						function ( e ) {
1562							e.preventDefault();
1563							self.close_popup();
1564						}
1565					);
1566
1567				init_swiper( self.slide, 'gallery' );
1568			},
1569			close_popup:    function () {
1570				// Popup close actions.
1571				this.element.addClass( 'closed' ).removeClass( 'visible' );
1572				// Remove class to html.
1573				$( 'html' ).removeClass( 'yith-ywar-open-popup' );
1574				this.scroll.scrollTop( 0 );
1575				this.element.find( '.popup-content' ).html( '' );
1576				sb_instance = null;
1577			}
1578		};
1579
1580		yith_ywar_attachment_gallery.prototype = {
1581			init:           function () {
1582				const self = this;
1583				ywar
1584					.ajax(
1585						{
1586							active_review_id: self.review_id,
1587							request:          'load_reviews_with_attachments',
1588						},
1589						{block: self.parent}
1590					)
1591					.done(
1592						function ( response ) {
1593							self.open_popup( response, self );
1594						}
1595					);
1596			},
1597			open_popup:     function ( content, self ) {
1598				self.init_scrollbar( self.scroll );
1599				// Add class to html for prevent page scroll on mobile device.
1600				$( 'html' ).addClass( 'yith-ywar-open-popup' );
1601				self.element.removeClass( 'closed' ).addClass( 'visible' );
1602				self.element.find( '.popup-content' ).html( content.data );
1603				self.after_load( self );
1604			},
1605			init_scrollbar: function ( scroller ) {
1606				sb_instance = new ywar.SimpleBar(
1607					scroller[0],
1608					{
1609						forceVisible: true,
1610						autoHide:     false
1611					}
1612				);
1613			},
1614			after_load:     function ( self ) {
1615				$( document )
1616					.on(
1617						'click',
1618						'.popup-close, .popup-close-link',
1619						function ( e ) {
1620							e.preventDefault();
1621							self.close_popup();
1622						}
1623					);
1624
1625				init_swiper( self.slide, 'gallery' );
1626			},
1627			close_popup:    function () {
1628				// Popup close actions.
1629				this.element.addClass( 'closed' ).removeClass( 'visible' );
1630				// Remove class to html.
1631				$( 'html' ).removeClass( 'yith-ywar-open-popup' );
1632				this.scroll.scrollTop( 0 );
1633				this.element.find( '.popup-content' ).html( '' );
1634				sb_instance = null;
1635			}
1636		};
1637
1638		yith_ywar_attachment_lightbox.prototype = {
1639			init:        function () {
1640				const self = this;
1641				ywar
1642					.ajax(
1643						{
1644							review_id: self.review_id,
1645							request:   'load_review_attachments',
1646						},
1647						{block: self.parent}
1648					)
1649					.done(
1650						function ( response ) {
1651							self.open_popup( response, self );
1652						}
1653					);
1654
1655			},
1656			open_popup:  function ( content, self ) {
1657				self.element.removeClass( 'closed' ).addClass( 'visible' );
1658				self.element.find( '.lightbox-content' ).html( content.data );
1659				self.after_load( self );
1660			},
1661			after_load:  function ( self ) {
1662				$( document )
1663					.on(
1664						'click',
1665						'.lightbox-close, .lightbox-overlay',
1666						function ( e ) {
1667							e.preventDefault();
1668							self.close_popup();
1669						}
1670					);
1671
1672				init_swiper( self.slide, 'lightbox' );
1673			},
1674			close_popup: function () {
1675				// Popup close actions.
1676				this.element.removeClass( 'visible' ).addClass( 'closed' );
1677			}
1678		};
1679
1680		$.fn.yith_ywar_reviews             = function () {
1681			return this.each(
1682				function () {
1683					if ( ! $.data( this, 'plugin_yith_ywar_reviews' ) ) {
1684						$.data( this, 'plugin_yith_ywar_reviews', new yith_ywar_reviews( this ) );
1685					}
1686				}
1687			);
1688		};
1689		$.fn.yith_ywar_reviews_shortcode   = function () {
1690			return this.each(
1691				function () {
1692					if ( ! $.data( this, 'plugin_yith_ywar_reviews_shortcode' ) ) {
1693						$.data( this, 'plugin_yith_ywar_reviews_shortcode', new yith_ywar_reviews_shortcode( this ) );
1694					}
1695				}
1696			);
1697		};
1698		$.fn.yith_ywar_filtered_reviews    = function ( args ) {
1699			$.data( this, 'plugin_yith_ywar_filtered_reviews', new yith_ywar_filtered_reviews( this, args ) );
1700		};
1701		$.fn.yith_ywar_attachment_review   = function ( args ) {
1702			$.data( this, 'plugin_yith_ywar_attachment_review', new yith_ywar_attachment_review( this, args ) );
1703		};
1704		$.fn.yith_ywar_attachment_gallery  = function ( args ) {
1705			$.data( this, 'plugin_yith_ywar_attachment_gallery', new yith_ywar_attachment_gallery( this, args ) );
1706		};
1707		$.fn.yith_ywar_attachment_lightbox = function ( args ) {
1708			$.data( this, 'plugin_yith_ywar_attachment_lightbox', new yith_ywar_attachment_lightbox( this, args ) );
1709		};
1710
1711		$( 'body' )
1712			.on(
1713				'init',
1714				function () {
1715
1716					if ( ywar_init ) {
1717						console.log( 'YWAR already loaded' );
1718
1719						return;
1720					}
1721					ywar_init = true;
1722					console.log( 'YWAR loaded' );
1723
1724					if ( window.location.hash === '#reviews' ) {
1725						scroll_to_review_tab();
1726					}
1727
1728					// Load reviews on page load.
1729					$( '.yith-ywar-main-wrapper' ).each(
1730						function () {
1731							$( this ).yith_ywar_reviews()
1732						}
1733					);
1734				}
1735			)
1736			.trigger( 'init' );
1737
1738		$( 'body:not(.woocommerce)' ).trigger( 'init' );
1739
1740		// Load reviews in shortcode on page load.
1741		$( '.yith-ywar-reviews-list-shortcode' ).each(
1742			function () {
1743				$( this ).yith_ywar_reviews_shortcode()
1744			}
1745		);
1746
1747		$( document )
1748			.on(
1749				'click',
1750				'.yith-ywar-user-reviews-wrapper.in-shortcode .review-pagination',
1751				function ( e ) {
1752					e.preventDefault();
1753					var wrapper = $( '.yith-ywar-user-reviews-wrapper' );
1754					ywar
1755						.ajax(
1756							{
1757								page:    $( this ).data( 'page' ),
1758								request: 'load_user_reviews',
1759							},
1760							{block: wrapper}
1761						)
1762						.done(
1763							function ( response ) {
1764
1765								if ( response.success === true ) {
1766									wrapper.html( $( response.data ).html() );
1767									$( 'html, body' )
1768										.animate(
1769											{
1770												scrollTop: wrapper.offset().top - ywar_frontend.scroll_offset
1771											},
1772											200
1773										);
1774								}
1775							}
1776						);
1777
1778				}
1779			)
1780			.on(
1781				'click',
1782				'a.total-reviews',
1783				function ( e ) {
1784					e.stopPropagation();
1785					e.preventDefault();
1786					scroll_to_review_tab();
1787				}
1788			);
1789
1790		// Init selectWoo on sorting dropdown.
1791		$( '.sorting-options' )
1792			.selectWoo(
1793				{
1794					dropdownCssClass:        'yith-ywar-select2',
1795					minimumResultsForSearch: Infinity
1796				}
1797			);
1798	}
1799)( jQuery, window.ywar );

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.