[Pkg-javascript-commits] [dojo] 11/21: Fixes #17228 on branch 1.9

David Prévot taffit at moszumanska.debian.org
Thu Aug 21 17:39:53 UTC 2014


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

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

commit 9415f036b79e5b66a963bdc63f8e20833e09d970
Author: Sebastien Brunot <sbrunot at gmail.com>
Date:   Fri Oct 25 12:36:41 2013 +0200

    Fixes #17228 on branch 1.9
---
 tests/test_touch.html | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++
 touch.js              | 18 ++++++++------
 2 files changed, 78 insertions(+), 7 deletions(-)

diff --git a/tests/test_touch.html b/tests/test_touch.html
index 6eb0fe0..57b7224 100644
--- a/tests/test_touch.html
+++ b/tests/test_touch.html
@@ -24,6 +24,18 @@
 				border: 1px solid yellow;
 				background-color: yellow;
 			}
+			#test3 {
+				width: 300px;
+				height: 150px;
+				border: 1px solid red;
+				background-color: red;      
+			}
+			#innertest3 {
+				border: 1px solid white;
+				width: 250px;
+				height: 75px;
+				background-color: white;
+			}
 			#current, #log {
 				width: 300px;
 				height: 200px;
@@ -110,6 +122,22 @@
 //					on(node, "touchcancel", action);
 //					on(node, "orientationchange", action);
 
+				dom.byId("test3").dojoClick = true;
+				on(dom.byId("test3"), "click", function(e){
+					if(has("touch")){
+						// click should be a synthetic click
+						dom.byId("log").innerHTML = (e._dojo_click ? "Synthetic click received in test3" : "ERROR: native click received in test3") + "<br/>" + dom.byId("log").innerHTML;
+					}else{
+						// click should be a native click
+						dom.byId("log").innerHTML = (e._dojo_click ? "ERROR: Synthetic click received in test3 (non touch device)" : "Native click received in test3  (non touch device)") + "<br/>" + dom.byId("log").innerHTML;
+					}
+				});
+				dom.byId("innertest3").dojoClick = false;
+				on(dom.byId("innertest3"), "click", function(e){
+					// click should be a native click
+					dom.byId("log").innerHTML = (e._dojo_click ? "ERROR: Synthetic click received in innertest3" : "Native click received in innertest3") + "<br/>" + dom.byId("log").innerHTML;;
+					e.stopPropagation();
+				});
 
 				/**
 				 * Fires an event.  All coordinates are defaulted to zero.
@@ -286,6 +314,39 @@
 						}
 					}
 
+					if(has("touch")){
+						doh.registerTest("synthetic clicks", {
+			                name: "Synthetic click disabled",
+			                timeout: 1000,
+			                runTest: function(){
+								/**
+								 * check that synthetic click is NOT fired when dojoClick value is set
+								 * to falsy on a dom element and touch is released inside the element.
+								 * Note that synthetic click is fired ONLY on touch enabled devices (touch or MSPointer).
+								 */
+								var domEltWithDisabledSyntheticClick = dom.byId("innertest3");
+								var box = domEltWithDisabledSyntheticClick.getBoundingClientRect(); // position in viewport coordinates
+								var coordInsideEltWithDisabledSyntheticClick = {x: box.right - box.left, y:box.bottom - box.top};
+								var clicked = false;
+								// register the click handler
+								function listener(e){
+									alert("click fired ??");
+									clicked = true;
+								}
+								domEltWithDisabledSyntheticClick.addEventListener("click", listener);
+								// emit "touchstart" and "touchend" events inside the element
+								emit(domEltWithDisabledSyntheticClick, "touchstart", {screenX: coordInsideEltWithDisabledSyntheticClick.x, screenY: coordInsideEltWithDisabledSyntheticClick.y});
+								emit(domEltWithDisabledSyntheticClick, "touchend", {screenX: coordInsideEltWithDisabledSyntheticClick.x, screenY: coordInsideEltWithDisabledSyntheticClick.y});
+								var deferred = new doh.Deferred();
+								// without deferred the click handler is called after the doh method ends.
+								setTimeout(deferred.getTestCallback(function(){
+									doh.t(!clicked, 'synthetic click fired');
+								}), 0);
+								return deferred;
+			                }
+						});
+					}
+
 					doh.run();
 				});
 			});
@@ -301,6 +362,12 @@
 		<div id="test2">
 			touch.move
 		</div>
+		<div id="test3">
+			On touch devices, synthetic clicks are enabled in this area.
+			<div id="innertest3">
+				On touch devices, synthetic clicks disabled in this area.
+			</div>
+		</div>
 		<div id="dohDiv">doh</div>
 		<div id="current"></div>
 		<div id="log"></div>
diff --git a/touch.js b/touch.js
index f0dd154..a056772 100644
--- a/touch.js
+++ b/touch.js
@@ -51,7 +51,7 @@ function(dojo, aspect, dom, domClass, lang, on, has, mouse, domReady, win){
 	function marked(/*DOMNode*/ node){
 		// Test if a node or its ancestor has been marked with the dojoClick property to indicate special processing,
 		do{
-			if(node.dojoClick){ return node.dojoClick; }
+			if(node.dojoClick !== undefined){ return node.dojoClick; }
 		}while(node = node.parentNode);
 	}
 	
@@ -60,7 +60,9 @@ function(dojo, aspect, dom, domClass, lang, on, has, mouse, domReady, win){
 		//		Setup touch listeners to generate synthetic clicks immediately (rather than waiting for the browser
 		//		to generate clicks after the double-tap delay) and consistently (regardless of whether event.preventDefault()
 		//		was called in an event listener. Synthetic clicks are generated only if a node or one of its ancestors has
-		//		its dojoClick property set to truthy.
+		//      its dojoClick property set to truthy. If a node receives synthetic clicks because one of its ancestors has its
+		//      dojoClick property set to truthy, you can disable synthetic clicks on this node by setting its own dojoClick property
+		//      to falsy.
 		
 		clickTracker  = !e.target.disabled && marked(e.target); // click threshold = true, number or x/y object
 		if(clickTracker){
@@ -260,10 +262,10 @@ function(dojo, aspect, dom, domClass, lang, on, has, mouse, domReady, win){
 		//		This module provides unified touch event handlers by exporting
 		//		press, move, release and cancel which can also run well on desktop.
 		//		Based on http://dvcs.w3.org/hg/webevents/raw-file/tip/touchevents.html
-		//		Also, if the dojoClick property is set to true on a DOM node, dojo/touch generates
-		//		click events immediately for this node and its descendants, to avoid the
-		//		delay before native browser click events, and regardless of whether evt.preventDefault()
-		//		was called in a touch.press event listener.
+		//      Also, if the dojoClick property is set to truthy on a DOM node, dojo/touch generates
+		//      click events immediately for this node and its descendants (except for descendants that
+		//      have a dojoClick property set to falsy), to avoid the delay before native browser click events,
+		//      and regardless of whether evt.preventDefault() was called in a touch.press event listener.
 		//
 		// example:
 		//		Used with dojo/on
@@ -287,7 +289,9 @@ function(dojo, aspect, dom, domClass, lang, on, has, mouse, domReady, win){
 		// example:
 		//		Have dojo/touch generate clicks without delay, with a move threshold of 50 pixels horizontally and 10 pixels vertically
 		//		|	node.dojoClick = {x:50, y:5};
-		
+		// example:
+		//    Disable clicks without delay generated by dojo/touch on a node that has an ancestor with property dojoClick set to truthy
+		//    |  node.dojoClick = false;		
 
 		press: function(node, listener){
 			// 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