Skip to content

Commit

Permalink
Increase compatibility in addEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianheine committed Sep 16, 2011
1 parent 7827dd2 commit 1c04390
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions lib/scripts/compatibility.js
Expand Up @@ -187,8 +187,29 @@ function prependChild(parent,element) {
}

function addEvent(element, type, handler) {
DEPRECATED('Use jQuery.bind() instead.');
jQuery(element).bind(type,{},handler);
DEPRECATED('Use jQuery.bind() instead. Note that jQuery’s behaviour' +
' when a handler returns false differs from addEvent’s');
jQuery(element).bind(type,{},function (e) {
// returning false in an addEvent event handler did not prevent
// bubbling but just canceled handlers on this node and prevented
// default behavior, so wrap the handler call and mimic that behavior.
//
// Refer to jQuery.event.handle().
var ret = handler.apply(this, Array.prototype.slice.call(arguments, 0));
if (typeof ret !== 'undefined') {
if ( ret !== false ) {
return ret;
}
// What jQuery does.
e.result = ret;
e.preventDefault();
// Not what jQuery does. This would be: event.stopPropagation();
// Hack it so that immediate propagation (other event handlers on
// this element) appears stopped without stopping the actual
// propagation (bubbling)
e.isImmediatePropagationStopped = function () { return true; };
}
});
}

function removeEvent(element, type, handler) {
Expand Down

0 comments on commit 1c04390

Please sign in to comment.