File: /home/vspt/public_html/wp-content/plugins/winwheel4wp/assets/winwheel4wp.js
/*
Win Wheel For Wordpress - winwheel4wp.js
Author: Jure Hajdinjak / Copyright (c) Jure Hajdinjak
Support: https://codecanyon.net/user/superduper-plugins
It is allowed to distirbute this file only if you have a license (Envato Regular / Envato Extended) and by terms & conditions defined in your license:
https://codecanyon.net/licenses/terms/regular
https://codecanyon.net/licenses/terms/extended
*/
window.winwheel4wp_AnimFrame = (function(){
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
function(){ };
})();
function winwheel4wp(html_id,ajax_url) {
this.ajax_url = ajax_url;
this.html_id = html_id;
this.wheel_time = 0;
this.wheel_deg = 0;
this.wheel_deg_end = 0;
this.wheel_time_end = 0;
this.wheel_deg_ease = 0;
this.animation_start_time = null;
this.win_msg = '';
this.times_run = 0;
this.enable_spin_again_dialog = true;
this.getRandomInt = function(min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; };
this.wheel_ease = function(x) { return 1 - Math.pow( 1 - x, 5 ); };
this.marker_ease = function(x) {
var n = (- Math.pow((1-(x*2)),2)+1);
if (n < 0) n = 0;
return n;
};
this.animate = function(timestamp) {
var aa;
var bb;
var i;
var ticker_calc;
if (!this.animation_start_time) this.animation_start_time = timestamp;
this.wheel_time = timestamp - this.animation_start_time;
if(this.wheel_time > this.wheel_time_end) this.wheel_time = this.wheel_time_end;
this.wheel_deg_ease = this.wheel_ease( (( this.wheel_deg_end / this.wheel_time_end ) * this.wheel_time) / this.wheel_deg_end );
this.wheel_deg = this.wheel_deg_ease * this.wheel_deg_end;
jQuery('#winwheel4wp_'+this.html_id+' .winwheel4wp_marker').css({'transform' : 'translateX(-50%) translateY(-50%) rotate3d(0,0,1,' + '270deg)'});
jQuery('#winwheel4wp_'+this.html_id+' .winwheel4wp_marker').css({'-webkit-transform' : 'translateX(-50%) translateY(-50%) rotate3d(0,0,1,' + '270deg)'});
ticker_calc = this.wheel_deg - Math.floor(this.wheel_deg/360)*360;
for (i = 1; i <= 8; i++) {
if ((ticker_calc >= (i*45)-25) && (ticker_calc <= (i*45))) {
aa = 0.2;
if(this.wheel_deg_ease > aa) aa=this.wheel_deg_ease;
bb = this.marker_ease(-(((i*45)-25)-ticker_calc)/10) * (20*aa);
jQuery('#winwheel4wp_'+this.html_id+' .winwheel4wp_marker').css({'transform' : 'translateX(-50%) translateY(-50%) rotate3d(0,0,1,'+ (270-bb) + 'deg)'});
jQuery('#winwheel4wp_'+this.html_id+' .winwheel4wp_marker').css({'-webkit-transform' : 'translateX(-50%) translateY(-50%) rotate3d(0,0,1,'+ (270-bb) + 'deg)'});
}
}
jQuery('#winwheel4wp_'+this.html_id+' .winwheel4wp').css({'transform' : 'rotate3d(0,0,1,'+ this.wheel_deg +'deg)'});
jQuery('#winwheel4wp_'+this.html_id+' .winwheel4wp').css({'-webkit-transform' : 'rotate3d(0,0,1,'+ this.wheel_deg +'deg)'});
if(timestamp - this.animation_start_time > this.wheel_time_end) {
jQuery('#winwheel4wp_wheel_run_win_msg_'+this.html_id).html(this.win_msg);
jQuery('#winwheel4wp_wheel_run_win_msg_modal_'+this.html_id).html(this.win_msg);
jQuery('#winwheel4wp_modal_box_container_'+this.html_id).show();
jQuery('#winwheel4wp_wheel_run_win_msg_'+this.html_id).slideDown();
jQuery('#winwheel4wp_form_'+this.html_id + ' *').attr('disabled',false);
return;
}
winwheel4wp_AnimFrame(this.animate.bind(this));
};
this.wheel_run = function() {
if ( (this.enable_spin_again_dialog) && (this.times_run == 1) ) {
var detect_ios = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
if(!detect_ios) confirm_spin_again = confirm(jQuery('#winwheel4wp_form_'+this.html_id+' #lang_spin_again').val());
if(detect_ios) confirm_spin_again = true;
if(confirm_spin_again === false) {
jQuery('#winwheel4wp_form_'+this.html_id + ' *').attr('disabled',false);
return;
}
}
jQuery.ajax({
url: ajax_url,
method: 'POST',
data: {
action: 'winwheel4wp_wheel_run',
form_data: jQuery('#winwheel4wp_form_'+this.html_id).serialize()
},
context: this,
}).done(function(json){
json = jQuery.parseJSON(json);
if ((grecaptcha !== undefined) && (json.error_code === 'recaptcha')) grecaptcha.reset();
if (json.error_msg !== undefined) {
jQuery('#winwheel4wp_wheel_run_err_msg_'+this.html_id).html(json.error_msg);
jQuery('#winwheel4wp_form_'+this.html_id + ' *').attr('disabled',false);
return;
}
if (json.win_msg !== undefined) {
this.times_run = 1;
jQuery('#winwheel4wp_wheel_run_win_msg_'+this.html_id).slideUp();
this.win_msg = json.win_msg;
}
jQuery('#winwheel4wp_wheel_run_err_msg_'+this.html_id).html('');
this.wheel_deg_end = json.wheel_deg_end;
this.wheel_time_end = json.wheel_time_end;
jQuery('#winwheel4wp_form_'+this.html_id + ' *').attr('disabled',true);
this.wheel_time = 0;
this.wheel_deg = 0;
jQuery(document.body).animate({
'scrollTop': jQuery('#winwheel4wp_'+this.html_id).offset().top - 70
}, 650,'swing');
var parent = this;
this.animation_start_time = null;
setTimeout(function(){winwheel4wp_AnimFrame(parent.animate.bind(parent));},750);
});
};
}
function winwheel4wp_modal_box_close(wheel_html_id) {
jQuery('#winwheel4wp_modal_box_container_'+wheel_html_id).hide();
}