Last active
August 8, 2024 10:04
-
-
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 <[email protected]> | |
* @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); | |
} | |
}); |
In case someone needs because of TypeError: undefined is not an object
bind: function (bind) {
const args = Array.from(arguments)
if ((new Error()).stack.match(/recaptcha/)) {
return this._polybind.apply(this, args)
}
return this._compatbind.apply(this, args)
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Now this error appears:
TypeError: Properties can only be defined on Objects.