Skip to content

Instantly share code, notes, and snippets.

@sleemanj
Last active August 8, 2024 10:04
Show Gist options
  • Save sleemanj/f076ed2c0b887ab08074b55dad2fd636 to your computer and use it in GitHub Desktop.
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.
/* 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);
}
});
@rasho62
Copy link

rasho62 commented Aug 6, 2021

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?

@tinodj
Copy link

tinodj commented May 9, 2024

Now this error appears:

TypeError: Properties can only be defined on Objects.

@Magnum5234
Copy link

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