summaryrefslogtreecommitdiff
path: root/lib/scripts
diff options
context:
space:
mode:
authorAdrian Lang <lang@cosmocode.de>2011-09-16 14:20:47 +0200
committerAdrian Lang <lang@cosmocode.de>2011-09-16 14:20:47 +0200
commit1c04390c3b7c331cf85c4fa21c8c52212c15d903 (patch)
treee1b12fa5a0580bb5f241f5bb20ec2d84e127df7c /lib/scripts
parent7827dd2afcb37599610894016f2e1e6150e561b7 (diff)
downloadrpg-1c04390c3b7c331cf85c4fa21c8c52212c15d903.tar.gz
rpg-1c04390c3b7c331cf85c4fa21c8c52212c15d903.tar.bz2
Increase compatibility in addEvent
Diffstat (limited to 'lib/scripts')
-rw-r--r--lib/scripts/compatibility.js25
1 files changed, 23 insertions, 2 deletions
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) {