Work around module loading issue in `WCF.System.Captcha.getData()`
authorMatthias Schmidt <gravatronics@live.com>
Mon, 14 Aug 2017 15:13:57 +0000 (17:13 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Mon, 14 Aug 2017 15:13:57 +0000 (17:13 +0200)
wcfsetup/install/files/js/WCF.js

index f70c1706db443beddcb293774be5d99739395594..ee51887997b29b047e0519f940ed8d28df3db519 100755 (executable)
@@ -4734,6 +4734,12 @@ WCF.System.ObjectStore = {
  * Stores captcha callbacks used for captchas in AJAX contexts.
  */
 WCF.System.Captcha = {
+       /**
+        * ids of registered captchas
+        * @var {string[]}
+        */
+       _registeredCaptchas: [],
+       
        /**
         * Adds a callback for a certain captcha.
         * 
@@ -4744,6 +4750,8 @@ WCF.System.Captcha = {
                require(['WoltLabSuite/Core/Controller/Captcha'], function(ControllerCaptcha) {
                        try {
                                ControllerCaptcha.add(captchaID, callback);
+                               
+                               this._registeredCaptchas.push(captchaID);
                        }
                        catch (e) {
                                if (e instanceof TypeError) {
@@ -4753,7 +4761,7 @@ WCF.System.Captcha = {
                                
                                // ignore other errors
                        }
-               });
+               }.bind(this));
        },
        
        /**
@@ -4764,6 +4772,10 @@ WCF.System.Captcha = {
        getData: function(captchaID) {
                var returnValue;
                
+               if (this._registeredCaptchas.indexOf(captchaID) === -1) {
+                       return returnValue;
+               }
+               
                var ControllerCaptcha = require('WoltLabSuite/Core/Controller/Captcha');
                try {
                        returnValue = ControllerCaptcha.getData(captchaID);
@@ -4782,11 +4794,13 @@ WCF.System.Captcha = {
                require(['WoltLabSuite/Core/Controller/Captcha'], function(ControllerCaptcha) {
                        try {
                                ControllerCaptcha.delete(captchaID);
+                               
+                               this._registeredCaptchas.splice(this._registeredCaptchas.indexOf(item), 1);
                        }
                        catch (e) {
                                // ignore errors for unknown captchas
                        }
-               });
+               }.bind(this));
        }
 };