[Pkg-javascript-commits] [dojo] 16/19: Refs #18168. Rework dojo/on's way to decide about using event delegation. Now uses feature detection, which fixes the event handling currently broken on Safari iOS 8 beta

David Prévot taffit at moszumanska.debian.org
Sun Sep 14 16:23:09 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to annotated tag 1.8.7
in repository dojo.

commit 2ab96e496725dce3fc02e2745a2c945ec9f0016a
Author: Adrian Vasiliu <vasiliu at fr.ibm.com>
Date:   Fri Aug 29 14:48:02 2014 +0200

    Refs #18168. Rework dojo/on's way to decide about using event delegation. Now uses feature detection, which fixes the event handling currently broken on Safari iOS 8 beta
---
 on.js | 44 +++++++++++++++++++++++++++++++++++---------
 1 file changed, 35 insertions(+), 9 deletions(-)

diff --git a/on.js b/on.js
index 6db1310..9fcef2f 100644
--- a/on.js
+++ b/on.js
@@ -9,6 +9,30 @@ define(["./has!dom-addeventlistener?:./aspect", "./_base/kernel", "./has"], func
 		has.add("event-focusin", function(global, doc, element){
 			return 'onfocusin' in element;
 		});
+		
+		if(has("touch")){
+			has.add("touch-can-modify-event-delegate", function(){
+				// This feature test checks whether deleting a property of an event delegate works
+				// for a touch-enabled device. If it works, event delegation can be used as fallback
+				// for browsers such as Safari in older iOS where deleting properties of the original
+				// event does not work.
+				var EventDelegate = function(){};
+				EventDelegate.prototype =
+					document.createEvent("MouseEvents"); // original event
+				// Attempt to modify a property of an event delegate and check if
+				// it succeeds. Depending on browsers and on whether dojo/on's
+				// strict mode is stripped in a Dojo build, there are 3 known behaviors:
+				// it may either succeed, or raise an error, or fail to set the property
+				// without raising an error.
+				try{
+					var eventDelegate = new EventDelegate;
+					eventDelegate.target = null;
+					return eventDelegate.target === null;
+				}catch(e){
+					return false; // cannot use event delegation
+				}
+			});
+		}
 	}
 	var on = function(target, type, listener, dontFix){
 		// summary:
@@ -451,7 +475,7 @@ define(["./has!dom-addeventlistener?:./aspect", "./_base/kernel", "./has"], func
 		};
 	}
 	if(has("touch")){ 
-		var Event = function(){};
+		var EventDelegate = function(){};
 		var windowOrientation = window.orientation; 
 		var fixTouchListener = function(listener){ 
 			return function(originalEvent){ 
@@ -468,17 +492,19 @@ define(["./has!dom-addeventlistener?:./aspect", "./_base/kernel", "./has"], func
 						delete originalEvent.type; // on some JS engines (android), deleting properties make them mutable
 					}catch(e){} 
 					if(originalEvent.type){
-						// deleting properties doesn't work (older iOS), have to use delegation
-						if(has('mozilla')){
-							// Firefox doesn't like delegated properties, so we have to copy
-							var event = {};
+						// Deleting the property of the original event did not work (this is the case of
+						// browsers such as older Safari iOS), hence fallback:
+						if(has("touch-can-modify-event-delegate")){
+							// If deleting properties of delegated event works, use event delegation:
+							EventDelegate.prototype = originalEvent;
+							event = new EventDelegate;
+						}else{
+							// Otherwise last fallback: other browsers, such as mobile Firefox, do not like
+							// delegated properties, so we have to copy
+							event = {};
 							for(var name in originalEvent){
 								event[name] = originalEvent[name];
 							}
-						}else{
-							// old iOS branch
-							Event.prototype = originalEvent;
-							var event = new Event;
 						}
 						// have to delegate methods to make them work
 						event.preventDefault = function(){

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/dojo.git



More information about the Pkg-javascript-commits mailing list