[Pkg-javascript-commits] [dojo] 04/21: 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 15:39:21 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository dojo.
commit 0e056aba5644267da8eeff427ff12cfa0fc6317f
Author: Adrian Vasiliu <vasiliu at fr.ibm.com>
Date: Wed Jul 30 21:42:40 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 | 41 +++++++++++++++++++++++++++++++----------
1 file changed, 31 insertions(+), 10 deletions(-)
diff --git a/on.js b/on.js
index 2f53965..419ff24 100644
--- a/on.js
+++ b/on.js
@@ -9,6 +9,25 @@ define(["./has!dom-addeventlistener?:./aspect", "./_base/kernel", "./sniff"], fu
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
+ try{
+ // Attempt to modify a property of an event delegate:
+ (new EventDelegate).target = null;
+ return true; // can use event delegation
+ }catch(e){
+ return false; // cannot use event delegation
+ }
+ });
+ }
}
var on = function(target, type, listener, dontFix){
// summary:
@@ -495,7 +514,7 @@ define(["./has!dom-addeventlistener?:./aspect", "./_base/kernel", "./sniff"], fu
};
}
if(has("touch")){
- var Event = function(){};
+ var EventDelegate = function(){};
var windowOrientation = window.orientation;
var fixTouchListener = function(listener){
return function(originalEvent){
@@ -509,20 +528,22 @@ define(["./has!dom-addeventlistener?:./aspect", "./_base/kernel", "./sniff"], fu
if(!event){
var type = originalEvent.type;
try{
- delete originalEvent.type; // on some JS engines (android), deleting properties make them mutable
+ delete originalEvent.type; // on some JS engines (android), deleting properties makes 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