Prototype JS Bug – Solutions and Fixes

prototype-js

In the admin zone, when i open the firebug I'm getting this erros message:

TypeError: registry is undefined
var respondersForEvent = registry.get(eventName);

this errors message appears in prototype.js file.
The error disappears when i added this line :

if (element === null) return;

after the function:

function _createResponder(element, eventName, handler) {
    if (element === null) return;
    var registry = Element.retrieve(element, 'prototype_event_registry');

    if (Object.isUndefined(registry)) {
      CACHE.push(element);
      registry = Element.retrieve(element, 'prototype_event_registry', $H());
    }

    var respondersForEvent = registry.get(eventName);
    if (Object.isUndefined(respondersForEvent)) {
      respondersForEvent = [];
      registry.set(eventName, respondersForEvent);
    }....

What i don't understand if this line of code affects in any way the magento functionalities?
and what does this function actually do ?

Best Answer

Adding the line of code you did will prevent the error from happening, but whatever is triggering that is trying to do so on an element that does not exist, so nothing would have happened anyway.

This block of code creates the event observers when you call $('element').observe('event',function(){});

Since this is from the 1.7 version of PrototypeJS the actual DOM element object is passed into the method to register the event to that DOM element. In all the later versions (1.7.1,1.7.2) only an internal reference ID is passed into this method which is safer and more resource friendly.