[Pkg-javascript-commits] [dojo] 62/88: backport [30397] and [30398] to 1.8 branch, to support machines with both touch and mouse, fixes #13048 on 1.8 branch !strict
David Prévot
taffit at moszumanska.debian.org
Thu Aug 21 17:39:39 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to annotated tag 1.8.5
in repository dojo.
commit 62edc04b442f0560359229361c778b7205dad804
Author: Bill Keese <bill at dojotoolkit.org>
Date: Fri Jan 25 06:55:14 2013 +0000
backport [30397] and [30398] to 1.8 branch, to support machines with both touch and mouse, fixes #13048 on 1.8 branch !strict
git-svn-id: http://svn.dojotoolkit.org/src/branches/1.8/dojo@30449 560b804f-0ae3-0310-86f3-f6aa0a117693
---
touch.js | 65 ++++++++++++++++++++++++++++++++++++++++++++--------------------
1 file changed, 45 insertions(+), 20 deletions(-)
diff --git a/touch.js b/touch.js
index 586ed19..e4e57d7 100644
--- a/touch.js
+++ b/touch.js
@@ -1,5 +1,5 @@
-define(["./_base/kernel", "./aspect", "./dom", "./on", "./has", "./mouse", "./ready", "./_base/window"],
-function(dojo, aspect, dom, on, has, mouse, ready, win){
+define(["./_base/kernel", "./aspect", "./dom", "./on", "./has", "./mouse", "./domReady", "./_base/window"],
+function(dojo, aspect, dom, on, has, mouse, domReady, win){
// module:
// dojo/touch
@@ -15,14 +15,45 @@ function(dojo, aspect, dom, on, has, mouse, ready, win){
ios4 = os < 5;
}
+ // Time of most recent touchstart or touchmove event
+ var lastTouch;
+
+ function dualEvent(mouseType, touchType){
+ // Returns synthetic event that listens for both the specified mouse event and specified touch event.
+ // But ignore fake mouse events that were generated due to the user touching the screen.
+ if(hasTouch){
+ return function(node, listener){
+ var handle1 = on(node, touchType, listener),
+ handle2 = on(node, mouseType, function(evt){
+ if(!lastTouch || (new Date()).getTime() > lastTouch + 1000){
+ listener.call(this, evt);
+ }
+ });
+ return {
+ remove: function(){
+ handle1.remove();
+ handle2.remove();
+ }
+ };
+ };
+ }else{
+ // Avoid creating listeners for touch events on performance sensitive older browsers like IE6
+ return function(node, listener){
+ return on(node, mouseType, listener);
+ }
+ }
+ }
+
var touchmove, hoveredNode;
if(hasTouch){
- ready(function(){
+ domReady(function(){
// Keep track of currently hovered node
hoveredNode = win.body(); // currently hovered node
win.doc.addEventListener("touchstart", function(evt){
+ lastTouch = (new Date()).getTime();
+
// Precede touchstart event with touch.over event. DnD depends on this.
// Use addEventListener(cb, true) to run cb before any touchstart handlers on node run,
// and to ensure this code runs even if the listener on the node does event.stop().
@@ -42,6 +73,8 @@ function(dojo, aspect, dom, on, has, mouse, ready, win){
// Fire synthetic touchover and touchout events on nodes since the browser won't do it natively.
on(win.doc, "touchmove", function(evt){
+ lastTouch = (new Date()).getTime();
+
var newNode = win.doc.elementFromPoint(
evt.pageX - (ios4 ? 0 : win.global.pageXOffset), // iOS 4 expects page coords
evt.pageY - (ios4 ? 0 : win.global.pageYOffset)
@@ -79,26 +112,18 @@ function(dojo, aspect, dom, on, has, mouse, ready, win){
}
- function _handle(type){
- // type: String
- // press | move | release | cancel
-
- return function(node, listener){//called by on(), see dojo.on
- return on(node, type, listener);
- };
- }
-
//device neutral events - touch.press|move|release|cancel/over/out
var touch = {
- press: _handle(hasTouch ? "touchstart": "mousedown"),
- move: hasTouch ? touchmove :_handle("mousemove"),
- release: _handle(hasTouch ? "touchend": "mouseup"),
- cancel: hasTouch ? _handle("touchcancel") : mouse.leave,
- over: _handle(hasTouch ? "dojotouchover": "mouseover"),
- out: _handle(hasTouch ? "dojotouchout": "mouseout"),
- enter: mouse._eventHandler(hasTouch ? "dojotouchover" : "mouseover"),
- leave: mouse._eventHandler(hasTouch ? "dojotouchout" : "mouseout")
+ press: dualEvent("mousedown", "touchstart"),
+ move: dualEvent("mousemove", touchmove),
+ release: dualEvent("mouseup", "touchend"),
+ cancel: dualEvent(mouse.leave, "touchcancel"),
+ over: dualEvent("mouseover", "dojotouchover"),
+ out: dualEvent("mouseout", "dojotouchout"),
+ enter: mouse._eventHandler(dualEvent("mouseover","dojotouchover")),
+ leave: mouse._eventHandler(dualEvent("mouseout", "dojotouchout"))
};
+
/*=====
touch = {
// summary:
--
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