(function($){
var EWFCF7=function($form){
this.currentClass='ewfcf7__step_current';
this.completeClass='ewfcf7__step_completed';
this.inactiveClass='ewfcf7__step_inactive';
this.groupCurrentClass='ewfcf7-group-current';
this.groupHideClass='ewfcf7-group-hide';
this.transition=$form.data('transition');
this.current_step=$form.find('.ewfcf7-group-current').data('step');
this.next_step;
this.prev_step;
this.stepCount=$form.find('.ewfcf7__indicator').length;
this.animating=false;
this.events($form);
}
EWFCF7.prototype.toStep=function(next_step, next=false, prev=false, $form){
$form.find('.ewfcf7__indicator').removeClass(this.currentClass);
$form.find('.ewfcf7__indicator').removeClass(this.completeClass);
$form.find('.ewfcf7__indicator').removeClass(this.inactiveClass);
for(var i=next_step + 1; i < this.stepCount; i++){
$form.find('.ewfcf7__indicator:eq('+i+')').addClass(this.inactiveClass);
}
for(var i=next_step - 1; i >=0; i--){
$form.find('.ewfcf7__indicator:eq('+i+')').addClass(this.completeClass);
}
$form.find('.ewfcf7__indicator:eq('+next_step+')').addClass(this.currentClass);
if(this.transition=='none'){
var next_fs=$form.find('.ewfcf7-step-group:eq('+next_step+')');
var current_fs=$form.find('.ewfcf7-step-group:eq('+this.current_step+')');
$('.ewfcf7-step-group').removeClass(this.groupCurrentClass).addClass(this.groupHideClass);
current_fs.removeClass(this.groupCurrentClass).addClass(this.groupHideClass);
next_fs.removeClass(this.groupHideClass).addClass(this.groupCurrentClass);
this.current_step=next_step;
this.animating=false;
}
if(this.transition=='fade'){
this.toNextFadeIn(this.current_step, next_step, $form);
}
if(this.transition=='inoutback'){
if(next){
this.toNextInOut(this.current_step, next_step, $form);
}
if(prev){
this.toPrevInOut(this.current_step, next_step, $form);
}}
}
EWFCF7.prototype.toNext=function($form){
if(this.animating) return false;
this.animating=true;
if(( this.current_step + 1) < this.stepCount){
var next_step=this.current_step + 1;
this.toStep(next_step, true, false, $form);
}}
EWFCF7.prototype.toPrev=function($form){
if(this.animating) return false;
this.animating=true;
if(( this.current_step) > 0){
var next_step=this.current_step - 1;
this.toStep(next_step, false, true, $form);
}}
EWFCF7.prototype.events=function($form){
var that=this;
$form.find('.ewfcf7__indicator').each(function(){
$(this).on('click',function(){
if(that.animating) return false;
var step=parseInt($(this).data('step'));
if(step!=that.current_step&&(step + 1) <=that.stepCount){
if(step > that.current_step){
that.animating=true;
that.toStep(step, true, false, $form);
}
if(step < that.current_step){
that.animating=true;
that.toStep(step, false, true, $form);
}}
});
});
$form.find('.ewfcf7-button').each(function(){
$(this).on('click', function(){
if($(this).data('target')=='next'){
that.toNext($form);
}
else if($(this).data('target')=='previous'){
that.toPrev($form);
}});
});
}
EWFCF7.prototype.toNextFadeIn=function(current_step, next_step, $form){
var that=this;
var next_fs=$form.find('.ewfcf7-step-group:eq('+next_step+')');
var current_fs=$form.find('.ewfcf7-step-group:eq('+current_step+')');
var opacity;
next_fs.show();
current_fs.animate({opacity: 0}, {
step: function(now, mx){
opacity=1 - now;
next_fs.css({'opacity': opacity});
current_fs.css({
'position':'absolute'
})
},
duration: 800,
complete: function(){
current_fs.hide();
that.animating=false;
that.current_step=next_step;
current_fs.css({'position': 'relative'});
},
easing: 'easeInOutBack'
})
}
EWFCF7.prototype.toNextInOut=function(current_step, next_step, $form){
var next_fs=$form.find('.ewfcf7-step-group:eq('+next_step+')');
var current_fs=$form.find('.ewfcf7-step-group:eq('+current_step+')');
var that=this;
var left, opacity, scale;
next_fs.show();
next_fs.css({
'transform': 'scale(1)',
'position': 'relative'
});
current_fs.animate({opacity: 0}, {
step: function(now, mx){
scale=1 - (1 - now) * 0.2;
left=(now * 50)+"%";
opacity=1 - now;
current_fs.css({
'transform': 'scale('+scale+')',
'position': 'absolute'
});
next_fs.css({'left': left, 'opacity': opacity});
},
duration: 800,
complete: function(){
current_fs.hide();
that.animating=false;
that.current_step=next_step;
current_fs.css({'position': 'relative'});
},
easing: 'easeInOutBack'
});
}
EWFCF7.prototype.toPrevInOut=function(current_step, prev_step, $form){
var that=this;
var prev_fs=$form.find('.ewfcf7-step-group:eq('+prev_step+')');
var current_fs=$form.find('.ewfcf7-step-group:eq('+current_step+')');
var left, opacity, scale;
prev_fs.show();
prev_fs.css({
'left': '0%',
'position': 'absolute'
});
current_fs.animate({opacity: 0}, {
step: function(now, mx){
scale=0.8 + (1 - now) * 0.2;
left=((1-now) * 50)+"%";
opacity=1 - now;
current_fs.css({'left': left});
prev_fs.css({'transform': 'scale('+scale+')', 'opacity': opacity});
},
duration: 800,
complete: function(){
current_fs.hide();
that.animating=false;
that.current_step=prev_step;
prev_fs.css({'position': 'relative'});
current_fs.css({'position': 'relative'});
},
easing: 'easeInOutBack'
});
}
$(window).on('elementor/frontend/init', function(){
elementorFrontend.hooks.addAction('frontend/element_ready/ewfcf7_widget.default', function($scope, $){
$scope.find('.ewfcf7-form').each(function(){
new EWFCF7($(this));
});
});
});
}(jQuery));