|
516 | 516 | name: 'recaptcha', |
517 | 517 | validatorFunction: function (val, $el) |
518 | 518 | { |
519 | | - return grecaptcha.getResponse($el.data('validation-recaptcha-widget-id')); |
| 519 | + return grecaptcha.getResponse($el.valAttr('recaptcha-widgetId')); |
520 | 520 | }, |
521 | 521 | errorMessage: '', |
522 | 522 | errorMessageKey: 'badreCaptcha' |
|
529 | 529 |
|
530 | 530 | var setupGooglereCaptcha = function (evt, $forms, config) |
531 | 531 | { |
532 | | - if( typeof grecaptcha !== typeof undefined ){ |
| 532 | + if( typeof grecaptcha !== typeof undefined && !$.formUtils.hasLoadedGrecaptcha ){ |
533 | 533 | throw new Error('reCaptcha API can not be loaded by hand, delete reCaptcha API snippet.'); |
534 | | - } |
535 | | - |
536 | | - var src = '//www.google.com/recaptcha/api.js?onload=reCaptchaLoaded&render=explicit' + (config.lang ? '&hl=' + config.lang : ''); |
537 | | - if ($('body').find('script[src="' + src + '"]').length === 0) |
| 534 | + } else if(!$.formUtils.hasLoadedGrecaptcha) |
538 | 535 | { |
| 536 | + $.formUtils.hasLoadedGrecaptcha = true; |
| 537 | + |
| 538 | + var src = '//www.google.com/recaptcha/api.js?onload=reCaptchaLoaded&render=explicit' + (config.lang ? '&hl=' + config.lang : ''); |
539 | 539 | var script = document.createElement('script'); |
540 | 540 | script.type = 'text/javascript'; |
541 | 541 | script.async = true; |
|
557 | 557 | $forms.each(function () |
558 | 558 | { |
559 | 559 | var $form = $(this), |
560 | | - config = $form.context.validationConfig, |
561 | | - theme = config.reCaptchaTheme; |
| 560 | + config = $form.context.validationConfig; |
562 | 561 |
|
563 | 562 | $('[data-validation~="recaptcha"]', $form).each(function () |
564 | 563 | { |
565 | 564 | var $el = $(this), |
566 | 565 | div = document.createElement('DIV'), |
567 | | - sitekey = config.reCaptchaSiteKey || $el.valAttr('recaptcha-sitekey'); |
| 566 | + siteKey = config.reCaptchaSiteKey || $el.valAttr('recaptcha-sitekey'), |
| 567 | + theme = config.reCaptchaTheme || $el.valAttr('recaptcha-theme') || 'light'; |
568 | 568 |
|
569 | | - if( !sitekey ){ |
| 569 | + if( !siteKey ){ |
570 | 570 | throw new Error('Google reCaptcha site key is required.'); |
571 | 571 | } |
572 | 572 |
|
573 | 573 | $el.hide(); |
574 | 574 | $el.parent().append(div); |
575 | 575 |
|
576 | | - var widget_id = grecaptcha.render(div, { |
577 | | - sitekey: sitekey, |
578 | | - theme: theme || $el.valAttr('recaptcha-theme') || 'light' |
| 576 | + var widgetId = grecaptcha.render(div, { |
| 577 | + sitekey: siteKey, |
| 578 | + theme: theme |
579 | 579 | }); |
580 | 580 |
|
581 | 581 | $el |
582 | | - .data('validation-recaptcha-widget-id', widget_id); |
| 582 | + .valAttr('recaptcha-widgetId', widgetId); |
583 | 583 | }); |
584 | 584 |
|
585 | 585 | }); |
|
0 commit comments