(function($, publicConfig){
'use strict';
let JetReviews={
eventBus: new Vue(),
initedInstance: [],
captchaToken: false,
init: function(){
JetReviews.defineVueComponents();
this.initInstances();
window.addEventListener('jetReviews/editor/templateRenderer/renderSuccess',(event)=> {
this.initBlockInstances();
}, false);
},
initInstances: function(){
let instancesList=$('.jet-reviews-advanced');
if(! instancesList[0]){
return false;
}
instancesList.each(function(){
let $target=$(this),
instanceId=$target.attr('id'),
uniqid=$target.data('uniqid')||false,
options=window['jetReviewsWidget' + uniqid]||false;
if(! options){
let optionsScript=document.getElementById('jetReviewsWidgetOptions' + uniqid);
if(optionsScript){
eval(optionsScript.innerHTML);
options=window['jetReviewsWidget' + uniqid]||false;
}}
if(! $target[0]||! uniqid||! options){
return;
}
window.JetReviews.createJetReviewAdvancedInstance(instanceId, options);
});
},
initBlockInstances: function(){
const targetNode=document.querySelector('.jet-reviews-block-holder');
if(! targetNode) return;
const observer=new MutationObserver(function(mutationsList, observer){
for(const mutation of mutationsList){
if(mutation.type==='childList'){
const event=new Event('jetReviews/editor/block/renderSuccess');
document.dispatchEvent(event);
observer.disconnect();
}}
});
observer.observe(targetNode, { childList: true, subtree: true });
document.addEventListener('jetReviews/editor/block/renderSuccess',(event)=> {
this.initInstances();
});
},
defineVueComponents: function(){
Vue.component('jet-reviews-widget-pagination', {
template: '#jet-reviews-widget-pagination-template',
props: {
current: {
type: Number,
default: 1
},
total: {
type: Number,
default: 0
},
pageSize: {
type: Number,
default: 10
},
prevIcon: {
type: String,
default: '<svg width="7" height="12" viewBox="0 0 7 12" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M5.67089 0L-5.96046e-08 6L5.67089 12L7 10.5938L2.65823 6L7 1.40625L5.67089 0Z"/></svg>'
},
nextIcon: {
type: String,
default: '<svg width="7" height="12" viewBox="0 0 7 12" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1.32911 0L7 6L1.32911 12L0 10.5938L4.34177 6L0 1.40625L1.32911 0Z"/></svg>'
},
customCss: {
type: String,
default: ''
},
},
data(){
return {
baseClass: 'jet-reviews-widget-pagination',
currentPage: this.current,
currentPageSize: this.pageSize
};},
watch: {
total(val){
let maxPage=Math.ceil(val / this.currentPageSize);
if(maxPage < this.currentPage){
this.currentPage=(maxPage===0 ? 1:maxPage);
}},
current(val){
this.currentPage=val;
},
pageSize(val){
this.currentPageSize=val;
}},
computed: {
classesList(){
let classesList=[
this.baseClass,
];
if(this.customCss){
classesList.push(this.customCss);
}
return classesList;
},
prevClasses (){
return [
`${this.baseClass}__item`,
`${this.baseClass}__item--prev`,
{
[`${this.baseClass}__item--disabled`]: this.currentPage===1||false
}
];
},
nextClasses (){
return [
`${this.baseClass}__item`,
`${this.baseClass}__item--next`,
{
[`${this.baseClass}__item--disabled`]: this.currentPage===this.allPages||false
}
];
},
firstPageClasses (){
return [
`${this.baseClass}__item`,
{
[`${this.baseClass}__item--active`]: this.currentPage===1
}
];
},
lastPageClasses (){
return [
`${this.baseClass}__item`,
{
[`${this.baseClass}__item--active`]: this.currentPage===this.allPages
}
];
},
allPages (){
const allPage=Math.ceil(this.total / this.currentPageSize);
return(allPage===0) ? 1:allPage;
},
},
methods: {
changePage(page){
if(this.currentPage!==page){
this.currentPage=page;
this.$emit('update:current', page);
this.$emit('on-change', page);
}},
prev (){
const current=this.currentPage;
if(current <=1){
return false;
}
this.changePage(current - 1);
},
next (){
const current=this.currentPage;
if(current >=this.allPages){
return false;
}
this.changePage(current + 1);
},
fastPrev (){
const page=this.currentPage - 5;
if(page > 0){
this.changePage(page);
}else{
this.changePage(1);
}},
fastNext (){
const page=this.currentPage + 5;
if(page > this.allPages){
this.changePage(this.allPages);
}else{
this.changePage(page);
}},
},
});
Vue.component('jet-advanced-reviews-form', {
template: '#jet-advanced-reviews-form-template',
props: {
reviewFields: Array
},
data: function(){
return ( {
reviewSubmiting: false,
reviewTitle: '',
reviewContent: '',
reviewAuthorName: '',
reviewAuthorMail: '',
reviewMedia: [],
reviewMediaPreview: [],
messageText: '',
fields: this.reviewFields,
isValidUpload: true,
trySend: false
});
},
mounted: function(){
let self=this;
Vue.nextTick().then(function (){
let reviewContent=self.$refs.reviewContent,
textarea=reviewContent.$refs.textarea;
textarea.focus();
});
if(this.$root.isUserGuest){
this.reviewAuthorName=JetReviews.getLocalStorageData('guestName', '');
this.reviewAuthorMail=JetReviews.getLocalStorageData('guestMail', '');
}},
computed: {
formControlsVisible: function(){
if(this.$root.isUserGuest){
return this.isValidReviewContent &&
this.isValidReviewTitle &&
this.isValidAuthorName &&
this.isValidAuthorEmail;
}
return this.isValidReviewContent&&this.isValidReviewTitle;
},
formMessageVisible: function(){
return ''!==this.messageText;
},
reviewTitleVisible: function(){
return this.$root.options.reviewTitleInputVisible;
},
reviewContentVisible: function(){
return this.$root.options.reviewContentInputVisible;
},
isValidReviewTitle: function(){
if(! this.trySend){
return true
}
return ''!==this.reviewTitle||! this.reviewTitleVisible;
},
isValidReviewContent: function(){
if(! this.trySend){
return true
}
return ''!==this.reviewContent||! this.reviewContentVisible;
},
isValidAuthorName: function(){
if(! this.trySend){
return true
}
return ''!==this.reviewAuthorName;
},
isValidAuthorEmail: function(){
if(! this.trySend){
return true
}
return(''!==this.reviewAuthorMail&&JetReviews.checkValidEmail(this.reviewAuthorMail) );
},
isValidMedia: function(){
return this.isValidUpload;
}},
methods: {
cancelSubmit: function(){
JetReviews.eventBus.$emit('closeNewReviewForm', { uniqId: this.$root.options.uniqId });
},
submitReview: function(){
this.trySend=true;
if(! this.formControlsVisible){
return false;
}
let self=this,
forSendingData={
source: this.$root.sourceData.source,
source_type: this.$root.sourceData.sourceType,
source_id: this.$root.sourceData.sourceId,
title: this.reviewTitle,
content: this.reviewContent,
author_id: this.$root.userData.id,
author_name: this.reviewAuthorName,
author_mail: this.reviewAuthorMail,
rating_data: this.fields,
media: this.reviewMedia,
},
recaptchaConfig=window.jetReviewPublicConfig.recaptchaConfig;
if(recaptchaConfig.enable){
window.grecaptcha.ready(function(){
grecaptcha.execute(recaptchaConfig.site_key,
{
action: 'submit_review'
}
).then(function(token){
JetReviews.captchaToken=token;
let modifyData=Object.assign({}, forSendingData, {
captcha_token: token
});
self.submitReviewHandle(modifyData);
});
});
return false;
}
this.submitReviewHandle(forSendingData);
},
submitReviewHandle: function(sendData=false){
let self=this;
if(! sendData){
console.warn('Empty new review data for sending');
return false;
}
const formData=new FormData();
formData.append('source', sendData.source);
formData.append('source_type', sendData.source_type);
formData.append('source_id', sendData.source_id) ;
formData.append('title', sendData.title);
formData.append('content', sendData.content);
formData.append('author_id', sendData.author_id);
formData.append('author_name', sendData.author_name);
formData.append('author_mail', sendData.author_mail);
formData.append('rating_data', JSON.stringify(sendData.rating_data||{}) );
formData.append('captcha_token', sendData.captcha_token||'');
for(const file of sendData.media){
formData.append('attached_media[]', file);
}
this.reviewSubmiting=true;
this.messageText='';
wp.apiFetch({
method: 'post',
path: window.jetReviewPublicConfig.submitReviewRoute,
body: formData,
}).then(function(response){
response=self.maybeModifyResponce(response);
let responseSuccess=response.success,
responseData=response.data,
responseMessage=response.message;
self.reviewSubmiting=false;
self.messageText=responseMessage;
if(self.$root.isUserGuest){
let guestReviewedItems=JetReviews.getLocalStorageData(self.$root.guestReviewedStorageName, []);
if(responseSuccess&&! guestReviewedItems.includes(self.$root.sourceData.sourceId) ){
self.$root.userData.name=self.reviewAuthorName;
self.$root.userData.mail=self.reviewAuthorMail;
JetReviews.setLocalStorageData('guestName', self.reviewAuthorName);
JetReviews.setLocalStorageData('guestMail', self.reviewAuthorMail);
guestReviewedItems.push(self.$root.sourceData.sourceId);
JetReviews.setLocalStorageData(self.$root.guestReviewedStorageName, guestReviewedItems);
}}
if(responseSuccess){
if('review-created'===response.code){
JetReviews.eventBus.$emit('addReview', {
uniqId: self.$root.options.uniqId,
reviewData: responseData.item,
});
self.$root.reviewsAverageRating=+responseData.rating;
}
self.$root.formVisible=false;
self.$root.userData.canReview.allowed=false;
self.$root.userData.canReview.message=responseMessage;
}});
},
maybeModifyResponce: function(responce=false){
let code=responce.code;
if('need-approve'===code&&''!==this.$root.options.labels.moderatorCheckMessage){
responce.message=this.$root.options.labels.moderatorCheckMessage;
}
if('already-created'===code&&''!==this.$root.options.labels.alreadyReviewedMessage){
responce.message=this.$root.options.labels.alreadyReviewedMessage;
}
return responce;
},
handleFiles(files){
this.reviewMedia=files;
},
handleUploadStatus(payload){
this.isValidUpload=payload;
},
requiredFieldsCheck(){
return true;
}}
});
Vue.component('slider-input', {
template: '#jet-advanced-reviews-slider-input-template',
props: {
value: {
type: [ String, Number ],
default: ''
},
max: {
type: [ Number ],
default: 5
},
step: {
type: [ Number ],
default: 1
},
label: {
type: [ String, Boolean ],
default: false
},
},
data: function(){
return ( {
});
},
computed: {
valueLabel: function(){
return this.value;
}},
methods: {
handleInput(event){
let value=event.target.value;
this.$emit('input', value);
this.$emit('on-change', event);
},
handleChange(event){
this.$emit('on-input-change', event);
}},
});
Vue.component('stars-input', {
template: '#jet-advanced-reviews-stars-input-template',
props: {
value: {
type: [ String, Number ],
default: ''
},
max: {
type: [ Number ],
default: 5
},
step: {
type: [ Number ],
default: 1
},
label: {
type: [ String, Boolean ],
default: false
},
},
data: function(){
return ( {
currentRating: this.value,
});
},
computed: {
valueLabel: function(){
return `${ this.value }/${ this.max }`;
},
rating: function(){
return(this.currentRating / this.max) * 100;
},
preparedRating: function(){
if(10 > this.rating){
return 10;
}
return this.rating;
},
emptyIcon: function(){
return this.$root.refsHtml.emptyStarIcon||'<i class="far fa-star"></i>';
},
emptyIcons: function(){
let icon=`<div class="jet-reviews-star">${ this.$root.refsHtml.emptyStarIcon }</div>`||'<div class="jet-reviews-star"><i class="far fa-star"></i></div>';
return icon.repeat(this.max);
},
filledIcons: function(){
let icon=`<div class="jet-reviews-star">${ this.$root.refsHtml.filledStarIcon }</div>`||`<div class="jet-reviews-star"><i class="fas fa-star"></i></div>`;
return icon.repeat(this.max);
},
ratingClass: function(){
let ratingClass='very-high-rating';
if(this.rating >=80&&this.rating <=100){
ratingClass='very-high-rating';
}
if(this.rating >=60&&this.rating <=79){
ratingClass='high-rating';
}
if(this.rating >=40&&this.rating <=59){
ratingClass='medium-rating';
}
if(this.rating >=22&&this.rating <=39){
ratingClass='low-rating';
}
if(this.rating >=0&&this.rating <=21){
ratingClass='very-low-rating';
}
return ratingClass;
},
},
methods: {
ratingClick(rating){
this.currentRating=rating;
this.$emit('input', rating);
},
ratingMouseOver(rating){
this.currentRating=rating;
},
ratingMouseOut(){
this.currentRating=this.value;
},
},
});
Vue.component('jet-advanced-reviews-item', {
template: '#jet-advanced-reviews-item-template',
props: {
itemData: Object
},
data: function(){
return ( {
commentFormVisible: false,
commentText: '',
commentAuthorName: '',
commentAuthorMail: '',
commentSubmiting: false,
approvalSubmiting: false,
parentComment: 0,
commentsVisible: false,
responseMessage: '',
detailsVisibleState: false
});
},
mounted: function(){
if(this.$root.isUserGuest){
this.commentAuthorName=JetReviews.getLocalStorageData('guestName', '');
this.commentAuthorMail=JetReviews.getLocalStorageData('guestMail', '');
let guestReviewRatedData=JetReviews.getLocalStorageData(this.$root.guestRatedStorageName, {});
if(guestReviewRatedData.hasOwnProperty(this.itemData.id) ){
this.$set(this.itemData, 'approval', guestReviewRatedData[ this.itemData.id ]);
}}
},
computed: {
isDetailsFieldsAvaliable: function(){
return 1 < this.itemData.rating_data.length;
},
detailsVisible: function(){
return this.isDetailsFieldsAvaliable&&this.detailsVisibleState;
},
averageRatingVisible: function(){
return 'average'===this.$root.options.reviewRatingType;
},
detailsRatingVisible: function(){
return 'details'===this.$root.options.reviewRatingType;
},
authorVerificationData: function(){
return 0!==this.itemData.verifications.length ? this.itemData.verifications:false;
},
isCommentsEmpty: function(){
return 0===this.itemData.comments.length;
},
isCommentsVisible: function(){
return !this.isCommentsEmpty&&this.commentsVisible;
},
itemCommentsCount: function(){
let itemCommentsCount=false;
itemCommentsCount=this.getCommentsCount(this.itemData.comments);
return itemCommentsCount;
},
pinnedVisible: function(){
return this.itemData.pinned;
},
commentControlsVisible: function(){
if(this.$root.isUserGuest){
return this.isCommentValid &&
this.isValidAuthorName &&
this.isValidAuthorEmail;
}
return this.isCommentValid;
},
averageRatingData: function(){
let ratingDatalength=this.itemData.rating_data.length,
summaryValue=0,
avarageValue=0,
summaryMax=0,
avarageMax=0;
summaryValue=this.itemData.rating_data.reduce(function(accumulator, currentValue){
return accumulator + +currentValue.field_value;
}, 0);
summaryMax=this.itemData.rating_data.reduce(function(accumulator, currentValue){
return accumulator + +currentValue.field_max;
}, 0);
avarageValue=Math.round(summaryValue / ratingDatalength);
avarageMax=Math.round(summaryMax / ratingDatalength);
return {
rating: Math.round(avarageValue * 100 / avarageMax, 1),
max: Math.round(avarageMax, 1),
value: Math.round(avarageValue, 1)
};},
addCommentIcon: function(){
return this.$root.refsHtml.newCommentButtonIcon||false;
},
showCommentsIcon: function(){
return this.$root.refsHtml.showCommentsButtonIcon||false;
},
pinnedIcon: function(){
return this.$root.refsHtml.pinnedIcon||'<i class="fas fa-thumbtack"></i>';
},
likeIcon: function(){
let emptyLike=this.$root.refsHtml.reviewEmptyLikeIcon||'<i class="far fa-thumbs-up"></i>',
filledLike=this.$root.refsHtml.reviewFilledLikeIcon||'<i class="fas fa-thumbs-up"></i>';
return ! this.itemData.approval.like ? emptyLike:filledLike;
},
dislikeIcon: function(){
let emptyDislike=this.$root.refsHtml.reviewEmptyDislikeIcon||'<i class="far fa-thumbs-down"></i>',
filledDislike=this.$root.refsHtml.reviewFilledDislikeIcon||'<i class="fas fa-thumbs-down"></i>';
return ! this.itemData.approval.dislike ? emptyDislike:filledDislike;
},
userCanComment: function(){
return this.$root.sourceData.commentsAllowed&&this.$root.userData.canComment.allowed;
},
userCanRate: function(){
return this.$root.sourceData.approvalAllowed&&this.$root.userData.canRate;
},
isValidAuthorName: function(){
return ''!==this.commentAuthorName;
},
isValidAuthorEmail: function(){
return JetReviews.checkValidEmail(this.commentAuthorMail);
},
isCommentValid: function(){
return ''!==this.commentText;
},
mediaList: function(){
if(0===this.itemData.media.length){
return false
}
return this.itemData.media;
}},
methods: {
showCommentForm: function(){
let self=this;
this.commentFormVisible = !this.commentFormVisible;
if(this.commentFormVisible){
Vue.nextTick().then(function (){
let commentContent=self.$refs.commentContent,
textarea=commentContent.$refs.textarea;
textarea.focus();
});
}},
cancelNewComment: function(){
this.commentFormVisible=false;
this.responseMessage='';
},
submitNewComment: function(){
let self=this,
forSendingData={
source: this.$root.sourceData.source,
source_type: this.$root.sourceData.sourceType,
source_id: this.$root.sourceData.sourceId,
parent_id: this.parentComment,
review_id: this.itemData.id,
author_id: this.$root.userData.id,
author_name: this.commentAuthorName,
author_mail: this.commentAuthorMail,
content: this.commentText,
},
recaptchaConfig=window.jetReviewPublicConfig.recaptchaConfig;
if(recaptchaConfig.enable){
window.grecaptcha.ready(function(){
grecaptcha.execute(recaptchaConfig.site_key,
{
action: 'submit_review_comment'
}
).then(function(token){
JetReviews.captchaToken=token;
let modifyData=Object.assign({}, forSendingData, {
captcha_token: token
});
self.submitCommentHandler(modifyData);
});
});
return false;
}
this.submitCommentHandler(forSendingData);
},
submitCommentHandler: function(sendData=false){
let self=this;
if(! sendData){
console.warn('Empty new comment data for sending');
return false;
}
this.commentSubmiting=true;
wp.apiFetch({
method: 'post',
path: window.jetReviewPublicConfig.submitReviewCommentRoute,
data: sendData,
}).then(function(response){
self.commentSubmiting=false;
self.$root.userData.name=self.commentAuthorName;
self.$root.userData.mail=self.commentAuthorMail;
JetReviews.setLocalStorageData('guestName', self.commentAuthorName);
JetReviews.setLocalStorageData('guestMail', self.commentAuthorMail);
if(response.success){
self.commentFormVisible=false;
self.commentText='';
self.itemData.comments.unshift(response.data);
self.commentsVisible=true;
}else{
self.responseMessage=response.message;
console.log(response.message);
}});
},
updateApprovalHandler: function(type){
let self=this,
altType='like'===type ? 'dislike':'like';
this.approvalSubmiting=true;
wp.apiFetch({
method: 'post',
path: window.jetReviewPublicConfig.likeReviewRoute,
data: {
review_id: self.itemData.id,
type: type,
inc: ! self.itemData.approval[ type ],
current_state: self.itemData.approval,
},
}).then(function(response){
self.approvalSubmiting=false;
if(response.success){
self.$set(self.itemData, 'approval', response.data.approval);
self.$set(self.itemData, 'like', response.data.like);
self.$set(self.itemData, 'dislike', response.data.dislike);
if(self.$root.isUserGuest){
self.updateGuestApprovalData(self.itemData.id, self.itemData.approval);
}}else{
console.log(response.message);
}});
},
updateGuestApprovalData: function($reviewId=false, rateData=false){
let guestReviewRateData=JetReviews.getLocalStorageData(this.$root.guestRatedStorageName, {});
guestReviewRateData[ $reviewId ]=rateData;
JetReviews.setLocalStorageData(this.$root.guestRatedStorageName, guestReviewRateData);
},
toggleCommentsVisible: function(){
this.commentsVisible = !this.commentsVisible;
},
getCommentsCount: function(comments, initialValue=0){
let total=comments.reduce(( accumulator, commentData)=> {
if(commentData.hasOwnProperty('children')&&0!==commentData.children.length){
let initialValue=accumulator + 1;
return this.getCommentsCount(commentData.children, initialValue);
}else{
return accumulator + 1;
}}, initialValue);
return total;
}}
});
Vue.component('jet-advanced-reviews-comment', {
template: '#jet-advanced-reviews-comment-template',
props: {
commentData: Object,
parentId: Number,
parentComments: Array,
depth: Number,
},
data: function(){
return ( {
commentsList: this.commentData.children||[],
replySubmiting: false,
replyFormVisible: false,
replyText: '',
replyAuthorName: '',
replyAuthorMail: '',
responseMessage: ''
});
},
mounted: function(){
if(this.$root.isUserGuest){
this.replyAuthorName=JetReviews.getLocalStorageData('guestName', '');
this.replyAuthorMail=JetReviews.getLocalStorageData('guestMail', '');
}},
computed: {
commentClass: function(){
return '';
},
formControlsVisible: function(){
return this.$root.sourceData.commentsAllowed;
},
submitVisible: function(){
if(this.$root.isUserGuest){
return this.isReplyTextValid &&
this.isValidAuthorName &&
this.isValidAuthorEmail;
}
return this.isReplyTextValid;
},
replyIcon: function(){
return this.$root.refsHtml.replyButtonIcon||false;
},
isValidAuthorName: function(){
return ''!==this.replyAuthorName;
},
isValidAuthorEmail: function(){
return JetReviews.checkValidEmail(this.replyAuthorMail);
},
isReplyTextValid: function(){
return ''!==this.replyText;
},
authorVerificationData: function(){
if(! this.commentData.verifications){
return false;
}
return 0!==this.commentData.verifications.length ? this.commentData.verifications:false;
},
},
methods: {
showReplyForm: function(){
let self=this;
this.replyFormVisible = !this.replyFormVisible;
if(this.replyFormVisible){
this.replyText='<b>' + this.commentData.author.name + '</b>,&nbsp;';
Vue.nextTick().then(function (){
let commentText=self.$refs.commentText,
textarea=commentText.$refs.textarea;
JetReviews.placeCaretAtEnd(textarea);
});
}},
cancelNewReply: function(){
this.replyFormVisible=false;
this.responseMessage='';
},
submitNewReply: function(){
let self=this,
forSendingData={
source: this.$root.sourceData.source,
source_type: this.$root.sourceData.sourceType,
source_id: this.$root.sourceData.sourceId,
parent_id: 0===this.depth ? this.commentData.id:this.parentId,
review_id: this.commentData.review_id,
author_id: this.$root.userData.id,
author_name: this.replyAuthorName,
author_mail: this.replyAuthorMail,
content: this.replyText,
},
recaptchaConfig=window.jetReviewPublicConfig.recaptchaConfig;
if(recaptchaConfig.enable){
window.grecaptcha.ready(function(){
grecaptcha.execute(recaptchaConfig.site_key,
{
action: 'submit_comment_reply'
}
).then(function(token){
JetReviews.captchaToken=token;
let modifyData=Object.assign({}, forSendingData, {
captcha_token: token
});
self.submitReplyHandler(modifyData);
});
});
return false;
}
this.submitReplyHandler(forSendingData);
},
submitReplyHandler: function(sendData=false){
let self=this;
if(! sendData){
console.warn('Empty review comment data for sending');
return false;
}
this.replySubmiting=true;
wp.apiFetch({
method: 'post',
path: window.jetReviewPublicConfig.submitReviewCommentRoute,
data: sendData,
}).then(function(response){
self.replySubmiting=false;
self.$root.userData.name=self.replyAuthorName;
self.$root.userData.mail=self.replyAuthorMail;
JetReviews.setLocalStorageData('guestName', self.replyAuthorName);
JetReviews.setLocalStorageData('guestMail', self.replyAuthorMail);
if(response.success){
self.replyFormVisible=false;
self.replyText='';
if(0===self.depth){
self.commentData.children.unshift(response.data);
}else{
self.parentComments.push(response.data);
}}else{
self.responseMessage=response.message;
}});
}}
});
Vue.component('points-field', {
template: '#jet-advanced-reviews-point-field-template',
props: {
before: {
type: [ Number, String, Boolean ],
default: false
},
rating: Number,
after: {
type: [ Number, String, Boolean ],
default: false
},
},
data: function(){
return ( {});
},
computed: {
isBeforeEmpty: function(){
return false===this.before||''===this.before;
},
isAfterEmpty: function(){
return false===this.after||''===this.after;
},
preparedRating: function(){
if(10 > this.rating){
return 10;
}
return this.rating;
},
ratingClass: function(){
let ratingClass='very-high-rating';
if(this.rating >=80&&this.rating <=100){
ratingClass='very-high-rating';
}
if(this.rating >=60&&this.rating <=79){
ratingClass='high-rating';
}
if(this.rating >=40&&this.rating <=59){
ratingClass='medium-rating';
}
if(this.rating >=22&&this.rating <=39){
ratingClass='low-rating';
}
if(this.rating >=0&&this.rating <=21){
ratingClass='very-low-rating';
}
return ratingClass;
}}
});
Vue.component('stars-field', {
template: '#jet-advanced-reviews-star-field-template',
props: {
before: {
type: [ Number, String, Boolean ],
default: false
},
rating: Number,
after: {
type: [ Number, String, Boolean ],
default: false
},
},
data: function(){
return ( {});
},
computed: {
isBeforeEmpty: function(){
return ! this.before||''===this.before;
},
isAfterEmpty: function(){
return ! this.after||''===this.after;
},
preparedRating: function(){
if(10 > this.rating){
return 10;
}
return this.rating;
},
emptyIcons: function(){
let icon=`<div class="jet-reviews-star">${ this.$root.refsHtml.emptyStarIcon }</div>`||'<div class="jet-reviews-star"><i class="far fa-star"></i></div>';
return icon.repeat(5);
},
filledIcons: function(){
let icon=`<div class="jet-reviews-star">${ this.$root.refsHtml.filledStarIcon }</div>`||'<div class="jet-reviews-star"><i class="fas fa-star"></i></div>';
return icon.repeat(5);
},
ratingClass: function(){
let ratingClass='very-high-rating';
if(this.rating >=80&&this.rating <=100){
ratingClass='very-high-rating';
}
if(this.rating >=60&&this.rating <=79){
ratingClass='high-rating';
}
if(this.rating >=40&&this.rating <=59){
ratingClass='medium-rating';
}
if(this.rating >=22&&this.rating <=39){
ratingClass='low-rating';
}
if(this.rating >=0&&this.rating <=21){
ratingClass='very-low-rating';
}
return ratingClass;
}},
});
Vue.component('html-textarea', {
template:'<div :class="classes" ref="textarea" contenteditable="true" tabindex="0" :data-placeholder="placeholder" :data-not-valid-label="notValidLabel" @input="updateHTML" @focus="focusHandler" @blur="blurHandler"></div>',
props: {
value: String,
isValid: {
type: Boolean,
default: true,
},
placeholder: {
type: String,
default: 'Input',
},
notValidLabel: {
type: String,
default: 'This field is required or not valid',
},
},
data: function(){
return ( {
isFocus: false,
isEmpty: true,
});
},
computed: {
classes: function(){
let classes=[
'jet-reviews-content-editable',
!this.isValid ? 'jet-reviews-content-editable--not-valid':false,
this.isFocus ? 'jet-reviews-content-editable--focus':false,
this.isPlaceholder ? 'jet-reviews-content-editable--placeholder':false,
];
return classes;
},
isPlaceholder: function(){
if(this.isFocus||! this.isEmpty){
return false;
}
return true;
}},
mounted: function (){
this.$el.innerHTML=this.value;
},
methods: {
updateHTML: function(e){
const html=e.target.innerHTML.trim();
if(html==='<br>'||html===''){
this.isEmpty=true;
this.$emit('input', '');
}else{
this.isEmpty=false;
this.$emit('input', html);
}},
focusHandler: function(e){
this.$emit('focus', e.target);
this.isFocus=true;
},
blurHandler: function(e){
this.$emit('blur', e.target);
this.isFocus=false;
}}
});
Vue.component('file-input', {
template: '#jet-reviews-widget-file-input-template',
props: {
allowedTypes: {
type: [ Array ],
default(){
return [ 'image/jpeg', 'image/png', 'image/gif' ];
}},
maxFileSize: {
type: [ Number ],
default: 5
},
uploadIcon: {
type: [ String ],
default: ''
},
uploadControlLabel: {
type: [ String ],
default: 'Upload your file here'
},
buttonLabel: {
type: [ String ],
default: 'Choose File'
},
maxFileSizeLabel: {
type: [ String ],
default: 'Maximum size'
},
},
data: function(){
return ( {
baseClass: 'jet-reviews-widget-file-input',
reviewMedia: [],
reviewMediaPreview: [],
messageText: '',
isDragOver: false,
});
},
computed: {
classesList(){
let classesList=[
this.baseClass,
this.isDragOver ? 'is-dragover':'',
];
return classesList;
},
maxSizeLabel(){
return `${ this.maxFileSizeLabel }: ${ this.maxFileSize }MB`;
},
isMessageVisible: function(){
return ''!==this.messageText;
},
maxSize: function(){
return this.maxFileSize * 1024 * 1024;
},
},
methods: {
triggerFileInput(){
this.$refs.fileInput.click();
},
handleFiles(event){
const files=Array.from(event.target.files);
this.reviewMedia=[];
this.reviewMediaPreview=[];
this.messageText='';
this.$emit('on-change', event);
this.$emit('on-send-status', true);
files.forEach(file=> {
if(! this.allowedTypes.includes(file.type) ){
this.$emit('on-send-status', false);
this.messageText='Not allowed file type';
return;
}
if(file.size > this.maxSize){
this.$emit('on-send-status', false);
this.messageText='Maximum file size exceeded';
return;
}
this.reviewMedia.push(file);
const reader=new FileReader();
reader.onload=event=> this.reviewMediaPreview.push(event.target.result);
reader.readAsDataURL(file);
});
this.$emit('on-file-change', this.reviewMedia);
},
onDragOver(){
this.isDragOver=true;
},
onDragLeave(){
this.isDragOver=false;
},
onFileDrop(event){
this.isDragOver=false;
const filesList=event?.dataTransfer?.files;
if(! filesList||filesList.length===0) return;
const files=Array.from(filesList);
this.reviewMedia=[];
this.reviewMediaPreview=[];
this.messageText='';
this.$emit('on-send-status', true);
files.forEach(file=> {
if(! this.allowedTypes.includes(file.type) ){
this.$emit('on-send-status', false);
this.messageText='Not allowed file type';
return;
};
if(file.size > this.maxSize){
this.$emit('on-send-status', false);
this.messageText='Maximum file size exceeded';
return;
};
this.reviewMedia.push(file);
const reader=new FileReader();
reader.onload=event=> this.reviewMediaPreview.push(event.target.result);
reader.readAsDataURL(file);
});
this.$emit('on-file-change', this.reviewMedia);
},
},
});
},
createJetReviewAdvancedInstance: function(instanceId, options){
if(JetReviews.initedInstance.includes(instanceId) ){
return;
}
JetReviews.initedInstance.push(instanceId);
let JetReviewAdvancedInstance=new Vue( {
el: '#' + instanceId,
data: {
uniqId: instanceId,
options: options,
reviewsLoaded: false,
getReviewsProcessing: false,
reviewsList: [],
reviewsPage: 1,
reviewsTotal: 0,
reviewsAverageRating: 0,
userData: options.userData,
sourceData: options.sourceData,
reviewTypeFields: options.reviewsFields,
formVisible: false,
isMounted: false,
refsHtml: {},
},
mounted: function(){
let self=this,
refsHtml={};
this.isMounted=true;
for(var ref in this.$refs){
Object.assign(refsHtml, { [ ref ]: this.$refs[ ref ].innerHTML });
}
this.refsHtml=refsHtml;
if(this.isUserGuest){
this.$set(this.userData, 'id', this.guestId);
this.$set(this.userData, 'name', this.guestName);
this.$set(this.userData, 'mail', this.guestMail);
let guestReviewedItems=JetReviews.getLocalStorageData(this.guestReviewedStorageName, []);
if(guestReviewedItems.includes(this.sourceData.sourceId) ){
this.$set(this.userData.canReview, 'allowed', false);
this.$set(this.userData.canReview, 'message', this.options.labels.alreadyReviewedMessage);
}}
if(this.options.reviewsListData){
this.reviewsList=this.options.reviewsListData.list;
this.reviewsTotal=+this.options.reviewsListData.total;
this.reviewsAverageRating=+this.options.reviewsListData.rating;
this.reviewsLoaded=true;
}else{
wp.apiFetch({
method: 'post',
path: window.jetReviewPublicConfig.getPublicReviewsRoute,
data: {
source: self.sourceData.source,
source_id: self.sourceData.sourceId,
page: self.reviewsPage - 1,
page_size: self.options.pageSize
},
}).then(function(response){
self.reviewsLoaded=true;
if(response.success&&response.data){
self.reviewsList=response.data.list;
self.reviewsTotal=+response.data.total;
self.reviewsAverageRating=+response.data.rating;
}else{
console.log('Error');
}});
}
JetReviews.eventBus.$on('addReview', function(payLoad){
if(self.options.uniqId!==payLoad.uniqId){
return;
}
self.formVisible=false;
let reviewData=payLoad.reviewData;
self.reviewsList.unshift(reviewData);
self.reviewsTotal +=1;
});
JetReviews.eventBus.$on('closeNewReviewForm', function(payLoad){
if(self.options.uniqId!==payLoad.uniqId){
return;
}
self.formVisible=false;
});
},
computed: {
instanceClass: function(){
let classes=[
'jet-reviews-advanced__instance',
];
if(this.isMounted){
classes.push('is-mounted');
}
return classes;
},
reviewsLength: function(){
return this.reviewsList.length;
},
reviewsListEmpty: function(){
return 0===this.reviewsList.length ? true:false;
},
preparedFields: function(){
let rawFields=this.reviewTypeFields,
preparedFields=[];
for(let fieldData of rawFields){
preparedFields.push({
field_label: fieldData.label,
field_value: +fieldData.max,
field_step: +fieldData.step,
field_max: +fieldData.max,
});
}
return preparedFields;
},
averageRating: function(){
let totalRating=0;
if(this.reviewsListEmpty){
return 0;
}
totalRating=this.reviewsList.reduce(function(sum, reviewItem){
return +reviewItem.rating + sum;
}, 0);
return Math.round(totalRating / this.reviewsList.length, 1);
},
averageValue: function(){
let summaryValue=0;
if(this.reviewsListEmpty){
return 0;
}
for(let reviewItem of this.reviewsList){
let ratingData=reviewItem.rating_data,
itemSummary=0;
for(let ratingItem of ratingData){
itemSummary +=+ratingItem.field_value
}
summaryValue +=Math.round(itemSummary / ratingData.length, 1)
}
return Math.round(summaryValue / this.reviewsList.length, 1);
},
averageMax: function(){
let totalMax=0,
fields=this.reviewTypeFields;
totalMax=fields.reduce(function(sum, field){
return +field.max + sum;
}, 0);
return Math.round(totalMax / fields.length, 1);
},
addReviewIcon: function(){
return this.refsHtml.newReviewButtonIcon||false;
},
isUserGuest: function(){
return this.userData.roles.includes('guest');
},
guestId: function(){
let guestId=JetReviews.getLocalStorageData('guestId', false);
if(! guestId){
let guestId=`guest_${ JetReviews.getUniqId() }`;
JetReviews.setLocalStorageData('guestId', guestId);
return guestId;
}
return guestId;
},
guestName: function(){
let guestName=JetReviews.getLocalStorageData('guestName', false);
if(! guestName){
JetReviews.setLocalStorageData('guestName', '');
return '';
}
return guestName;
},
guestMail: function(){
let guestMail=JetReviews.getLocalStorageData('guestMail', false);
if(! guestMail){
JetReviews.setLocalStorageData('guestMail', '');
return '';
}
return guestMail;
},
guestReviewedStorageName: function(){
return `reviewed${ JetReviews.capitalizeString(this.sourceData.source) }Items`;
},
guestRatedStorageName: function(){
return `rated${ JetReviews.capitalizeString(this.sourceData.source) }Items`;
},
guestNameFieldVisible: function(){
return this.isUserGuest&&''===this.userData.name;
},
guestMailFieldVisible: function(){
return this.isUserGuest&&''===this.userData.mail;
},
paginationVisible: function(){
return this.reviewsTotal > this.options.pageSize;
},
},
methods: {
formVisibleToggle: function(){
this.formVisible = !this.formVisible;
},
getLabelBySlug: function(slug=false){
if(! slug){
return false;
}
if(! window.jetReviewPublicConfig.labels.hasOwnProperty(slug) ){
return false;
}
return window.jetReviewPublicConfig.labels[ slug ];
},
changePageHandle: function(page){
this.reviewsPage=page;
this.getReviews();
},
getReviews: function(){
let self=this;
self.getReviewsProcessing=true;
wp.apiFetch({
method: 'post',
path: window.jetReviewPublicConfig.getPublicReviewsRoute,
data: {
source: self.sourceData.source,
source_id: self.sourceData.sourceId,
page: self.reviewsPage - 1,
page_size: self.options.pageSize,
},
}).then(function(response){
self.getReviewsProcessing=false;
self.scrollToInstance();
if(response.success&&response.data){
self.reviewsList=response.data.list;
self.reviewsTotal=+response.data.total;
self.reviewsAverageRating=+response.data.rating;
}else{
console.log('Error');
}});
},
scrollToInstance: function(){
let $instance=$(`#${ this.uniqId }`),
offsetTop=$instance.offset().top - 50;
window.scrollTo({
top: offsetTop,
behavior: 'smooth',
});
}}
});
},
getLocalStorageData: function(_key=false, _default=false){
try {
let jetReviewsData=JSON.parse(window.localStorage.getItem('jetReviewsData') );
if(_key){
if(jetReviewsData.hasOwnProperty(_key) ){
return jetReviewsData[ _key ];
}else{
return _default;
}}
return jetReviewsData;
} catch(e){
return _default;
}},
setLocalStorageData: function(key, data){
let jetReviewsData=this.getLocalStorageData()||{};
jetReviewsData[ key ]=data;
window.localStorage.setItem('jetReviewsData', JSON.stringify(jetReviewsData) );
},
getUniqId: function(){
return Math.random().toString(36).substr(2, 9);
},
capitalizeString: function(string=''){
if(typeof string!=='string'){
return ''
}
return string.charAt(0).toUpperCase() + string.slice(1);
},
placeCaretAtEnd: function(el){
el.focus();
if('undefined'!==typeof window.getSelection&&'undefined'!==typeof document.createRange){
let range=document.createRange();
range.selectNodeContents(el);
range.collapse(false);
let selection=window.getSelection();
selection.removeAllRanges();
selection.addRange(range);
}else if('undefined'!==typeof document.body.createTextRange){
let textRange=document.body.createTextRange();
textRange.moveToElementText(el);
textRange.collapse(false);
textRange.select();
}},
checkValidEmail: function(email){
var reg=/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return reg.test(email);
},
};
window.JetReviews=JetReviews;
JetReviews.init();
}(jQuery, window.jetReviewPublicConfig) );
(function($, elementorFrontend, publicConfig){
'use strict';
let JetReviewsElementor={
init: function(){
var widgets={
'jet-reviews.default':JetReviewsElementor.widgetJetReviewsSimple,
'jet-reviews-advanced.default':JetReviewsElementor.widgetJetReviewsAdvanced,
};
$.each(widgets, function(widget, callback){
elementorFrontend.hooks.addAction('frontend/element_ready/' + widget, callback);
});
},
widgetJetReviewsSimple: function($scope){
var $target=$scope.find('.jet-review'),
settings=$target.data('settings'),
$form=$('.jet-review__form', $target),
$submitButton=$('.jet-review__form-submit', $target),
$removeButton=$('.jet-review__item-remove', $target),
$message=$('.jet-review__form-message', $target),
$rangeControl=$('.jet-review__form-field.type-range input', $target),
ajaxRequest=null;
$rangeControl.on('input', function(event){
var $this=$(this),
$parent=$this.closest('.jet-review__form-field'),
$currentValue=$('.current-value', $parent),
value=$this.val();
$currentValue.html(value);
});
$submitButton.on('click.widgetJetReviews', function(){
addReviewHandle();
return false;
});
$removeButton.on('click.widgetJetReviews', function(){
var $this=$(this);
removeReviewHandle($this);
return false;
});
function addReviewHandle(){
var now=new Date(),
reviewTime=now.getTime(),
reviewDate=new Date(reviewTime).toLocaleString(),
sendData={
'post_id': settings['post_id'],
'review_time': reviewTime,
'review_date': reviewDate
},
serializeArray=$form.serializeObject();
sendData=jQuery.extend(sendData, serializeArray);
ajaxRequest=jQuery.ajax({
type: 'POST',
url: window.jetReviewPublicConfig.ajax_url,
data: {
'action': 'jet_reviews_add_meta_review',
'data': sendData
},
beforeSend: function(jqXHR, ajaxSettings){
if(null!==ajaxRequest){
ajaxRequest.abort();
}
$submitButton.addClass('load-state');
},
error: function(jqXHR, ajaxSettings){
},
success: function(data, textStatus, jqXHR){
var responseType=data['type'],
message=data.message||'';
if('error'===responseType){
$submitButton.removeClass('load-state');
$message.addClass('visible-state');
$('span', $message).html(message);
}
if('success'===responseType){
location.reload();
}}
});
};
function removeReviewHandle($removeButton){
var $reviewItem=$removeButton.closest('.jet-review__item'),
reviewUserId=$reviewItem.data('user-id'),
sendData={
'post_id': settings['post_id'],
'user_id': reviewUserId
};
ajaxRequest=jQuery.ajax({
type: 'POST',
url: window.jetReviewPublicConfig.ajax_url,
data: {
'action': 'jet_reviews_remove_review',
'data': sendData
},
beforeSend: function(jqXHR, ajaxSettings){
if(null!==ajaxRequest){
ajaxRequest.abort();
}
$removeButton.addClass('load-state');
},
error: function(jqXHR, ajaxSettings){
},
success: function(data, textStatus, jqXHR){
var successType=data.type,
message=data.message||'';
if('error'==successType){
}
if('success'==successType){
location.reload();
}}
});
};},
widgetJetReviewsAdvanced: function($scope){
let $target=$scope.find('.jet-reviews-advanced'),
instanceId=$target.attr('id'),
uniqid=$target.data('uniqid')||false,
options=window['jetReviewsWidget' + uniqid]||{};
if(! $target[0]||! uniqid){
return;
}
window.JetReviews.createJetReviewAdvancedInstance(instanceId, options);
},
}
$(window).on('elementor/frontend/init', JetReviewsElementor.init);
$.fn.serializeObject=function(){
var self=this,
json={},
push_counters={},
patterns={
"validate": /^[a-zA-Z][a-zA-Z0-9_-]*(?:\[(?:\d*|[a-zA-Z0-9_-]+)\])*$/,
"key":      /[a-zA-Z0-9_-]+|(?=\[\])/g,
"push":     /^$/,
"fixed":    /^\d+$/,
"named":    /^[a-zA-Z0-9_-]+$/
};
this.build=function(base, key, value){
base[key]=value;
return base;
};
this.push_counter=function(key){
if(push_counters[key]===undefined){
push_counters[key]=0;
}
return push_counters[key]++;
};
$.each($(this).serializeArray(), function(){
if(!patterns.validate.test(this.name)){
return;
}
var k,
keys=this.name.match(patterns.key),
merge=this.value,
reverse_key=this.name;
while((k=keys.pop())!==undefined){
reverse_key=reverse_key.replace(new RegExp("\\[" + k + "\\]$"), '');
if(k.match(patterns.push)){
merge=self.build([], self.push_counter(reverse_key), merge);
}
else if(k.match(patterns.fixed)){
merge=self.build([], k, merge);
}
else if(k.match(patterns.named)){
merge=self.build({}, k, merge);
}}
json=$.extend(true, json, merge);
});
return json;
};}(jQuery, window.elementorFrontend, window.jetReviewPublicConfig) );
(function($, elementor){
'use strict';
var JetTricks={
init: function(){
elementor.hooks.addAction('frontend/element_ready/section', JetTricks.elementorSection);
elementor.hooks.addAction('frontend/element_ready/section', JetTricks.elementorColumn);
elementor.hooks.addAction('frontend/element_ready/container', JetTricks.elementorSection);
elementor.hooks.addAction('frontend/element_ready/container', JetTricks.elementorColumn);
elementor.hooks.addAction('frontend/element_ready/column', JetTricks.elementorColumn);
elementor.hooks.addAction('frontend/element_ready/widget', JetTricks.elementorWidget);
var widgets={
'jet-view-more.default':JetTricks.widgetViewMore,
'jet-unfold.default':JetTricks.widgetUnfold,
'jet-hotspots.default':JetTricks.widgetHotspots
};
$.each(widgets, function(widget, callback){
elementor.hooks.addAction('frontend/element_ready/' + widget, callback);
});
window.elementorFrontend.elements.$window.on('elementor/nested-tabs/activate',
(event, content)=> {
const $content=$(content);
var $button=$content.find('.jet-unfold__button');
$button.off('click.jetUnfold');
JetTricks.initWidgetsHandlers($content);
JetTricks.elementorSection($content);
}
);
var loopCarouselTypes=[
'loop-carousel.post',
'loop-carousel.product',
'loop-carousel.post_taxonomy',
'loop-carousel.product_taxonomy'
];
loopCarouselTypes.forEach(function(carouselType){
elementorFrontend.hooks.addAction('frontend/element_ready/' + carouselType, function($scope, $){
$(window).on('load', function(){
var loopCarousel=$scope.find('.swiper'),
swiperInstance=loopCarousel.data('swiper'),
$button=$scope.find('.jet-unfold__button');
if(swiperInstance&&$button){
$button.off('click.jetUnfold');
JetTricks.initLoopCarouselHandlers($scope);
swiperInstance.on('slideChange', function(){
$button.off('click.jetUnfold');
JetTricks.initLoopCarouselHandlers($scope);
});
}});
});
});
},
initLoopCarouselHandlers: function($selector){
$selector.find('.elementor-widget-jet-unfold').each(function(){
var $this=$(this),
elementType=$this.data('element_type');
if(!elementType){
return;
}
if('widget'===elementType){
elementType=$this.data('widget_type');
window.elementorFrontend.hooks.doAction('frontend/element_ready/widget', $this, $);
}
window.elementorFrontend.hooks.doAction('frontend/element_ready/global', $this, $);
window.elementorFrontend.hooks.doAction('frontend/element_ready/' + elementType, $this, $);
});
},
initWidgetsHandlers: function($selector){
$selector.find('[data-element_type]').each(function(){
var excludeWidgets=[
'jet-woo-product-gallery-slider.default',
'accordion.default',
'jet-form-builder-form.default',
'nav-menu.default'
];
var $this=$(this),
elementType=$this.data('element_type');
if(!elementType){
return;
}
if('widget'===elementType){
elementType=$this.data('widget_type');
if(excludeWidgets.includes(elementType) ){
return;
}
window.elementorFrontend.hooks.doAction('frontend/element_ready/widget', $this, $);
}
window.elementorFrontend.hooks.doAction('frontend/element_ready/global', $this, $);
window.elementorFrontend.hooks.doAction('frontend/element_ready/' + elementType, $this, $);
});
},
elementorSection: function($scope){
var $target=$scope,
sectionId=$scope.data('id'),
editMode=Boolean(elementor.isEditMode()),
jetListing=$target.parents('.elementor-widget-jet-listing-grid').data('id'),
settings={};
if(window.JetTricksSettings&&window.JetTricksSettings.elements_data.sections.hasOwnProperty(sectionId) ){
settings=window.JetTricksSettings.elements_data.sections[ sectionId ];
}
if(editMode){
settings=JetTricks.sectionEditorSettings($scope);
}
if(! settings){
return false;
}
if(jQuery.isEmptyObject(settings) ){
return false;
}
if('false'===settings.particles||''===settings.particles_json){
return false;
}
if(jetListing&&$target.parent().data('elementor-type')==='jet-listing-items'){
sectionId +=jetListing + $target.parents('.jet-listing-grid__item').data('post-id');
}
var particlesId='jet-tricks-particles-instance-' + sectionId,
particlesJson=JSON.parse(settings.particles_json);
$scope.prepend('<div id="' + particlesId + '" class="jet-tricks-particles-section__instance"></div>');
if(typeof tsParticles!=='undefined'&&tsParticles.load&&tsParticles.version&&tsParticles.version.startsWith('3.')){
tsParticles.load({
id: particlesId,
options: particlesJson
});
}else if(typeof tsParticles!=='undefined'&&tsParticles.load){
tsParticles.load(particlesId, particlesJson);
}},
elementorColumn: function($scope){
var $target=$scope,
$parentSection=$scope.closest('.elementor-section'),
isLegacyModeActive = !!$target.find('> .elementor-column-wrap').length,
$window=$(window),
columnId=$target.data('id'),
editMode=Boolean(elementor.isEditMode()),
settings={},
stickyInstance=null,
stickyInstanceOptions={
topSpacing: 50,
bottomSpacing: 50,
containerSelector: isLegacyModeActive ? '.elementor-row':'.elementor-container, .e-con-inner',
innerWrapperSelector: isLegacyModeActive ? '.elementor-column-wrap':'.elementor-widget-wrap',
},
$observerTarget=$target.find('.elementor-element');
if(! editMode){
settings=$target.data('jet-settings');
if($target.hasClass('jet-sticky-column') ){
if(-1!==settings['stickyOn'].indexOf(elementorFrontend.getCurrentDeviceMode()) ){
$target.each(function(){
var $this=$(this),
elementType=$this.data('element_type');
if(settings['behavior']==='fixed'){
initFixedSticky($this, settings);
}else if(elementType!=='container'&&elementType!=='section'){
initSidebarSticky($this, settings, stickyInstanceOptions);
}else if(settings['behavior']==='scroll_until_end'){
initScrollUntilEndSticky($this, settings);
}else{
initDefaultSticky($this, settings);
}});
}}
}
function initFixedSticky($element, settings){
var offsetTop=parseInt(settings['topSpacing'])||0;
var bottomSpacing=parseInt(settings['bottomSpacing'])||0;
var $window=$(window);
var elementId=$element.data('id');
var originalOffsetTop=$element.offset().top;
var originalHeight=$element.outerHeight();
var $allStickyElements=$('.jet-sticky-column').filter(function(){
var $this=$(this);
var elementSettings=$this.data('jet-settings');
return elementSettings&&elementSettings.stickyOn.indexOf(elementorFrontend.getCurrentDeviceMode())!==-1;
});
var currentIndex=$allStickyElements.index($element);
var $nextSticky=currentIndex + 1 < $allStickyElements.length ? $allStickyElements.eq(currentIndex + 1):null;
var $stopper=null;
if($nextSticky){
$stopper=$nextSticky.closest('.elementor-top-section, .e-parent');
if(!$stopper.length){
$stopper=$nextSticky;
}}
const $placeholder=$('<div></div>')
.addClass('jet-sticky-placeholder')
.css({
display: 'none',
height: originalHeight,
width: $element.outerWidth(),
visibility: 'hidden'
});
$element.before($placeholder);
function enableSticky(){
$placeholder.show();
$element.addClass('jet-sticky-container--stuck');
var stopperTop=$stopper?.offset()?.top;
var stopPoint=stopperTop ? (stopperTop - $element.outerHeight() - offsetTop - bottomSpacing):null;
var diff=0;
if(stopPoint&&stopPoint < $window.scrollTop()){
diff=(stopPoint - $window.scrollTop());
}
$element.css({
position: 'fixed',
top: diff + 'px',
transform: `translateY(${offsetTop}px)`,
left: $placeholder.offset().left + 'px',
width: $placeholder.outerWidth() + 'px'
});
}
function disableSticky(){
$placeholder.hide();
$element.removeClass('jet-sticky-container--stuck');
$element.css({
position: '',
top: '',
transform: '',
left: '',
width: ''
});
}
function onScroll(){
var scrollTop=$window.scrollTop();
if(scrollTop >=originalOffsetTop){
enableSticky();
}else{
disableSticky();
}}
function onResize(){
originalOffsetTop=$placeholder.offset().top;
originalHeight=$element.outerHeight();
$placeholder.css({
height: originalHeight,
width: $element.outerWidth()
});
onScroll();
}
let ticking=false;
$window.on('scroll.jetStickyHeader-' + elementId, function(){
if(!ticking){
requestAnimationFrame(function(){
onScroll();
ticking=false;
});
ticking=true;
}});
$window.on('resize.jetStickyHeader-' + elementId, JetTricksTools.debounce(100, onResize));
onScroll();
$window.on('resize.jetStickyHeader-' + elementId, JetTricksTools.debounce(100, function(){
if(-1===settings['stickyOn'].indexOf(elementorFrontend.getCurrentDeviceMode())){
cleanupSticky($element, $placeholder, elementId);
}}));
}
function cleanupSticky($element, $placeholder, elementId){
$placeholder.remove();
$element.css({
position: '',
top: '',
transform: '',
left: '',
width: '',
zIndex: '',
transition: '',
willChange: ''
});
$element.removeClass('jet-sticky-container--stuck');
$window.off('scroll.jetStickyHeader-' + elementId);
$window.off('resize.jetStickyHeader-' + elementId);
}
function initSidebarSticky($element, settings, options){
options.topSpacing=settings['topSpacing'];
options.bottomSpacing=settings['bottomSpacing'];
imagesLoaded($parentSection, function(){
$target.data('stickyColumnInit', true);
stickyInstance=new StickySidebar($target[0], options);
});
var targetMutation=$target[0],
config={ attributes: true, childList: true, subtree: true };
var observer=new MutationObserver(function(mutations){
for(var mutation of mutations){
if('attributes'===mutation.type&&mutation.attributeName!=='style'){
$target[0].style.height='auto';
}}
});
observer.observe(targetMutation, config);
$window.on('resize.JetTricksStickyColumn orientationchange.JetTricksStickyColumn',
JetTricksTools.debounce(50, resizeDebounce) );
var observer=new MutationObserver(function(mutations){
if(stickyInstance){
mutations.forEach(function(mutation){
if(mutation.attributeName==='class'){
setTimeout(function(){
stickyInstance.destroy();
stickyInstance=new StickySidebar($target[0], options);
}, 100);
}});
}});
$observerTarget.each(function(){
observer.observe($(this)[0], {
attributes: true
});
});
}
function initScrollUntilEndSticky($element, settings){
const stickyHeight=$element.outerHeight();
const stickyContentBottom=$element.offset().top + stickyHeight;
const stickyViewportOffset=$window.height() - stickyHeight - settings['bottomSpacing'];
$('body').addClass('jet-sticky-container');
$window.on('scroll.jetSticky', function (){
const scrollPosition=$window.scrollTop();
if(scrollPosition + $window.height() >=stickyContentBottom){
$element.css({
position: 'sticky',
top: stickyViewportOffset + 'px',
bottom: 'auto',
left: 'auto',
zIndex: settings['zIndex'],
});
}});
$observerTarget.on('destroy.jetSticky', function (){
$window.off('scroll.jetSticky');
$('body').removeClass('jet-sticky-container');
});
}
function initDefaultSticky($element, settings){
$('body').addClass('jet-sticky-container');
$element.addClass('jet-sticky-container-sticky');
$element.css({
'top': settings['topSpacing'],
'bottom': settings['bottomSpacing']
});
}
function resizeDebounce(){
var currentDeviceMode=elementorFrontend.getCurrentDeviceMode(),
availableDevices=settings['stickyOn']||[],
isInit=$target.data('stickyColumnInit');
if(-1!==availableDevices.indexOf(currentDeviceMode) ){
if(! isInit){
$target.data('stickyColumnInit', true);
stickyInstance=new StickySidebar($target[0], stickyInstanceOptions);
stickyInstance.updateSticky();
}}else{
$target.data('stickyColumnInit', false);
stickyInstance.destroy();
}}
},
elementorWidget: function($scope){
var parallaxInstance=null,
satelliteInstance=null,
tooltipInstance=null;
parallaxInstance=new jetWidgetParallax($scope);
parallaxInstance.init();
satelliteInstance=new jetWidgetSatellite($scope);
satelliteInstance.init();
tooltipInstance=new jetWidgetTooltip($scope);
tooltipInstance.init();
},
getElementorElementSettings: function($scope){
if(window.elementorFrontend&&window.elementorFrontend.isEditMode()&&$scope.hasClass('elementor-element-edit-mode') ){
return JetTricks.getEditorElementSettings($scope);
}
return $scope.data('settings')||{};},
getEditorElementSettings: function($scope){
var modelCID=$scope.data('model-cid'),
elementData;
if(! modelCID){
return {};}
if(! elementor.hasOwnProperty('config') ){
return {};}
if(! elementor.config.hasOwnProperty('elements') ){
return {};}
if(! elementor.config.elements.hasOwnProperty('data') ){
return {};}
elementData=elementor.config.elements.data[ modelCID ];
if(! elementData){
return {};}
return elementData.toJSON();
},
widgetViewMore: function($scope){
var $target=$scope.find('.jet-view-more'),
instance=null,
settings=$target.data('settings');
instance=new jetViewMore($target, settings);
instance.init();
},
widgetUnfold: function($scope){
var $target=$scope.find('.jet-unfold'),
$button=$('.jet-unfold__button', $target),
$mask=$('.jet-unfold__mask', $target),
$content=$('.jet-unfold__content', $target),
$contentInner=$('.jet-unfold__content-inner', $target),
$trigger=$('.jet-unfold__trigger', $target),
$separator=$('.jet-unfold__separator', $target),
settings=$.extend({}, $target.data('settings'), JetTricks.getElementorElementSettings($scope) ),
maskBreakpointsHeights=[],
prevBreakpoint='',
unfoldDuration=settings['unfoldDuration']||settings['unfold_duration'],
foldDuration=settings['foldDuration']||settings['fold_duration'],
unfoldEasing=settings['unfoldEasing']||settings['unfold_easing'],
foldEasing=settings['foldEasing']||settings['fold_easing'],
maskHeightAdv=20,
heightCalc='',
autoHide=settings['autoHide']||false,
autoHideTime=settings['autoHideTime']&&0!=settings['autoHideTime']['size'] ? settings['autoHideTime']['size']:5,
hideOutsideClick=settings['hideOutsideClick']||false,
heightControlType=settings['heightControlType']||'height',
wordCount=settings['wordCount']||20,
autoHideTrigger,
activeBreakpoints=elementor.config.responsive.activeBreakpoints,
initialLoaded=false;
function updateMaskGradientClass(){
if(settings.separatorType==='gradient'){
if($target.hasClass('jet-unfold-state')||$trigger.is(':hidden')){
$mask.removeClass('jet-unfold__mask-gradient');
}else{
$mask.addClass('jet-unfold__mask-gradient');
}}
}
function calculateHeightByWordCount(){
var text=$contentInner.text().trim();
if(!text){
return 0;
}
var words=text.split(/\s+/);
var wordsToShow=Math.min(getDeviceWordCount(), words.length);
var visibleText=words.slice(0, wordsToShow).join(' ');
var $tempElement=$contentInner.clone();
$tempElement
.css({
position: 'absolute',
visibility: 'hidden',
height: 'auto',
overflow: 'visible'
})
.text(visibleText);
$contentInner.after($tempElement);
var height=$tempElement.outerHeight();
$tempElement.remove();
return height;
}
maskBreakpointsHeights['desktop']=[];
maskBreakpointsHeights['widescreen']=[];
maskBreakpointsHeights['desktop']['maskHeight']=(settings['mask_height']&&settings['mask_height']['size']&&''!=settings['mask_height']['size']) ? settings['mask_height']['size']:50;
prevBreakpoint='desktop';
Object.keys(activeBreakpoints).reverse().forEach(function(breakpointName){
if('widescreen'===breakpointName){
maskBreakpointsHeights['widescreen']['maskHeight']=(settings['mask_height_widescreen']&&settings['mask_height_widescreen']['size']&&''!=settings['mask_height_widescreen']['size']) ? settings['mask_height_widescreen']['size']:maskBreakpointsHeights['desktop']['maskHeight'];
}else{
maskBreakpointsHeights[breakpointName]=[];
var breakpointSetting=settings['mask_height_' + breakpointName];
maskBreakpointsHeights[breakpointName]['maskHeight']=(breakpointSetting&&breakpointSetting['size']&&''!=breakpointSetting['size']) ? breakpointSetting['size']:maskBreakpointsHeights[prevBreakpoint]['maskHeight'];
prevBreakpoint=breakpointName;
}});
onLoaded();
if(typeof ResizeObserver!=='undefined'){
new ResizeObserver(function(entries){
if($target.hasClass('jet-unfold-state') ){
$mask.css({
'height': $contentInner.outerHeight()
});
}}).observe($contentInner[0]);
}
if('true'===hideOutsideClick){
$(window).on('mouseup', function(event){
let container=$target;
if(!container.is(event.target)&&0===container.has(event.target).length&&$target.hasClass('jet-unfold-state') ){
$button.trigger('click');
}})
}
$target.one('transitionend webkitTransitionEnd oTransitionEnd', function(){
if(!initialLoaded){
onLoaded();
initialLoaded=true;
}});
function onLoaded(){
initialLoaded=true;
var deviceHeight=getDeviceHeight();
heightCalc=+deviceHeight + maskHeightAdv;
if(heightCalc < $contentInner.height()){
if(! $target.hasClass('jet-unfold-state') ){
$separator.css({
'opacity': '1'
});
}
if(! $target.hasClass('jet-unfold-state') ){
$mask.css({
'height': deviceHeight
});
}else{
$mask.css({
'height': $contentInner.outerHeight()
});
}
$trigger.css('display', 'flex');
updateMaskGradientClass();
}else{
$trigger.hide();
$mask.css({
'height': '100%'
});
$content.css({
'max-height': 'none'
});
$separator.css({
'opacity': '0'
});
updateMaskGradientClass();
}}
$(window).on('resize.jetWidgetUnfold orientationchange.jetWidgetUnfold', JetTricksTools.debounce(50, function(){
initialLoaded=false;
onLoaded();
}) );
$button.keypress(function(e){
if(e.which==13){
$button.click();
return false;
}});
$button.on('click.jetUnfold', function(e){
var $this=$(this),
$buttonText=$('.jet-unfold__button-text', $this),
unfoldText=$this.data('unfold-text'),
foldText=$this.data('fold-text'),
$buttonIcon=$('.jet-unfold__button-icon', $this),
unfoldIcon=$this.data('unfold-icon'),
foldIcon=$this.data('fold-icon'),
contentHeight=$contentInner.outerHeight(),
deviceHeight=getDeviceHeight();
e.preventDefault();
if(! $target.hasClass('jet-unfold-state') ){
$target.addClass('jet-unfold-state');
$separator.css({
'opacity': '0'
});
$buttonIcon.html(foldIcon);
$buttonText.html(foldText);
setTimeout(function(){
contentHeight=$contentInner.outerHeight();
anime( {
targets: $mask[0],
height: contentHeight,
duration: unfoldDuration['size'],
easing: unfoldEasing,
complete: function(anim){
$(document).trigger('jet-engine/listing/recalculate-masonry');
}});
}, 0);
if('true'===autoHide){
autoHideTrigger=setTimeout(function(){
$button.trigger('click');
}, autoHideTime * 1000);
}}else{
clearTimeout(autoHideTrigger);
$target.removeClass('jet-unfold-state');
$separator.css({
'opacity': '1'
});
$buttonIcon.html(unfoldIcon);
$buttonText.html(unfoldText);
anime( {
targets: $mask[0],
height: deviceHeight,
duration: foldDuration['size'],
easing: foldEasing,
complete: function(anim){
if('true'===settings['foldScrolling']){
$('html, body').animate({
scrollTop: $target.offset().top - settings['foldScrollOffset']['size']
}, 'slow');
}
$(document).trigger('jet-engine/listing/recalculate-masonry');
}});
}
updateMaskGradientClass();
});
function getDeviceHeight(){
if(heightControlType==='word_count'){
return calculateHeightByWordCount();
}
let device=elementorFrontend.getCurrentDeviceMode();
let heightSettings;
switch(device){
case 'mobile':
heightSettings=settings.mask_height_mobile;
break;
case 'tablet':
heightSettings=settings.mask_height_tablet;
break;
default:
heightSettings=settings.mask_height;
}
if(! heightSettings||! heightSettings.size||! heightSettings.unit){
heightSettings=settings.mask_height;
}
switch(heightSettings.unit){
case 'vh':
return(window.innerHeight * heightSettings.size) / 100;
case '%':
let parentHeight=$contentInner.parent().height();
return(parentHeight * heightSettings.size) / 100;
default:
return heightSettings.size;
}}
function getDeviceWordCount(){
let device=elementorFrontend.getCurrentDeviceMode();
let value;
switch(device){
case 'mobile':
value=settings.word_count_mobile;
break;
case 'tablet':
value=settings.word_count_tablet;
break;
default:
value=settings.word_count;
}
if(value!==null&&value!==undefined){
return parseInt(value, 10);
}
return 20;
}},
widgetHotspots: function($scope){
var $target=$scope.find('.jet-hotspots'),
$hotspots=$('.jet-hotspots__item', $target),
settings=$target.data('settings'),
editMode=Boolean(elementor.isEditMode()),
itemActiveClass='jet-hotspots__item--active';
$target.imagesLoaded().progress(function(){
$target.addClass('image-loaded');
});
$hotspots.each(function(index){
var $this=$(this),
horizontal=$this.data('horizontal-position'),
vertical=$this.data('vertical-position'),
tooltipWidth=$this.data('tooltip-width')||null,
showOnInit=$this.data('show-on-init'),
itemSelector=$this[0],
options={};
$this.css({
'left': horizontal + '%',
'top': vertical + '%'
});
if(itemSelector._tippy){
itemSelector._tippy.destroy();
}
options={
content: $this.data('tippy-content'),
arrow: settings['tooltipArrow'] ? true:false,
placement: settings['tooltipPlacement'],
trigger: settings['tooltipTrigger'],
appendTo: editMode ? document.body:$target[0],
hideOnClick: 'manual'!==settings['tooltipTrigger'],
maxWidth: 'none',
offset: [0, settings['tooltipDistance']['size']],
allowHTML: true,
interactive: settings['tooltipInteractive'] ? true:false,
onShow(instance){
$(itemSelector).addClass(itemActiveClass);
if(tooltipWidth){
instance.popper.querySelector('.tippy-box').style.width=tooltipWidth;
}},
onHidden(instance){
$(itemSelector).removeClass(itemActiveClass);
}}
if('manual'!=settings['tooltipTrigger']){
options['duration']=[ settings['tooltipShowDuration']['size'], settings['tooltipHideDuration']['size'] ];
options['animation']=settings['tooltipAnimation'];
options['delay']=settings['tooltipDelay'];
}
tippy([ itemSelector ], options);
if('manual'===settings['tooltipTrigger']&&itemSelector._tippy){
itemSelector._tippy.show();
}
if(( showOnInit==='yes'||settings['tooltipShowOnInit'])&&itemSelector._tippy){
itemSelector._tippy.show();
}});
},
columnEditorSettings: function(columnId){
var editorElements=null,
columnData={};
if(! window.elementor.hasOwnProperty('elements') ){
return false;
}
editorElements=window.elementor.elements;
if(! editorElements.models){
return false;
}
$.each(editorElements.models, function(index, obj){
$.each(obj.attributes.elements.models, function(index, obj){
if(columnId==obj.id){
columnData=obj.attributes.settings.attributes;
}});
});
return {
'sticky': columnData['jet_tricks_column_sticky']||false,
'topSpacing': columnData['jet_tricks_top_spacing']||50,
'bottomSpacing': columnData['jet_tricks_bottom_spacing']||50,
'stickyOn': columnData['jet_tricks_column_sticky_on']||[ 'desktop', 'tablet', 'mobile']
}},
sectionEditorSettings: function($scope){
var editorElements=null,
sectionData={};
if(! window.elementor.hasOwnProperty('elements') ){
return false;
}
sectionData=JetTricks.getElementorElementSettings($scope);
return {
'particles': sectionData['section_jet_tricks_particles']||'false',
'particles_json': sectionData['section_jet_tricks_particles_json']||'',
}}
};
$(window).on('elementor/frontend/init', JetTricks.init);
var JetTricksTools={
debounce: function(threshold, callback){
var timeout;
return function debounced($event){
function delayed(){
callback.call(this, $event);
timeout=null;
}
if(timeout){
clearTimeout(timeout);
}
timeout=setTimeout(delayed, threshold);
};},
widgetEditorSettings: function(widgetId){
var editorElements=null,
widgetData={};
if(!window.elementor.hasOwnProperty('elements')||!window.elementor.elements.models){
return false;
}
editorElements=window.elementor.elements;
function findWidgetById(models, widgetId){
let foundData=null;
$.each(models, function(index, obj){
if(obj.id===widgetId){
foundData=obj.attributes.settings.attributes;
return false;
}
if(obj.attributes.elements&&obj.attributes.elements.models){
foundData=findWidgetById(obj.attributes.elements.models, widgetId);
if(foundData){
return false;
}}
});
return foundData;
}
widgetData=findWidgetById(editorElements.models, widgetId)||{};
return {
'speed': widgetData['jet_tricks_widget_parallax_speed']||{ 'size': 50, 'unit': '%'},
'parallax': widgetData['jet_tricks_widget_parallax']||'false',
'invert': widgetData['jet_tricks_widget_parallax_invert']||'false',
'stickyOn': widgetData['jet_tricks_widget_parallax_on']||[ 'desktop', 'tablet', 'mobile'],
'satellite': widgetData['jet_tricks_widget_satellite']||'false',
'satelliteType': widgetData['jet_tricks_widget_satellite_type']||'text',
'satellitePosition': widgetData['jet_tricks_widget_satellite_position']||'top-center',
'satelliteText': widgetData['jet_tricks_widget_satellite_text']||'Lorem Ipsum',
'satelliteIcon': widgetData['selected_jet_tricks_widget_satellite_icon']||'',
'satelliteImage': widgetData['jet_tricks_widget_satellite_image']||'',
'satelliteLink': widgetData['jet_tricks_widget_satellite_link']||'',
'tooltip': widgetData['jet_tricks_widget_tooltip']||'false',
'tooltipDescription': widgetData['jet_tricks_widget_tooltip_description']||'Lorem Ipsum',
'tooltipPlacement': widgetData['jet_tricks_widget_tooltip_placement']||'top',
'tooltipArrow': 'true'===widgetData['jet_tricks_widget_tooltip_arrow'] ? true:false,
'xOffset': widgetData['jet_tricks_widget_tooltip_x_offset']||0,
'yOffset': widgetData['jet_tricks_widget_tooltip_y_offset']||0,
'tooltipAnimation': widgetData['jet_tricks_widget_tooltip_animation']||'shift-toward',
'tooltipTrigger': widgetData['jet_tricks_widget_tooltip_trigger']||'mouseenter',
'customSelector': widgetData['jet_tricks_widget_tooltip_custom_selector']||'',
'zIndex': widgetData['jet_tricks_widget_tooltip_z_index']||'999',
'delay': widgetData['jet_tricks_widget_tooltip_delay']||'0',
'followCursor': widgetData['jet_tricks_widget_tooltip_follow_cursor']||'false'
}}
}
window.jetViewMore=function($selector, settings){
var self=this,
$window=$(window),
$button=$('.jet-view-more__button', $selector),
defaultSettings={
sections: {},
effect: 'move-up',
showall: false
},
settings=$.extend({}, defaultSettings, settings),
sections=settings['sections'],
sectionsData={},
editMode=Boolean(elementor.isEditMode()),
readLess=settings['read_less']||false,
readMoreLabel=settings['read_more_label'],
readLessLabel=settings['read_less_label'],
readMoreIcon=settings['read_more_icon'],
readLessIcon=settings['read_less_icon'],
hideAll=settings['hide_all']||false,
isOpened=false;
self.init=function(){
self.setSectionsData();
if(editMode){
return false;
}
function hideSection($section){
if(settings['hide_effect']&&settings['hide_effect']!=='none'){
$section.addClass('view-more-hiding');
$section.addClass('jet-tricks-' + settings['hide_effect'] + '-hide-effect');
(function($currentSection){
$currentSection.on('animationend', function animationEndHandler(){
$currentSection.off('animationend', animationEndHandler);
$currentSection.removeClass('view-more-hiding');
$currentSection.removeClass('jet-tricks-' + settings['hide_effect'] + '-hide-effect');
$currentSection.css('height', '');
$currentSection.removeClass('view-more-visible');
$currentSection.removeClass('jet-tricks-' + settings['effect'] + '-effect');
});
})($section);
}else{
$section.css('height', '');
$section.removeClass('view-more-visible');
$section.removeClass('jet-tricks-' + settings['effect'] + '-effect');
}}
function showAllSections(){
for(var section in sectionsData){
var $section=sectionsData[ section ]['selector'];
sectionsData[ section ]['visible']=true;
$section.css('height', $section[0].scrollHeight + 'px');
$section.addClass('view-more-visible');
$section.addClass('jet-tricks-' + settings['effect'] + '-effect');
}}
function hideAllSections(){
for(var section in sectionsData){
var $section=sectionsData[ section ]['selector'];
sectionsData[ section ]['visible']=false;
hideSection($section);
}}
function showNextSection(){
for(var section in sectionsData){
var $section=sectionsData[ section ]['selector'];
if(!sectionsData[ section ]['visible']){
sectionsData[ section ]['visible']=true;
$section.css('height', $section[0].scrollHeight + 'px');
$section.addClass('view-more-visible');
$section.addClass('jet-tricks-' + settings['effect'] + '-effect');
break;
}}
}
function hideNextSection(){
var sectionKeys=Object.keys(sectionsData).reverse();
for (var i=0; i < sectionKeys.length; i++){
var sectionKey=sectionKeys[i];
var $section=sectionsData[sectionKey]['selector'];
if(sectionsData[sectionKey]['visible']){
sectionsData[sectionKey]['visible']=false;
hideSection($section);
break;
}}
}
$button.on('click', function(){
if(readLess){
if(!isOpened){
if(!settings.showall){
showNextSection();
var allVisible=true;
for (var section in sectionsData){
if(!sectionsData[section]['visible']){
allVisible=false;
break;
}}
if(allVisible){
$button.find('.jet-view-more__label').text(readLessLabel);
if(readLessIcon&&readLessIcon.value){
$button.find('.jet-view-more__icon').html('<i class="' + readLessIcon.value + '"></i>');
}
$button.addClass('jet-view-more__button--read-less');
isOpened=true;
}}else{
showAllSections();
$button.find('.jet-view-more__label').text(readLessLabel);
if(readLessIcon&&readLessIcon.value){
$button.find('.jet-view-more__icon').html('<i class="' + readLessIcon.value + '"></i>');
}
$button.addClass('jet-view-more__button--read-less');
isOpened=true;
}}else{
if(hideAll){
hideAllSections();
$button.find('.jet-view-more__label').text(readMoreLabel);
if(readMoreIcon&&readMoreIcon.value){
$button.find('.jet-view-more__icon').html('<i class="' + readMoreIcon.value + '"></i>');
}
$button.removeClass('jet-view-more__button--read-less');
isOpened=false;
}else{
hideNextSection();
var allHidden=true;
for (var section in sectionsData){
if(sectionsData[section]['visible']){
allHidden=false;
break;
}}
if(allHidden){
$button.find('.jet-view-more__label').text(readMoreLabel);
if(readMoreIcon&&readMoreIcon.value){
$button.find('.jet-view-more__icon').html('<i class="' + readMoreIcon.value + '"></i>');
}
$button.removeClass('jet-view-more__button--read-less');
isOpened=false;
}}
}}else{
if(!settings.showall){
showNextSection();
}else{
showAllSections();
}
var allVisible=true;
for (var section in sectionsData){
if(!sectionsData[section]['visible']){
allVisible=false;
break;
}}
if(allVisible){
$button.css({ 'display': 'none' });
}}
});
$button.keydown(function(e){
var $which=e.which||e.keyCode;
if($which==13||$which==32){
e.preventDefault();
if(readLess){
$button.trigger('click');
}else{
if(!settings.showall){
showNextSection();
}else{
showAllSections();
}
var allVisible=true;
for (var section in sectionsData){
if(!sectionsData[section]['visible']){
allVisible=false;
break;
}}
if(allVisible){
$button.css({ 'display': 'none' });
}}
}});
};
self.setSectionsData=function(){
for(var section in sections){
var $selector=$('#' + sections[ section ]);
if(! editMode){
$selector.addClass('jet-view-more-section');
}else{
$selector.addClass('jet-view-more-section-edit-mode');
}
sectionsData[ section ]={
'section_id': sections[ section ],
'selector': $selector,
'visible': false,
}}
};};
window.jetWidgetParallax=function($scope){
var self=this,
$target=$scope,
$section=$scope.closest('.elementor-top-section'),
widgetId=$scope.data('id'),
settings={},
editMode=Boolean(elementor.isEditMode()),
$window=$(window),
isSafari     = !!navigator.userAgent.match(/Version\/[\d\.]+.*Safari/),
platform=navigator.platform,
safariClass=isSafari ? 'is-safari':'',
macClass='MacIntel'==platform ? ' is-mac':'';
self.init=function(){
$scope.addClass(macClass);
if(! editMode){
settings=$scope.data('jet-tricks-settings');
}else{
settings=JetTricksTools.widgetEditorSettings(widgetId);
}
if(! settings){
return false;
}
if('undefined'===typeof settings){
return false;
}
if('false'===settings['parallax']||'undefined'===typeof settings['parallax']){
return false;
}
$window.on('scroll.jetWidgetParallax resize.jetWidgetParallax', self.scrollHandler).trigger('resize.jetWidgetParallax');
};
self.scrollHandler=function(event){
var speed=+settings['speed']['size'] * 0.01,
invert='true'==settings['invert'] ? -1:1,
winHeight=$window.height(),
winScrollTop=$window.scrollTop(),
offsetTop=$scope.offset().top,
thisHeight=$scope.outerHeight(),
sectionHeight=$section.outerHeight(),
positionDelta=winScrollTop - offsetTop +(winHeight / 2),
abs=positionDelta > 0 ? 1:-1,
posY=abs * Math.pow(Math.abs(positionDelta), 0.85),
availableDevices=settings['stickyOn']||[],
currentDeviceMode=elementorFrontend.getCurrentDeviceMode();
posY=invert * Math.ceil(speed * posY);
if(-1!==availableDevices.indexOf(currentDeviceMode) ){
$target.css({
'transform': 'translateY(' + posY + 'px)'
});
}else{
$target.css({
'transform': 'translateY(0)'
});
}};};
window.jetWidgetSatellite=function($scope){
var self=this,
widgetId=$scope.data('id'),
settings={},
editMode=Boolean(elementor.isEditMode());
self.init=function(){
if(! editMode){
settings=$scope.data('jet-tricks-settings');
}else{
settings=JetTricksTools.widgetEditorSettings(widgetId);
}
if(! settings||typeof settings!=='object'){
return false;
}
if('false'===settings['satellite']||'undefined'===typeof settings['satellite']){
return false;
}
$scope.addClass('jet-satellite-widget');
$('.jet-tricks-satellite', $scope).addClass('jet-tricks-satellite--' + settings['satellitePosition']);
if(editMode&&$scope.find('.jet-tricks-satellite').length===0){
var html='';
var pos=settings['satellitePosition']||'top-center';
var link=settings['satelliteLink']||{};
var linkStart='', linkEnd='';
if(link.url){
linkStart='<a class="jet-tricks-satellite__link">';
linkEnd='</a>';
}
if(settings['satelliteType']==='text'&&settings['satelliteText']){
html='<div class="jet-tricks-satellite jet-tricks-satellite--' + pos + '"><div class="jet-tricks-satellite__inner"><div class="jet-tricks-satellite__text">' + linkStart + '<span>' + settings['satelliteText'] + '</span>' + linkEnd + '</div></div></div>';
}else if(settings['satelliteType']==='icon'&&settings['satelliteIcon']&&settings['satelliteIcon'].value){
html='<div class="jet-tricks-satellite jet-tricks-satellite--' + pos + '"><div class="jet-tricks-satellite__inner"><div class="jet-tricks-satellite__icon">' + linkStart + '<div class="jet-tricks-satellite__icon-instance jet-tricks-icon"><i class="' + settings['satelliteIcon'].value + '"></i></div>' + linkEnd + '</div></div></div>';
}else if(settings['satelliteType']==='image'&&settings['satelliteImage']&&settings['satelliteImage'].url){
html='<div class="jet-tricks-satellite jet-tricks-satellite--' + pos + '"><div class="jet-tricks-satellite__inner"><div class="jet-tricks-satellite__image">' + linkStart + '<img class="jet-tricks-satellite__image-instance" src="' + settings['satelliteImage'].url + '" alt="">' + linkEnd + '</div></div></div>';
}
if(html){
$scope.prepend(html);
}}
};};
window.jetWidgetTooltip=function($scope){
var self=this,
widgetId=$scope.data('id'),
widgetSelector=$scope[0],
tooltipSelector=widgetSelector,
settings={},
editMode=Boolean(elementor.isEditMode()),
delay,
tooltipEvent=editMode ? 'click':'mouseenter';
self.init=function(){
if(! editMode){
settings=$scope.data('jet-tricks-settings');
}else{
settings=JetTricksTools.widgetEditorSettings(widgetId);
}
if(widgetSelector._tippy){
widgetSelector._tippy.destroy();
}
if(! settings){
return false;
}
if('undefined'===typeof settings){
return false;
}
if('false'===settings['tooltip']||'undefined'===typeof settings['tooltip']||''===settings['tooltipDescription']){
return false;
}
$scope.addClass('jet-tooltip-widget');
if(settings['customSelector']){
tooltipSelector=$('.' + settings['customSelector'], $scope)[0];
}
if(editMode&&! $('#jet-tricks-tooltip-content-' + widgetId)[0]){
var template=$('<div>', {
id: 'jet-tricks-tooltip-content-' + widgetId,
class: 'jet-tooltip-widget__content'
});
template.html(settings['tooltipDescription']);
$scope.append(template);
}
tippy(
[ tooltipSelector ],
{
content: $scope.find('.jet-tooltip-widget__content')[0].innerHTML,
allowHTML: true,
appendTo: editMode ? document.body:widgetSelector,
arrow: settings['tooltipArrow'] ? true:false,
placement: settings['tooltipPlacement'],
offset: [ settings['xOffset'], settings['yOffset'] ],
animation: settings['tooltipAnimation'],
trigger: settings['tooltipTrigger'],
interactive: settings['followCursor']==='false'||settings['followCursor']==='initial',
zIndex: settings['zIndex'],
maxWidth: 'none',
delay: settings['delay']['size'] ? settings['delay']['size']:0,
followCursor: settings['followCursor']==='false' ? false:(settings['followCursor']==='true' ? true:settings['followCursor']),
onCreate: function (instance){
if(editMode){
var dataId=tooltipSelector.getAttribute('data-id');
if(dataId){
instance.popper.classList.add('tippy-' + dataId);
}}
}}
);
if(editMode&&widgetSelector._tippy){
widgetSelector._tippy.show();
}};};
}(jQuery, window.elementorFrontend) );