1jQuery(window).on('elementor/frontend/init', () => { 2 "use strict"; 3 elementorFrontend.hooks.addAction('frontend/element_ready/woocommerce-lucky-wheel.default', function ($scope) { 4 if (!window.elementor) { 5 return; 6 } 7 let $container = $scope.find('.wc-lucky-wheel-shortcode-container'); 8 if (!$container || $container.length === 0) { 9 return; 10 } 11 let shortcode_id = $container.attr('id'); 12 let shortcode_args = $container.data('shortcode_args'); 13 /*Click button spin when input fields are on focus and Enter key is pressed*/ 14 $container.find('.wc-lucky-wheel-shortcode-wheel-field').on('keyup', function (e) { 15 if (e.keyCode === 13) { 16 $container.find('.wc-lucky-wheel-shortcode-wheel-button').click(); 17 } 18 }); 19 let congratulations_effect = shortcode_args.congratulations_effect; 20 let font_size = shortcode_args.font_size || 100; 21 let wheel_size = shortcode_args.wheel_size || 100; 22 let custom_field_name_enable = shortcode_args.custom_field_name_enable; 23 let custom_field_name_required = shortcode_args.custom_field_name_required; 24 let custom_field_mobile_enable = shortcode_args.custom_field_mobile_enable; 25 let custom_field_mobile_required = shortcode_args.custom_field_mobile_required; 26 let color = shortcode_args.color; 27 let slices_text_color = shortcode_args.slices_text_color; 28 let label = shortcode_args.label; 29 let piece_coupons = shortcode_args.coupon_type; 30 let wlwl_center_color = shortcode_args.wheel_center_color; 31 let wlwl_border_color = shortcode_args.wheel_border_color; 32 let wlwl_dot_color = shortcode_args.wheel_dot_color; 33 let gdpr_checkbox = shortcode_args.gdpr; 34 let wlwl_spinning_time = shortcode_args.spinning_time; 35 let wheel_speed = shortcode_args.wheel_speed; 36 let center_image = shortcode_args.center_image; 37 38 let slices = piece_coupons.length; 39 let sliceDeg = 360 / slices; 40 let deg = -(sliceDeg / 2); 41 let cv = $container.find('.wc-lucky-wheel-shortcode-wheel-canvas-1')[0]; 42 if (cv === undefined) { 43 return; 44 } 45 let ctx = cv.getContext('2d'); 46 47 let canvas_width; 48 let wd_width, wd_height; 49 wd_width = window.innerWidth; 50 wd_height = window.innerHeight; 51 if (wd_width > wd_height) { 52 canvas_width = wd_height; 53 } else { 54 canvas_width = wd_width; 55 } 56 let width = parseInt(canvas_width * 0.75 + 16);// size 57 if (canvas_width > 480) { 58 width = parseInt(wheel_size * (canvas_width * 0.55 + 16) / 100); 59 } 60 cv.width = width; 61 cv.height = width; 62 if (window.devicePixelRatio) { 63 let hidefCanvasWidth = jQuery(cv).attr('width'); 64 let hidefCanvasHeight = jQuery(cv).attr('height'); 65 let hidefCanvasCssWidth = hidefCanvasWidth; 66 let hidefCanvasCssHeight = hidefCanvasHeight; 67 jQuery(cv).attr('width', hidefCanvasWidth * window.devicePixelRatio); 68 jQuery(cv).attr('height', hidefCanvasHeight * window.devicePixelRatio); 69 jQuery(cv).css('width', hidefCanvasCssWidth); 70 jQuery(cv).css('height', hidefCanvasCssHeight); 71 ctx.scale(window.devicePixelRatio, window.devicePixelRatio); 72 } 73 74 let center = width / 2; // center 75 $container.find('.wc-lucky-wheel-shortcode-wheel-canvas').css({ 76 'width': width + 'px', 77 'height': width + 'px' 78 }); 79 let inline_css = ''; 80 if (shortcode_args.pointer_position === 'center') { 81 inline_css += '#' + shortcode_id + ' .wc-lucky-wheel-shortcode-wheel-pointer:before{font-size:' + parseInt(width / 4) + 'px !important; }'; 82 } else { 83 inline_css += '#' + shortcode_id + ' .wc-lucky-wheel-shortcode-wheel-pointer:before{font-size:' + parseInt(width / 10) + 'px !important; }'; 84 inline_css += '#' + shortcode_id + '.wc-lucky-wheel-shortcode-margin-
84position .wc-lucky-wheel-shortcode-wheel-container .wc-lucky-wheel-shortcode-wheel-pointer-container .wc-lucky-wheel-shortcode-wheel-pointer:after{width:' + parseInt(width / 25) + 'px !important;height:' + parseInt(width / 25) + 'px !important;bottom:' + parseInt(width / 25) + 'px !important; }'; 85 } 86 jQuery('head').append('<style type="text/css">' + inline_css + '</style>'); 87 let wheel_text_size; 88 wheel_text_size = parseInt(width / 28) * parseInt(font_size) / 100; 89 90 function wlwl_shortcode_deg2rad(deg) { 91 return deg * Math.PI / 180; 92 } 93 94 function wlwl_shortcode_drawSlice(deg, color) { 95 ctx.beginPath(); 96 ctx.fillStyle = color; 97 ctx.moveTo(center, center); 98 let r; 99 if (width <= 480) { 100 r = width / 2 - 10; 101 } else { 102 r = width / 2 - 14; 103 } 104 ctx.arc(center, center, r, wlwl_shortcode_deg2rad(deg), wlwl_shortcode_deg2rad(deg + sliceDeg)); 105 ctx.lineTo(center, center); 106 ctx.fill(); 107 } 108 109 function wlwl_shortcode_drawPoint(deg, color) { 110 ctx.save(); 111 ctx.beginPath(); 112 ctx.fillStyle = color; 113 ctx.shadowBlur = 1; 114 ctx.shadowOffsetX = 8; 115 ctx.shadowOffsetY = 8; 116 ctx.shadowColor = 'rgba(0,0,0,0.2)'; 117 ctx.arc(center, center, width / 8, 0, 2 * Math.PI); 118 ctx.fill(); 119 ctx.clip(); 120 ctx.restore(); 121 } 122 123 function wlwl_shortcode_drawBorder(borderC, dotC, lineW, dotR, des, shadColor) { 124 let center1 = center - 2 * des; 125 ctx.beginPath(); 126 ctx.strokeStyle = borderC; 127 ctx.lineWidth = lineW; 128 ctx.shadowBlur = 1; 129 ctx.shadowOffsetX = 6; 130 ctx.shadowOffsetY = 6; 131 ctx.shadowColor = shadColor; 132 ctx.arc(center, center, center1, 0, 2 * Math.PI); 133 ctx.stroke(); 134 let x_val, y_val, deg; 135 deg = sliceDeg / 2; 136 for (let i = 0; i < slices; i++) { 137 ctx.beginPath(); 138 ctx.fillStyle = dotC; 139 x_val = center + center1 * Math.cos(deg * Math.PI / 180); 140 y_val = center - center1 * Math.sin(deg * Math.PI / 180); 141 ctx.arc(x_val, y_val, dotR, 0, 2 * Math.PI); 142 ctx.fill(); 143 deg += sliceDeg; 144 } 145 } 146 147 function wlwl_shortcode_drawText(deg, text, color) { 148 let font_text_wheel = 'Helvetica'; 149 if (typeof shortcode_args.font_text_wheel !== 'undefined' && shortcode_args.font_text_wheel !== '') { 150 font_text_wheel = shortcode_args.font_text_wheel; 151 } 152 ctx.save(); 153 ctx.translate(center, center); 154 ctx.rotate(wlwl_shortcode_deg2rad(deg)); 155 ctx.textAlign = "right"; 156 ctx.fillStyle = color; 157 ctx.font = '200 ' + wheel_text_size + 'px ' + font_text_wheel; 158 ctx.shadowOffsetX = 0; 159 ctx.shadowOffsetY = 0; 160 text = text.replace(/&#(\d{1,4});/g, function (fullStr, code) { 161 return String.fromCharCode(code); 162 }); 163 let reText = text.split('\/n'), text1 = '', text2 = '', text3 = ''; 164 if (reText.length > 1) { 165 text1 = reText[0]; 166 if (reText.length > 2) { 167 text2 = reText[1]; 168 } else { 169 text2 = reText.splice(1, reText.length - 1); 170 text2 = text2.join(''); 171 } 172 text3 = reText.splice(2, reText.length - 1); 173 text3 = text3.join(''); 174 175 } else { 176 reText = text.split('\\n'); 177 if (reText.length > 1) { 178 text1 = reText[0]; 179 text2 = reText.splice(1, reText.length - 1); 180 text2 = text2.join(''); 181 text3 = reText.splice(2, reText.length - 2); 182 text3 = text3.join(''); 183 } 184 } 185 if (text1.trim() !== "" && text2.trim() !== "" && text3.trim() === "") { 186 ctx.fillText(text1.trim(), 7 * center / 8, -(wheel_text_size * 1 / 4)); 187 ctx.fillText(text2.trim(), 7 * center / 8, wheel_text_size * 3 / 4); 188 } else if (text1.trim() !== "" && text2.trim() !== "" && text3.trim() !== "") { 189 ctx.fillText(text1.trim(), 7 * center / 8, -(wheel_text_size * 1 / 2)); 190 ctx.fillText(text2.trim(), 7 * center / 8, (wheel_text_size * 1 / 2)); 191 ctx.fillText(text3.trim(), 7 * center / 8, (wheel_text_size * 1.5)); 192 } else {
193 ctx.fillText(text.replace(/\\n/g, '').replace(/\/n/g, ''), 7 * center / 8, wheel_text_size / 2 - 2); 194 } 195 ctx.restore(); 196 } 197 198 function wlwl_shortcode_spins_wheel($container, stop_position, result_notification, result) { 199 let canvas_1 = $container.find('.wc-lucky-wheel-shortcode-wheel-canvas-1'); 200 let canvas_3 = $container.find('.wc-lucky-wheel-shortcode-wheel-canvas-3'); 201 let default_css = ''; 202 if (window.devicePixelRatio) { 203 default_css = 'width:' + width + 'px;height:' + width + 'px;'; 204 } 205 canvas_1.attr('style', default_css); 206 canvas_3.attr('style', default_css); 207 let stop_deg = 360 - sliceDeg * stop_position; 208 let wheel_stop = wheel_speed * 360 * wlwl_spinning_time + stop_deg; 209 let css = default_css + '-moz-transform: rotate(' + wheel_stop + 'deg);-webkit-transform: rotate(' + wheel_stop + 'deg);-o-transform: rotate(' + wheel_stop + 'deg);-ms-transform: rotate(' + wheel_stop + 'deg);transform: rotate(' + wheel_stop + 'deg);'; 210 css += '-webkit-transition: transform ' + wlwl_spinning_time + 's ease;-moz-transition: transform ' + wlwl_spinning_time + 's ease;-ms-transition: transform ' + wlwl_spinning_time + 's ease;-o-transition: transform ' + wlwl_spinning_time + 's ease;transition: transform ' + wlwl_spinning_time + 's ease;'; 211 canvas_1.attr('style', css); 212 canvas_3.attr('style', css); 213 spinning = true; 214 setTimeout(function () { 215 if (result === 'win' && congratulations_effect === 'firework') { 216 $container.find('.wlwl-congratulations-effect').addClass('wlwl-congratulations-effect-firework'); 217 } 218 $container.find('.wc-lucky-wheel-shortcode-wheel-fields-container').html('<div class="wc-lucky-wheel-shortcode--frontend-result">' + result_notification + '</div>'); 219 $container.find('.wc-lucky-wheel-shortcode-wheel-button-wrap').removeClass('wc-lucky-wheel-shortcode-loading'); 220 css = default_css + 'transform: rotate(' + stop_deg + 'deg);'; 221 canvas_1.attr('style', css); 222 canvas_3.attr('style', css); 223 spinning = false; 224 }, parseInt(wlwl_spinning_time * 1000)) 225 } 226 227 function isValidEmailAddress(emailAddress) { 228 let pattern = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}jQuery/i; 229 return pattern.test(emailAddress); 230 } 231 232 let spinning = false; 233 234 function validateRecaptcha(response) { 235 if (response) { 236 jQuery('.wlwl-shortcode-recaptcha-field #wlwl-shortcode-g-validate-response').val(response); 237 } 238 } 239 240 function expireRecaptcha() { 241 jQuery('.wlwl-shortcode-recaptcha-field #wlwl-shortcode-g-validate-response').val(null); 242 } 243 244 /* Googele recaptcha */ 245 window.addEventListener('load', function () { 246 if (shortcode_args.wlwl_recaptcha == 'on') { 247 if (shortcode_args.wlwl_recaptcha_version == 2) { 248 wlwlreCaptchaV2Onload(); 249 } else { 250 wlwlreCaptchaV3Onload(); 251 jQuery('.wlwl-shortcode-recaptcha-field').hide(); 252 } 253 } else { 254 jQuery('.wlwl-shortcode-recaptcha-field').hide(); 255 } 256 }); 257 258 function wlwlreCaptchaV3Onload() { 259 grecaptcha.ready(function () { 260 grecaptcha.execute(shortcode_args.wlwl_recaptcha_site_key, {action: 'homepage'}).then(function (token) { 261 validateRecaptcha(token); 262 }) 263 }); 264 } 265 266 function wlwlreCaptchaV2Onload() { 267 if (jQuery.find('.wlwl-shortcode-recaptcha').length == 0 || jQuery.find('.wlwl-shortcode-recaptcha iframe').length) { 268 return true; 269 } 270 grecaptcha.render('wlwl-shortcode-recaptcha', { 271 272 'sitekey': shortcode_args.wlwl_recaptcha_site_key, 273 274 'callback': validateRecaptcha, 275 276 'expired-callback': expireRecaptcha, 277 278 'theme': shortcode_args.wlwl_recaptcha_secret_theme, 279 280 'isolated': false 281 }); 282 283 } 284 285 function wlwl_shortcode_check_email() { 286 $container.find('.wc-lucky-wheel-shortcode-wheel-button-wrap').on('click', function () { 287 if (spinning) { 288 return; 289 } 290 $('#wlwl_shortcode_warring_recaptcha').html(''); 291 $('.wlwl-shortcode-recaptcha-field').removeClass('wc-lucky-wheel-shortcode-required-field'); 292 let $button = jQuery(this); 293 let $error_email = $container.find('.wc-lucky-wheel-shortcode-wheel-field-error-email'); 294 $error_email.html(''); 295 let $email = $container.find('.wc-lucky-wheel-shortcode-wheel-field-email'); 296 let $email_container = $email.closest('.wc-lucky-wheel-shortcode-wheel-field-email-wrap'); 297 let $name = $container.find('.wc-lucky-wheel-shortcode-wheel-field-name'); 298 let $name_container = $name.closest('.wc-lucky-wheel-shortcode-wheel-field-name-wrap'); 299 let $mobile = $container.find('.wc-lucky-wheel-shortcode-wheel-field-mobile'); 300 let $mobile_container = $mobile.closest('.wc-lucky-wheel-shortcode-wheel-field-mobile-wrap'); 301 $email_container.removeClass('wc-lucky-wheel-shortcode-required-field'); 302 $name_container.removeClass('wc-lucky-wheel-shortcode-required-field'); 303 $mobile_container.removeClass('wc-lucky-wheel-shortcode-required-field'); 304 if ('on' === gdpr_checkbox && !jQuery('.wc-lucky-wheel-shortcode-wheel-gdpr-wrap input[type="checkbox"]').prop('checked')) { 305 alert(shortcode_args.gdpr_warning); 306 return false; 307 } 308 let wlwl_email = $email.val(); 309 let wlwl_name = $name.val(); 310 let wlwl_mobile = $mobile.val(); 311 let shortcode_g_validate_response = $('#wlwl-shortcode-g-validate-response').val(); 312 let qualified = true; 313 let focus_field; 314 if (shortcode_args.wlwl_recaptcha && shortcode_args.wlwl_recaptcha_site_key && !shortcode_g_validate_response) { 315 $('.wlwl-shortcode-recaptcha-field #wlwl-shortcode-recaptcha > div').addClass('wc-lucky-wheel-shortcode-required-field').focus(); 316 $('#wlwl_shortcode_warring_recaptcha').html(shortcode_args.wlwl_warring_recaptcha); 317 qualified = false; 318 } else if (shortcode_args.wlwl_recaptcha && shortcode_args.wlwl_recaptcha_site_key) { 319 $('.wlwl-shortcode-recaptcha-field #wlwl-shortcode-recaptcha > div').removeClass('wc-lucky-wheel-shortcode-required-field'); 320 qualified = true; 321 } 322 if (!wlwl_email) { 323 $email.prop('disabled', false); 324 focus_field = $email; 325 $error_email.html(shortcode_args.empty_email_warning); 326 $email_container.addClass('wc-lucky-wheel-shortcode-required-field'); 327 qualified = false; 328 } 329 330 if (!isValidEmailAddress(wlwl_email)) { 331 $email.prop('disabled', false); 332 focus_field = $email; 333 $error_email.html(shortcode_args.invalid_email_warning); 334 $email_container.addClass('wc-lucky-wheel-shortcode-required-field'); 335 qualified = false; 336 } 337 if (custom_field_mobile_enable === 'on' && custom_field_mobile_required === 'on' && !wlwl_mobile) { 338 $mobile_container.addClass('wc-lucky-wheel-shortcode-required-field'); 339 $mobile.attr('placeholder', shortcode_args.custom_field_mobile_message); 340 focus_field = $mobile; 341 qualified = false; 342 } 343 if (custom_field_name_enable === 'on' && custom_field_name_required === 'on' && !wlwl_name) { 344 $name_container.addClass('wc-lucky-wheel-shortcode-required-field'); 345 $name.attr('placeholder', shortcode_args.custom_field_name_message); 346 focus_field = $name; 347 qualified = false; 348 } 349 350 if (qualified === false) { 351 focus_field.focus(); 352 return false; 353 } 354 $email.prop('disabled', true); 355 $error_email.html(''); 356 $button.addClass('wc-lucky-wheel-shortcode-loading'); 357 jQuery.ajax({ 358 type: 'post', 359 dataType: 'json', 360 url: shortcode_args.ajaxurl, 361 data: { 362 user_email: wlwl_email, 363 user_name: wlwl_name, 364 user_mobile: wlwl_mobile, 365 language: shortcode_args.language, 366 _woocommerce_lucky_wheel_nonce: jQuery('#_woocommerce_lucky_wheel_nonce').val(), 367 }, 368 success: function (response) { 369 if (response.allow_spin === 'yes') { 370 wlwl_shortcode_spins_wheel($container, response.stop_position, response.result_notification, response.result); 371 } else { 372 $button.removeClass('wc-lucky-wheel-shortcode-loading'); 373 $email.prop('disabled', false); 374 alert(response.allow_spin); 375 } 376 } 377 }); 378 }); 379 } 380 381 wlwl_shortcode_check_email(); 382 let center1 = 32; 383 for (let i = 0; i < slices; i++) { 384 wlwl_shortcode_drawSlice(deg, color[i]); 385 wlwl_shortcode_drawText(deg + sliceDeg / 2, label[i], slices_text_color[i]); 386 deg += sliceDeg; 387 388 } 389 cv = $container.find('.wc-lucky-wheel-shortcode-wheel-canvas-2')[0]; 390 ctx = cv.getContext('2d'); 391 cv.width = width; 392 cv.height = width; 393 if (window.devicePixelRatio) { 394 let hidefCanvasWidth = jQuery(cv).attr('width'); 395 let hidefCanvasHeight = jQuery(cv).attr('height'); 396 let hidefCanvasCssWidth = hidefCanvasWidth; 397 let hidefCanvasCssHeight = hidefCanvasHeight; 398 399 jQuery(cv).attr('width', hidefCanvasWidth * window.devicePixelRatio); 400 jQuery(cv).attr('height', hidefCanvasHeight * window.devicePixelRatio); 401 jQuery(cv).css('width', hidefCanvasCssWidth); 402 jQuery(cv).css('height', hidefCanvasCssHeight); 403 ctx.scale(window.devicePixelRatio, window.devicePixelRatio); 404 } 405 wlwl_shortcode_drawPoint(deg, wlwl_center_color); 406 if (center_image) { 407 let wl_image = new Image; 408 wl_image.onload = function () { 409 cv = $container.find('.wc-lucky-wheel-shortcode-wheel-canvas-2')[0]; 410 ctx = cv.getContext('2d'); 411 let image_size = 2 * (width / 8 - 7); 412 ctx.arc(center, center, image_size / 2, 0, 2 * Math.PI); 413 ctx.clip(); 414 ctx.drawImage(wl_image, center - image_size / 2, center - image_size / 2, image_size, image_size); 415 416 }; 417 wl_image.src = center_image; 418 } 419 420 if (width <= 480) { 421 wlwl_shortcode_drawBorder(wlwl_border_color, 'rgba(0,0,0,0)', 8, 3, 4, 'rgba(0,0,0,0.2)'); 422 } else { 423 wlwl_shortcode_drawBorder(wlwl_border_color, 'rgba(0,0,0,0)', 16, 6, 7, 'rgba(0,0,0,0.2)'); 424 } 425 cv = $container.find('.wc-lucky-wheel-shortcode-wheel-canvas-3')[0]; 426 ctx = cv.getContext('2d'); 427 428 cv.width = width; 429 cv.height = width; 430 if (window.devicePixelRatio) { 431 let hidefCanvasWidth = jQuery(cv).attr('width'); 432 let hidefCanvasHeight = jQuery(cv).attr('height'); 433 let hidefCanvasCssWidth = hidefCanvasWidth; 434 let hidefCanvasCssHeight = hidefCanvasHeight; 435 436 jQuery(cv).attr('width', hidefCanvasWidth * window.devicePixelRatio); 437 jQuery(cv).attr('height', hidefCanvasHeight * window.devicePixelRatio); 438 jQuery(cv).css('width', hidefCanvasCssWidth); 439 jQuery(cv).css('height', hidefCanvasCssHeight); 440 ctx.scale(window.devicePixelRatio, window.devicePixelRatio); 441 } 442 if (width <= 480) { 443 wlwl_shortcode_drawBorder('rgba(0,0,0,0)', wlwl_dot_color, 8, 3, 4, 'rgba(0,0,0,0)'); 444 } else { 445 wlwl_shortcode_drawBorder('rgba(0,0,0,0)', wlwl_dot_color, 16, 6, 7, 'rgba(0,0,0,0)'); 446 } 447 });
448}); 449jQuery(document).ready(function ($) { 450 "use strict"; 451 $('.wc-lucky-wheel-shortcode-container').map(function () { 452 let $container = $(this); 453 let shortcode_id = $container.attr('id'); 454 let shortcode_args = $container.data('shortcode_args'); 455 /*Click button spin when input fields are on focus and Enter key is pressed*/ 456 $container.find('.wc-lucky-wheel-shortcode-wheel-field').on('keyup', function (e) { 457 if (e.keyCode === 13) { 458 $container.find('.wc-lucky-wheel-shortcode-wheel-button').click(); 459 } 460 }); 461 let congratulations_effect = shortcode_args.congratulations_effect; 462 let font_size = shortcode_args.font_size || 100; 463 let wheel_size = shortcode_args.wheel_size || 100; 464 let custom_field_name_enable = shortcode_args.custom_field_name_enable; 465 let custom_field_name_required = shortcode_args.custom_field_name_required; 466 let custom_field_mobile_enable = shortcode_args.custom_field_mobile_enable; 467 let custom_field_mobile_required = shortcode_args.custom_field_mobile_required; 468 let color = shortcode_args.color; 469 let slices_text_color = shortcode_args.slices_text_color; 470 let label = shortcode_args.label; 471 let piece_coupons = shortcode_args.coupon_type; 472 let wlwl_center_color = shortcode_args.wheel_center_color; 473 let wlwl_border_color = shortcode_args.wheel_border_color; 474 let wlwl_dot_color = shortcode_args.wheel_dot_color; 475 let gdpr_checkbox = shortcode_args.gdpr; 476 let wlwl_spinning_time = shortcode_args.spinning_time; 477 let wheel_speed = shortcode_args.wheel_speed; 478 let center_image = shortcode_args.center_image; 479 480 let slices = piece_coupons.length; 481 let sliceDeg = 360 / slices; 482 let deg = -(sliceDeg / 2); 483 let cv = $container.find('.wc-lucky-wheel-shortcode-wheel-canvas-1')[0]; 484 if (cv === undefined) { 485 return; 486 } 487 let ctx = cv.getContext('2d'); 488 489 let canvas_width; 490 let wd_width, wd_height; 491 wd_width = window.innerWidth; 492 wd_height = window.innerHeight; 493 if (wd_width > wd_height) { 494 canvas_width = wd_height; 495 } else { 496 canvas_width = wd_width; 497 } 498 let width = parseInt(canvas_width * 0.75 + 16);// size 499 if (canvas_width > 480) { 500 width = parseInt(wheel_size * (canvas_width * 0.55 + 16) / 100); 501 } 502 cv.width = width; 503 cv.height = width; 504 if (window.devicePixelRatio) { 505 let hidefCanvasWidth = $(cv).attr('width'); 506 let hidefCanvasHeight = $(cv).attr('height'); 507 let hidefCanvasCssWidth = hidefCanvasWidth; 508 let hidefCanvasCssHeight = hidefCanvasHeight; 509 $(cv).attr('width', hidefCanvasWidth * window.devicePixelRatio); 510 $(cv).attr('height', hidefCanvasHeight * window.devicePixelRatio); 511 $(cv).css('width', hidefCanvasCssWidth); 512 $(cv).css('height', hidefCanvasCssHeight); 513 ctx.scale(window.devicePixelRatio, window.devicePixelRatio); 514 } 515 516 let center = width / 2; // center 517 $container.find('.wc-lucky-wheel-shortcode-wheel-canvas').css({'width': width + 'px', 'height': width + 'px'}); 518 let inline_css = ''; 519 if (shortcode_args.pointer_position === 'center') { 520 inline_css += '#' + shortcode_id + ' .wc-lucky-wheel-shortcode-wheel-pointer:before{font-size:' + parseInt(width / 4) + 'px !important; }'; 521 } else { 522 inline_css += '#' + shortcode_id + ' .wc-lucky-wheel-shortcode-wheel-pointer:before{font-size:' + parseInt(width / 10) + 'px !important; }'; 523 inline_css += '#' + shortcode_id + '.wc-lucky-wheel-shortcode-margin-position .wc-lucky-wheel-shortcode-wheel-container .wc-lucky-wheel-shortcode-wheel-pointer-container .wc-lucky-wheel-shortcode-wheel-pointer:after{width:' + parseInt(width / 25) + 'px !important;height:' + parseInt(width / 25) + 'px !important;bottom:' + parseInt(width / 25) + 'px !important; }'; 524 } 525 $('head').append('<style type="text/css">' + inline_css + '</style>'); 526 let wheel_text_size; 527 wheel_text_size = parseInt(width / 28) * parseInt(font_size) / 100; 528 529 function wlwl_shortcode_deg2rad(deg) { 530 return deg * Math.PI / 180; 531 } 532 533 function wlwl_shortcode_drawSlice(deg, color) { 534 ctx.beginPath(); 535 ctx.fillStyle = color; 536 ctx.moveTo(center, center); 537 let r; 538 if (width <= 480) { 539 r = width / 2 - 10; 540 } else { 541 r = width / 2 - 14; 542 } 543 ctx.arc(center, center, r, wlwl_shortcode_deg2rad(deg), wlwl_shortcode_deg2rad(deg + sliceDeg)); 544 ctx.lineTo(center, center); 545 ctx.fill(); 546 } 547 548 function wlwl_shortcode_drawPoint(deg, color) { 549 ctx.save(); 550 ctx.beginPath(); 551 ctx.fillStyle = color; 552 ctx.shadowBlur = 1; 553 ctx.shadowOffsetX = 8; 554 ctx.shadowOffsetY = 8; 555 ctx.shadowColor = 'rgba(0,0,0,0.2)'; 556 ctx.arc(center, center, width / 8, 0, 2 * Math.PI); 557 ctx.fill(); 558 ctx.clip();
559 ctx.restore(); 560 } 561 562 function wlwl_shortcode_drawBorder(borderC, dotC, lineW, dotR, des, shadColor) { 563 let center1 = center - 2 * des; 564 ctx.beginPath(); 565 ctx.strokeStyle = borderC; 566 ctx.lineWidth = lineW; 567 ctx.shadowBlur = 1; 568 ctx.shadowOffsetX = 6; 569 ctx.shadowOffsetY = 6; 570 ctx.shadowColor = shadColor; 571 ctx.arc(center, center, center1, 0, 2 * Math.PI); 572 ctx.stroke(); 573 let x_val, y_val, deg; 574 deg = sliceDeg / 2; 575 for (let i = 0; i < slices; i++) { 576 ctx.beginPath(); 577 ctx.fillStyle = dotC; 578 x_val = center + center1 * Math.cos(deg * Math.PI / 180); 579 y_val = center - center1 * Math.sin(deg * Math.PI / 180); 580 ctx.arc(x_val, y_val, dotR, 0, 2 * Math.PI); 581 ctx.fill(); 582 deg += sliceDeg; 583 } 584 } 585 586 function wlwl_shortcode_drawText(deg, text, color) { 587 let font_text_wheel = 'Helvetica'; 588 if (typeof shortcode_args.font_text_wheel !== 'undefined' && shortcode_args.font_text_wheel !== '') { 589 font_text_wheel = shortcode_args.font_text_wheel; 590 } 591 ctx.save(); 592 ctx.translate(center, center); 593 ctx.rotate(wlwl_shortcode_deg2rad(deg)); 594 ctx.textAlign = "right"; 595 ctx.fillStyle = color; 596 ctx.font = '400 ' + wheel_text_size + 'px ' + font_text_wheel; 597 ctx.shadowOffsetX = 0; 598 ctx.shadowOffsetY = 0; 599 text = text.replace(/&#(\d{1,4});/g, function (fullStr, code) { 600 return String.fromCharCode(code); 601 }); 602 let reText = text.split('\/n'), text1 = '', text2 = ''; 603 if (reText.length > 1) { 604 text1 = reText[0]; 605 text2 = reText.splice(1, reText.length - 1); 606 text2 = text2.join(''); 607 } else { 608 reText = text.split('\\n'); 609 if (reText.length > 1) { 610 text1 = reText[0]; 611 text2 = reText.splice(1, reText.length - 1); 612 text2 = text2.join(''); 613 } 614 } 615 if (text1.trim() !== "" && text2.trim() !== "") { 616 ctx.fillText(text1.trim(), 7 * center / 8, -(wheel_text_size * 1 / 4)); 617 ctx.fillText(text2.trim(), 7 * center / 8, wheel_text_size * 3 / 4); 618 } else {
619 ctx.fillText(text.replace(/\\n/g, '').replace(/\/n/g, ''), 7 * center / 8, wheel_text_size / 2 - 2); 620 } 621 ctx.restore(); 622 } 623 624 function wlwl_shortcode_spins_wheel($container, stop_position, result_notification, result) { 625 let canvas_1 = $container.find('.wc-lucky-wheel-shortcode-wheel-canvas-1'); 626 let canvas_3 = $container.find('.wc-lucky-wheel-shortcode-wheel-canvas-3'); 627 let default_css = ''; 628 if (window.devicePixelRatio) { 629 default_css = 'width:' + width + 'px;height:' + width + 'px;'; 630 } 631 canvas_1.attr('style', default_css); 632 canvas_3.attr('style', default_css); 633 let stop_deg = 360 - sliceDeg * stop_position; 634 let wheel_stop = wheel_speed * 360 * wlwl_spinning_time + stop_deg; 635 let css = default_css + '-moz-transform: rotate(' + wheel_stop + 'deg);-webkit-transform: rotate(' + wheel_stop + 'deg);-o-transform: rotate(' + wheel_stop + 'deg);-ms-transform: rotate(' + wheel_stop + 'deg);transform: rotate(' + wheel_stop + 'deg);'; 636 css += '-webkit-transition: transform ' + wlwl_spinning_time + 's ease;-moz-transition: transform ' + wlwl_spinning_time + 's ease;-ms-transition: transform ' + wlwl_spinning_time + 's ease;-o-transition: transform ' + wlwl_spinning_time + 's ease;transition: transform ' + wlwl_spinning_time + 's ease;'; 637 canvas_1.attr('style', css); 638 canvas_3.attr('style', css); 639 spinning = true; 640 setTimeout(function () { 641 if (result === 'win' && congratulations_effect === 'firework') { 642 $container.find('.wlwl-congratulations-effect').addClass('wlwl-congratulations-effect-firework'); 643 } 644 $container.find('.wc-lucky-wheel-shortcode-wheel-fields-container').html('<div class="wc-lucky-wheel-shortcode--frontend-result">' + result_notification + '</div>'); 645 $container.find('.wc-lucky-wheel-shortcode-wheel-button-wrap').removeClass('wc-lucky-wheel-shortcode-loading'); 646 css = default_css + 'transform: rotate(' + stop_deg + 'deg);'; 647 canvas_1.attr('style', css); 648 canvas_3.attr('style', css); 649 spinning = false; 650 }, parseInt(wlwl_spinning_time * 1000)) 651 } 652 653 function isValidEmailAddress(emailAddress) { 654 let pattern = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/i; 655 return pattern.test(emailAddress); 656 } 657 658 let spinning = false; 659 660 function validateRecaptcha(response) { 661 if (response) { 662 jQuery('.wlwl-shortcode-recaptcha-field #wlwl-shortcode-g-validate-response').val(response); 663 } 664 } 665 666 function expireRecaptcha() { 667 jQuery('.wlwl-shortcode-recaptcha-field #wlwl-shortcode-g-validate-response').val(null); 668 } 669 670 /* Googele recaptcha */ 671 window.addEventListener('load', function () { 672 if (shortcode_args.wlwl_recaptcha == 'on') { 673 if (shortcode_args.wlwl_recaptcha_version == 2) { 674 wlwlreCaptchaV2Onload(); 675 } else { 676 wlwlreCaptchaV3Onload(); 677 jQuery('.wlwl-shortcode-recaptcha-field').hide(); 678 } 679 } else { 680 jQuery('.wlwl-shortcode-recaptcha-field').hide(); 681 } 682 }); 683 684 function wlwlreCaptchaV3Onload() { 685 grecaptcha.ready(function () { 686 grecaptcha.execute(shortcode_args.wlwl_recaptcha_site_key, {action: 'homepage'}).then(function (token) { 687 validateRecaptcha(token); 688 }) 689 }); 690 } 691 692 function wlwlreCaptchaV2Onload() { 693 if (jQuery.find('.wlwl-shortcode-recaptcha').length == 0 || jQuery.find('.wlwl-shortcode-recaptcha iframe').length) { 694 return true; 695 } 696 grecaptcha.render('wlwl-shortcode-recaptcha', { 697 'sitekey': shortcode_args.wlwl_recaptcha_site_key, 698 'callback': validateRecaptcha, 699 'expired-callback': expireRecaptcha, 700 'theme': shortcode_args.wlwl_recaptcha_secret_theme, 701 'isolated': false 702 }); 703 704 } 705 706 function wlwl_shortcode_check_email() { 707 $container.find('.wc-lucky-wheel-shortcode-wheel-button-wrap').on('click', function () { 708 if (spinning) { 709 return; 710 } 711 $('#wlwl_shortcode_warring_recaptcha').html(''); 712 let $button = $(this); 713 let $error_email = $container.find('.wc-lucky-wheel-shortcode-wheel-field-error-email'); 714 $error_email.html(''); 715 let $email = $container.find('.wc-lucky-wheel-shortcode-wheel-field-email'); 716 let $email_container = $email.closest('.wc-lucky-wheel-shortcode-wheel-field-email-wrap'); 717 let $name = $container.find('.wc-lucky-wheel-shortcode-wheel-field-name'); 718 let $name_container = $name.closest('.wc-lucky-wheel-shortcode-wheel-field-name-wrap'); 719 let $mobile = $container.find('.wc-lucky-wheel-shortcode-wheel-field-mobile'); 720 let $mobile_container = $mobile.closest('.wc-lucky-wheel-shortcode-wheel-field-mobile-wrap'); 721 722 let shortcode_g_validate_response = $('#wlwl-shortcode-g-validate-response').val(); 723 724 $('.wlwl-shortcode-recaptcha-field').removeClass('wc-lucky-wheel-shortcode-required-field'); 725 $email_container.removeClass('wc-lucky-wheel-shortcode-required-field'); 726 $name_container.removeClass('wc-lucky-wheel-shortcode-required-field'); 727 $mobile_container.removeClass('wc-lucky-wheel-shortcode-required-field'); 728 729 if ('on' === gdpr_checkbox && !$('.wc-lucky-wheel-shortcode-wheel-gdpr-wrap input[type="checkbox"]').prop('checked')) { 730 alert(shortcode_args.gdpr_warning); 731 return false; 732 } 733 let wlwl_email = $email.val(); 734 let wlwl_name = $name.val(); 735 let wlwl_mobile = $mobile.val(); 736 let qualified = true; 737 let focus_field; 738 if (shortcode_args.wlwl_recaptcha && shortcode_args.wlwl_recaptcha_site_key && !shortcode_g_validate_response) { 739 $('.wlwl-shortcode-recaptcha-field #wlwl-shortcode-recaptcha > div').addClass('wc-lucky-wheel-shortcode-required-field').focus(); 740 $('#wlwl_shortcode_warring_recaptcha').html(shortcode_args.wlwl_warring_recaptcha); 741 qualified = false; 742 } else if (shortcode_args.wlwl_recaptcha && shortcode_args.wlwl_recaptcha_site_key) { 743 $('.wlwl-shortcode-recaptcha-field #wlwl-shortcode-recaptcha > div').removeClass('wc-lucky-wheel-shortcode-required-field'); 744 qualified = true; 745 } 746 if (!wlwl_email) { 747 $email.prop('disabled', false); 748 focus_field = $email; 749 $error_email.html(shortcode_args.empty_email_warning); 750 $email_container.addClass('wc-lucky-wheel-shortcode-required-field'); 751 qualified = false; 752 } 753 754 if (!isValidEmailAddress(wlwl_email)) { 755 $email.prop('disabled', false); 756 focus_field = $email; 757 $error_email.html(shortcode_args.invalid_email_warning); 758 $email_container.addClass('wc-lucky-wheel-shortcode-required-field'); 759 qualified = false; 760 } 761 if (custom_field_mobile_enable === 'on' && custom_field_mobile_required === 'on' && !wlwl_mobile) { 762 $mobile_container.addClass('wc-lucky-wheel-shortcode-required-field'); 763 $mobile.attr('placeholder', shortcode_args.custom_field_mobile_message); 764 focus_field = $mobile; 765 qualified = false; 766 } 767 if (custom_field_name_enable === 'on' && custom_field_name_required === 'on' && !wlwl_name) { 768 $name_container.addClass('wc-lucky-wheel-shortcode-required-field'); 769 $name.attr('placeholder', shortcode_args.custom_field_name_message); 770 focus_field = $name; 771 qualified = false; 772 } 773 774 if (qualified === false) { 775 focus_field.focus(); 776 return false; 777 } 778 $email.prop('disabled', true); 779 $error_email.html(''); 780 $button.addClass('wc-lucky-wheel-shortcode-loading'); 781 $.ajax({
782 type: 'post', 783 dataType: 'json', 784 url: shortcode_args.ajaxurl, 785 data: { 786 user_email: wlwl_email, 787 user_name: wlwl_name, 788 user_mobile: wlwl_mobile, 789 language: shortcode_args.language, 790 g_validate_response: shortcode_g_validate_response, 791 _woocommerce_lucky_wheel_nonce: $('#_woocommerce_lucky_wheel_nonce').val(), 792 }, 793 success: function (response) { 794 if (response.allow_spin === 'yes') { 795 wlwl_shortcode_spins_wheel($container, response.stop_position, response.result_notification, response.result); 796 } else { 797 $button.removeClass('wc-lucky-wheel-shortcode-loading'); 798 $email.prop('disabled', false); 799 alert(response.allow_spin); 800 } 801 } 802 }); 803 }); 804 } 805 806 wlwl_shortcode_check_email(); 807 let center1 = 32; 808 for (let i = 0; i < slices; i++) { 809 wlwl_shortcode_drawSlice(deg, color[i]); 810 wlwl_shortcode_drawText(deg + sliceDeg / 2, label[i], slices_text_color[i]); 811 deg += sliceDeg; 812 813 } 814 cv = $container.find('.wc-lucky-wheel-shortcode-wheel-canvas-2')[0]; 815 ctx = cv.getContext('2d'); 816 cv.width = width; 817 cv.height = width; 818 if (window.devicePixelRatio) { 819 let hidefCanvasWidth = $(cv).attr('width'); 820 let hidefCanvasHeight = $(cv).attr('height'); 821 let hidefCanvasCssWidth = hidefCanvasWidth; 822 let hidefCanvasCssHeight = hidefCanvasHeight; 823 824 $(cv).attr('width', hidefCanvasWidth * window.devicePixelRatio); 825 $(cv).attr('height', hidefCanvasHeight * window.devicePixelRatio); 826 $(cv).css('width', hidefCanvasCssWidth); 827 $(cv).css('height', hidefCanvasCssHeight); 828 ctx.scale(window.devicePixelRatio, window.devicePixelRatio); 829 } 830 wlwl_shortcode_drawPoint(deg, wlwl_center_color); 831 if (center_image) { 832 let wl_image = new Image; 833 wl_image.onload = function () { 834 cv = $container.find('.wc-lucky-wheel-shortcode-wheel-canvas-2')[0]; 835 ctx = cv.getContext('2d'); 836 let image_size = 2 * (width / 8 - 7); 837 ctx.arc(center, center, image_size / 2, 0, 2 * Math.PI); 838 ctx.clip(); 839 ctx.drawImage(wl_image, center - image_size / 2, center - image_size / 2, image_size, image_size); 840 841 }; 842 wl_image.src = center_image; 843 } 844 845 if (width <= 480) { 846 wlwl_shortcode_drawBorder(wlwl_border_color, 'rgba(0,0,0,0)', 8, 3, 4, 'rgba(0,0,0,0.2)'); 847 } else { 848 wlwl_shortcode_drawBorder(wlwl_border_color, 'rgba(0,0,0,0)', 16, 6, 7, 'rgba(0,0,0,0.2)'); 849 } 850 cv = $container.find('.wc-lucky-wheel-shortcode-wheel-canvas-3')[0]; 851 ctx = cv.getContext('2d'); 852 853 cv.width = width; 854 cv.height = width; 855 if (window.devicePixelRatio) { 856 let hidefCanvasWidth = $(cv).attr('width'); 857 let hidefCanvasHeight = $(cv).attr('height'); 858 let hidefCanvasCssWidth = hidefCanvasWidth; 859 let hidefCanvasCssHeight = hidefCanvasHeight; 860 861 $(cv).attr('width', hidefCanvasWidth * window.devicePixelRatio); 862 $(cv).attr('height', hidefCanvasHeight * window.devicePixelRatio); 863 $(cv).css('width', hidefCanvasCssWidth); 864 $(cv).css('height', hidefCanvasCssHeight); 865 ctx.scale(window.devicePixelRatio, window.devicePixelRatio); 866 } 867 if (width <= 480) { 868 wlwl_shortcode_drawBorder('rgba(0,0,0,0)', wlwl_dot_color, 8, 3, 4, 'rgba(0,0,0,0)'); 869 } else { 870 wlwl_shortcode_drawBorder('rgba(0,0,0,0)', wlwl_dot_color, 16, 6, 7, 'rgba(0,0,0,0)'); 871 } 872 }) 873});
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.