Last active
November 16, 2023 10:47
-
-
Save sleemanj/f076ed2c0b887ab08074b55dad2fd636 to your computer and use it in GitHub Desktop.
Fix for Mootools 1.3 with 1.2 compatibility layer to work with Recaptcha due to bind being incorrect with 1.2 compatibility enabled.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Quick Dirty Patch for Recaptcha with Mootools 1.2 Compatability Layer | |
* | |
* Make sure that all your mootools core/more source is loaded before this | |
* fix is loaded. | |
* | |
* @author James Sleeman <james@gogo.co.nz> | |
* @see https://github.com/google/recaptcha/issues/374 | |
* | |
*/ | |
// Grab the Mootools 1.2 Compatability bind which mootools replaced | |
Function.prototype._compatbind = Function.prototype.bind; | |
// Remove it from the Function prototype | |
delete Function.prototype.bind; | |
Function.implement({ | |
// This is the "polyfill" bind from Mootools 1.3 it should work the same | |
// as the actual native bind | |
_polybind: function(bind){ | |
var self = this, | |
args = (arguments.length > 1) ? Array.slice(arguments, 1) : null; | |
return function(){ | |
if (!args && !arguments.length) return self.call(bind); | |
if (args && arguments.length) return self.apply(bind, args.concat(Array.from(arguments))); | |
return self.apply(bind, args || arguments); | |
}; | |
}, | |
// Now if recaptcha calls bind, delegate to the polyfill one | |
// and if anything else calls bind delegate o the 1.2 compatability bind | |
// as was previously the case | |
bind: function(bind, args){ | |
if( (new Error()).stack.match(/recaptcha/) ) | |
{ | |
return this._polybind(bind, args); | |
} | |
return this._compatbind(bind, args); | |
} | |
}); |
Hi Sleemanj,
Thank you for posting the fix for mootools with recaptcha. It worked to get recpatcha to load. Only problem is now I am unable to submit form. Do you know what might cause this?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For anyone still supporting IE 11 this doesn't quite work as IE 11 doesn't initialise the Error().stack until the error is thrown. This change works: