From 230f29d0a78a04a6963514da8b1e34cc03e553d0 Mon Sep 17 00:00:00 2001 From: Vojta Jina Date: Thu, 23 Feb 2012 23:41:41 -0800 Subject: [PATCH] fix(jqLite): set event's monkey patched methods to null (on IE7) --- src/jqLite.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/jqLite.js b/src/jqLite.js index 8d9ce09cf227..f32aeaad96f0 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -474,11 +474,13 @@ function createEventHandler(element) { event.returnValue = false; //ie }; } + if (!event.stopPropagation) { event.stopPropagation = function() { event.cancelBubble = true; //ie }; } + if (!event.target) { event.target = event.srcElement || document; } @@ -502,10 +504,17 @@ function createEventHandler(element) { // Remove monkey-patched methods (IE), // as they would cause memory leaks in IE8. - // It shouldn't affect normal browsers, as their native methods are defined on prototype. - delete event.preventDefault; - delete event.stopPropagation; - delete event.isDefaultPrevented; + if (msie < 8) { + // IE7 does not allow to delete property on native object + event.preventDefault = null; + event.stopPropagation = null; + event.isDefaultPrevented = null; + } else { + // It shouldn't affect normal browsers (native methods are defined on prototype). + delete event.preventDefault; + delete event.stopPropagation; + delete event.isDefaultPrevented; + } }; eventHandler.fns = []; return eventHandler;