prototypejs / prototype

Prototype JavaScript framework
http://prototypejs.org/
Other
3.54k stars 640 forks source link

small fix in "createResponder" function #181

Closed jwestbrook closed 9 years ago

jwestbrook commented 10 years ago

previous lighthouse ticket #1477 by Aliaksandr Sebiashuk


we use some ActiveX component to trace phone calls in our Callcenter web client.

this component throws events with many paramethers and I have to fix every new prototype.js to make it works. so I have decides what other customers can have the same problems and this fix can be included in next version of the bibliothek.

so, what is it all about:

in the createResponder function is an "event handler" function returned. this function has only one paramether an "event". to make this function more useful, we can check the first paramether type und if it not an object, pass all arguments further.

function createResponder(uid, eventName, handler) {

if (Event._isCustomEvent(eventName))
  return createResponderForCustomEvent(uid, eventName, handler);
if (isSimulatedMouseEnterLeaveEvent(eventName))
  return createMouseEnterLeaveResponder(uid, eventName, handler);

return function(event) {
  var cacheEntry = Event.cache[uid];
  var element = cacheEntry.element;
//ASE. check if type of the first paramether is not an object, then it is the "many paramether" event handler. in this case pass all arguments further.

  var args;
            if(typeof(event) != 'object') {
                args = arguments;
            } else {
                args = event;
    }     

  Event.extend(args, element);
  handler.call(element, args);
};
}