From 1c04390c3b7c331cf85c4fa21c8c52212c15d903 Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Fri, 16 Sep 2011 14:20:47 +0200 Subject: Increase compatibility in addEvent --- lib/scripts/compatibility.js | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'lib/scripts/compatibility.js') diff --git a/lib/scripts/compatibility.js b/lib/scripts/compatibility.js index 46cb6ccc2..ea52153c5 100644 --- a/lib/scripts/compatibility.js +++ b/lib/scripts/compatibility.js @@ -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) { -- cgit v1.2.3