1/* 2 Plugin Name: Coupon Wheel For WooCommerce and WordPress 3 Description: One nice gamified exit-intent popup plugin :-) 4 Author: Jure Hajdinjak / Copyright (c) 2017-2020 Jure Hajdinjak 5*/ 6 7if ( typeof window.couponwheel_AnimFrame == 'undefined' ) { 8 window.couponwheel_AnimFrame = (function(){ 9 return window.requestAnimationFrame || 10 window.webkitRequestAnimationFrame || 11 window.mozRequestAnimationFrame || 12 function(){}; 13 })(); 14} 15 16function couponwheel(init_params) 17{ 18 //init vars 19 this.wheel_hash = init_params.wheel_hash; 20 this.wheel_dom = init_params.wheel_dom; 21 this.timed_trigger = init_params.timed_trigger; 22 this.exit_trigger = init_params.exit_trigger; 23 this.show_popup_after = init_params.show_popup_after; 24 this.preview_key = init_params.preview_key; 25 this.recaptcha_sitekey = init_params.recaptcha_sitekey; 26 this.require_recaptcha = init_params.require_recaptcha; 27 this.prevent_triggers_on_mobile = init_params.prevent_triggers_on_mobile; 28 this.kiosk_mode = init_params.kiosk_mode; 29 this.confirm_close_text = init_params.confirm_close_text; 30 this.custom_on_show_popup = init_params.custom_on_show_popup; 31 32 this.on_win_url = ''; 33 this.on_win_url_target_blank = false; 34 this.recaptcha_rendered = false; 35 this.exit_triggered = false; 36 this.can_show = true; 37 this.can_close = true; 38 this.reload_page = false; 39 this.window_scroll_value = 0; 40 this.stage = 1; 41 this.wheel_slice_number = 0; 42 43 //functions 44 this.render_recaptcha = function() 45 { 46 grecaptcha.render('couponwheel'+this.wheel_hash+'_recaptcha', {'sitekey' : this.recaptcha_sitekey}); 47 this.recaptcha_rendered = true; 48 }; 49 50 this.ios_input_workaround_enable = function() 51 { 52 // iOS fixed input render bug workaround 53 if (this.is_ios() === false) return; 54 this.window_scroll_value = jQuery(window).scrollTop(); 55 jQuery(window).scrollTop(0); 56 jQuery('.couponwheel_popup').css({'position':'absolute', top:0}); 57 jQuery('body').addClass('couponwheel_ios_stop_scrolling'); 58 // 59 }; 60 61 this.ios_input_workaround_disable = function() 62 { 63 if (this.is_ios() === false) return; 64 jQuery('body').removeClass('couponwheel_ios_stop_scrolling'); 65 jQuery(window).scrollTop(this.window_scroll_value); 66 }; 67 68 this.is_ios = function() 69 { 70 if (/iPad|iPhone|iPod/.test(navigator.userAgent)) return true; 71 return false; 72 }; 73 74 this.is_embed = function() 75 { 76 var i = jQuery(this.wheel_dom).parent()[0].className.indexOf('couponwheel_embed'); 77 if (i !== -1) return true; 78 return false; 79 }; 80 81 this.show_popup = function(exit_trigger_check) 82 { 83 84 if ( typeof exit_trigger_check == 'undefined') 85 { 86 exit_trigger_check = true; 87 } 88 89 if (this.can_show === false) return; 90 if (exit_trigger_check && this.exit_triggered) return; 91 this.exit_triggered = true; 92 this.can_show = false; 93 if (this.require_recaptcha && this.recaptcha_rendered === false) this.render_recaptcha(); 94 if (!this.is_embed()) this.ios_input_workaround_enable(); 95 jQuery(this.wheel_dom).css('pointer-events','auto'); 96 jQuery(this.wheel_dom+' .couponwheel_popup').show(); 97 if (!this.is_embed()) { 98 jQuery(this.wheel_dom+' .couponwheel_popup_shadow').show(); 99 jQuery(this.wheel_dom+' .couponwheel_popup').css({'left':'-100%'}); 100 jQuery(this.wheel_dom+' .couponwheel_popup').animate({left: '0px'},500,'easeOutExpo'); 101 } 102 jQuery.ajax({ 103 url: couponwheel_ajaxurl, 104 type: 'POST', 105 data: { 106 action: 'couponwheel_event', 107 code: 'show_popup', 108 wheel_hash: this.wheel_hash, 109 preview_key: this.preview_key 110 } 111 }); 112 113 this.custom_on_show_popup(); 114 115 }; 116 this.close_popup = function() 117 { 118 if(this.can_close === false) return; 119 this.can_close = false; 120 jQuery(this.wheel_dom).css('pointer-events','none'); 121 jQuery(this.wheel_dom+' .couponwheel_popup').css({'left':'0%'}); 122 jQuery(this.wheel_dom+' .couponwheel_popup').animate({left: '-100%'},600,'easeInExpo',function(){ 123 jQuery(this.wheel_dom+' .couponwheel_popup_shadow').hide(); 124 jQuery(this.wheel_dom+' .couponwheel_popup').hide(); 125 this.can_close = true; 126 this.can_show = true; 127 128 if (this.kiosk_mode) 129 { 130 this.reset_popup(); 131 return; 132 } 133 134 if (this.reload_page) location.reload(); 135 this.ios_input_workaround_disable(); 136 window.couponwheel_notice.reload(); 137 }.bind(this)); 138 }; 139 140 this.reset_popup = function() 141 { 142 var is_embed = this.is_embed(); 143 jQuery(this.wheel_dom).remove(); 144 window['couponwheel'+this.wheel_hash] = undefined; 145 window.couponwheel_manual_trigger(this.wheel_hash,is_embed); 146 }; 147 148 this.hide_popup = function() 149 { 150 jQuery(this.wheel_dom+' .couponwheel_popup_shadow').hide(); 151 jQuery(this.wheel_dom+' .couponwheel_popup').hide(); 152 }; 153 154 this.go_to_stage2 = function() 155 { 156 jQuery(this.wheel_dom+' .couponwheel_form_stage1').hide(); 157 jQuery(this.wheel_dom+' .couponwheel_form_stage2').removeClass('couponwheel_hidden'); 158 jQuery(this.wheel_dom+' .couponwheel_form_stage2').addClass('couponwheel_effects_animated couponwheel_effects_bounceIn'); 159 160 setTimeout(function(){ 161 jQuery(this.wheel_dom+' .couponwheel_popup').animate({'scrollTop': jQuery(this.wheel_dom+' .couponwheel_form_stage2').offset().top}, 650,'swing'); 162 }.bind(this),1000); 163 164 this.can_close = true; 165 this.stage = 2; 166 }; 167 168 this.submit_form_done = function(response) 169 { 170 jQuery(this.wheel_dom+' .couponwheel_ajax_loader').hide(); 171 172 if (response.hide_popup === true) 173 { 174 this.hide_popup(); 175 return; 176 } 177 178 if (response.error_code == 'form_error') 179 { 180 this.can_close = true; 181 jQuery(this.wheel_dom+' .couponwheel_popup_form_error_text').html(response.error_msg); 182 jQuery(this.wheel_dom+' .couponwheel_form_stage1 *').attr('disabled',false); 183 return; 184 } 185 186 if (response.success) 187 { 188 jQuery(this.wheel_dom+' .couponwheel_popup').animate({'scrollTop': jQuery(this.wheel_dom+' .couponwheel_wheel_crop').offset().top}, 650,'swing'); 189 jQuery(this.wheel_dom+' .couponwheel_form_stage2 .couponwheel_popup_heading_text').html(response.stage2_heading_text); 190 jQuery(this.wheel_dom+' .couponwheel_form_stage2 .couponwheel_popup_main_text').html(response.stage2_main_text); 191 this.start_wheel_animation(response.wheel_deg_end,response.wheel_time_end); 192 this.wheel_slice_number = response.wheel_slice_number; 193 this.reload_page = response.reload_page; 194 if (response.notice !== false) localStorage.setItem('couponwheel_notice',response.notice); 195 if (typeof response.on_win_url != 'undefined') this.on_win_url = response.on_win_url; 196 if (typeof response.on_win_url_target_blank != 'undefined') this.on_win_url_target_blank = response.on_win_url_target_blank; 197 return; 198 } 199 200 this.can_close = true; 201 }; 202 203 this.submit_form = function(form_data) 204 { 205 jQuery(this.wheel_dom+' .couponwheel_ajax_loader').show(); 206 jQuery(this.wheel_dom+' .couponwheel_form_stage1 *').attr('disabled',true); 207 jQuery(this.wheel_dom+' .couponwheel_popup_form_error_text').html(''); 208 jQuery.ajax({ 209 url: couponwheel_ajaxurl, 210 type: 'POST', 211 data: { 212 action: 'couponwheel_wheel_run', 213 form_data: form_data, 214 preview_key: this.preview_key 215 },
216 context: this, 217 }).done(function(json){ 218 this.submit_form_done(jQuery.parseJSON(json)); 219 }); 220 }; 221 222 this.start_wheel_animation = function(wheel_deg_end,wheel_time_end) 223 { 224 this.wheel_deg_end = wheel_deg_end; 225 this.wheel_time_end = wheel_time_end; 226 227 this.wheel_time = 0; 228 this.wheel_deg = 0; 229 230 var parent = this; 231 this.animation_start_time = null; 232 couponwheel_AnimFrame(parent.animate.bind(parent)); 233 }; 234 235 //animations 236 this.wheel_time = 0; 237 this.wheel_deg = 0; 238 this.wheel_deg_end = 0; 239 this.wheel_time_end = 0; 240 this.wheel_deg_ease = 0; 241 this.animation_start_time = null; 242 243 this.wheel_ease = function(x) 244 { 245 return 1 - Math.pow( 1 - x, 5 ); 246 }; 247 248 this.marker_ease = function(x) 249 { 250 var n = (- Math.pow((1-(x*2)),2)+1); 251 if (n < 0) n = 0; 252 return n; 253 }; 254 this.animate = function(timestamp) 255 { 256 if (!this.animation_start_time) this.animation_start_time = timestamp; 257 this.wheel_time = timestamp - this.animation_start_time; 258 if(this.wheel_time > this.wheel_time_end) this.wheel_time = this.wheel_time_end; 259 this.wheel_deg_ease = this.wheel_ease( (( this.wheel_deg_end / this.wheel_time_end ) * this.wheel_time) / this.wheel_deg_end ); 260 this.wheel_deg = this.wheel_deg_ease * this.wheel_deg_end; 261 262 if(this.wheel_deg_ease > 0.99){ 263 jQuery(this.wheel_dom+' .couponwheel_marker').css({'transform' : 'translateY(-50%) rotate3d(0,0,1,0deg)','-webkit-transform' : 'translateY(-50%) rotate3d(0,0,1,0deg)'}); 264 } 265 266 var ticker_calc = this.wheel_deg - Math.floor(this.wheel_deg/360)*360; 267 var i; 268 269 for (i = 1; i <= 12; i++) { 270 if ((ticker_calc >= (i*30)-18) && (ticker_calc <= (i*30))) 271 { 272 var aa = 0.2; 273 if(this.wheel_deg_ease > aa) aa=this.wheel_deg_ease; 274 275 var bb = this.marker_ease(-(((i*30)-18)-ticker_calc)/10) * (30*aa); 276 277 jQuery(this.wheel_dom+' .couponwheel_marker').css({'transform' : 'translateY(-50%) rotate3d(0,0,1,'+ (0-bb) + 'deg)','-webkit-transform' : 'translateY(-50%) rotate3d(0,0,1,'+ (0-bb) + 'deg)'}); 278 } 279 } 280 281 jQuery(this.wheel_dom+' .couponwheel_wheel').css({'transform' : 'rotate3d(0,0,1,'+ this.wheel_deg +'deg)','-webkit-transform' : 'rotate3d(0,0,1,'+ this.wheel_deg +'deg)'}); 282 283 var deg_remaining = this.wheel_deg_end - this.wheel_deg; 284 285 // release from animation early to prevent delay 286 if ( 1 > deg_remaining && this.stage == 1 ) this.go_to_stage2(); 287 if ( timestamp - this.animation_start_time > this.wheel_time_end ) return; 288 289 this.last_wheel_deg = this.wheel_deg; 290 291 couponwheel_AnimFrame(this.animate.bind(this)); 292 }; 293 294 //main init 295 jQuery(this.wheel_dom+' .couponwheel_stage1_submit_btn').attr('disabled',false); 296 297 jQuery(this.wheel_dom+' .couponwheel_stage2_continue_btn').click(function() 298 { 299 300 if (this.on_win_url.length > 0) 301 { 302 if (this.on_win_url_target_blank === true) { 303 window.open(this.on_win_url); 304 } else { 305 window.location = this.on_win_url; 306 return; 307 } 308 } 309 310 this.close_popup(); 311 312 }.bind(this)); 313 314 jQuery(this.wheel_dom+' .couponwheel_spin_again_btn').click(function(){this.kiosk_mode = true; this.close_popup(); }.bind(this)); 315 jQuery(this.wheel_dom+' .couponwheel_popup_close_btn').click(function(){this.close_popup(); }.bind(this)); 316 jQuery(this.wheel_dom+' .couponwheel_popup_shadow').click(function(){ 317 if (this.confirm_close_text.length === 0) { 318 this.close_popup(); 319 return; 320 } 321 if ( confirm(this.confirm_close_text+'?') == true ) { this.close_popup(); } 322 }.bind(this)); 323 324 jQuery(this.wheel_dom+' .couponwheel_form_stage1').on('submit',function(event){ 325 event.preventDefault(); 326 this.can_close = false; 327 this.submit_form(jQuery(this.wheel_dom+' .couponwheel_form_stage1').seri
327alize()); 328 }.bind(this)); 329 330 var isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent); 331 332 if (typeof this.prevent_triggers_on_mobile == 'undefined') this.prevent_triggers_on_mobile = false; 333 334 if (((isMobile) && (this.prevent_triggers_on_mobile)) === false) 335 { 336 if (this.timed_trigger) 337 { 338 new couponwheel_DialogTrigger(function(){this.show_popup();}.bind(this), { trigger: 'timeout', timeout: this.show_popup_after*1000 }); 339 } 340 341 if (this.exit_trigger) 342 { 343 new couponwheel_DialogTrigger(function(){this.show_popup();}.bind(this), { trigger: 'exitIntent' }); 344 new couponwheel_DialogTrigger(function(){this.show_popup();}.bind(this), { trigger: 'scrollUp', percent: 10, scrollInterval: 150 }); 345 } 346 } 347 348} 349 350function couponwheel_manual_trigger(wheel_hash,embed) 351{ 352 353 if (typeof embed == 'undefined') embed = false; 354 355 if ( jQuery('#couponwheel'+wheel_hash).length == 0 ) 356 { 357 jQuery.ajax({ 358 url: couponwheel_ajaxurl, 359 type: 'POST', 360 data: { 361 action: 'couponwheel_load_popups', 362 wheel_hash: wheel_hash 363 }, 364 context: this, 365 }).done(function(html){ 366 367 if (embed) 368 { 369 couponwheel_append_wheel_to_document(html,'.couponwheel_embed_'+wheel_hash); 370 } else { 371 couponwheel_append_wheel_to_document(html); 372 } 373 374 if (typeof window['couponwheel'+wheel_hash] != 'undefined') 375 { 376 window['couponwheel'+wheel_hash].show_popup(0); 377 } else { 378 console.log('Coupon Wheel with hash '+wheel_hash+' does not exist or is not LIVE'); 379 } 380 }); 381 } else { 382 window['couponwheel'+wheel_hash].show_popup(0); 383 } 384} 385 386function couponwheel_append_wheel_to_document(html,target) 387{ 388 if (typeof target == 'undefined') target = document.body; 389 jQuery.each(jQuery(html),function(i,v) { 390 var wheel_hash = jQuery(v).data('item'); 391 if ( jQuery('#couponwheel'+wheel_hash).length == 0 ) { 392 jQuery(target).append(v.innerHTML); 393 } 394 }); 395} 396 397window.addEventListener('load',function(){ 398 399 // CSS trigger 400 jQuery('[class*="couponwheel_css_trigger_"]').click(function(e){ 401 e.preventDefault(); 402 e.currentTarget.classList.forEach(v => { 403 if ( v.indexOf('couponwheel_css_trigger_') === 0 ) couponwheel_manual_trigger( v.split('_')[3] ); 404 }); 405 }); 406 // 407 408 if (typeof window.couponwheel_embed != 'undefined') return; 409 410 jQuery.ajax({ 411 url: couponwheel_ajaxurl, 412 type: 'POST', 413 data: { 414 action: 'couponwheel_load_popups', 415 page_id: couponwheel_page_id, 416 post_is_single: couponwheel_post_is_single, 417 locale: couponwheel_locale, 418 order_received: couponwheel_order_received 419 }, 420 context: this, 421 }).done(function(html){ 422 couponwheel_append_wheel_to_document(html); 423 }); 424 425}); 426 427 428// Coupon Wheel notice class 429 430couponwheel_notice = function() 431{ 432 this.interval = 0; 433 434 this.reload = function() 435 { 436 var ls = localStorage.getItem('couponwheel_notice'); 437 438 if ((ls !== null) && (ls.length !== 0)) 439 { 440 jQuery('#couponwheel_notice').empty(); 441 442 try { 443 jQuery('#couponwheel_notice').append(ls); 444 } catch(e) { 445 window.couponwheel_notice.clear(); 446 } 447 448 return; 449 } 450 }; 451 452 this.clear = function() 453 { 454 jQuery('#couponwheel_notice_content').hide(); 455 clearInterval(window.couponwheel_notice.interval); 456 localStorage.removeItem('couponwheel_notice'); 457 }; 458 459 this.start = function(notice, template_vars, expire_timestamp, lang_days) 460 { 461 462 if (typeof expire_timestamp == 'undefined') expire_timestamp = 0; 463 if (typeof lang_days == 'undefined') lang_days = 'days'; 464 465 function seconds_to_minsec(ds) { 466 var d = Math.floor(ds / 86400); 467 var h = Math.floor(ds % 86400 / 3600); 468 var m = Math.floor(ds % 3600 / 60); 469 var s = Math.floor(ds % 3600 % 60); 470 471 if (d > 0) return Math.floor(d) + ' ' + lang_days; 472 if (h > 0) return Math.floor(h) + couponwheel_notice_translations.h + ' ' + Math.floor(m) + couponwheel_notice_translations.m + ' ' + Math.floor(s) + couponwheel_notice_translations.s; 473 return Math.floor(m) + couponwheel_notice_translations.m + ' ' + Math.floor(s) + couponwheel_notice_translations.s; 474 } 475 476 function refresh() 477 { 478 var secleft = expire_timestamp - Math.floor(Date.now() / 1000); 479 480 jQuery('#couponwheel_notice_timer').html(seconds_to_minsec(secleft)); 481 482 if (secleft < 0) 483 { 484 window.couponwheel_notice.clear(); 485 } 486 } 487 488 var parsed_notice = notice; 489 parsed_notice = parsed_notice.replace('{couponcode}','<strong>'+template_vars.couponcode_raw+'</strong>'); 490 491 jQuery.each( template_vars, function(key,value) { 492 parsed_notice = parsed_notice.replace('{'+key+'}',value); 493 }); 494 495 parsed_notice = parsed_notice.replace('{timer}','<strong id="couponwheel_notice_timer">{timer}</strong>'); 496 jQuery('#couponwheel_notice_content > span').html(parsed_notice); 497
498 refresh(); 499 500 clearInterval(window.couponwheel_notice.interval); 501 window.couponwheel_notice.interval = setInterval(function(){ 502 refresh(); 503 },1000); 504 }; 505}; 506 507window.couponwheel_notice = new couponwheel_notice();
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.