[Pkg-javascript-commits] [dojo] 97/149: Fix dojo/touch to not break native checkbox and radio on iOS and Android when dojoClick=true. Fixes #18352

David Prévot taffit at moszumanska.debian.org
Sat Feb 27 03:13:52 UTC 2016


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

taffit pushed a commit to branch master
in repository dojo.

commit 961860c16a70204097718f0d65d0fc1afafcfb40
Author: Adrian Vasiliu <vasiliu at fr.ibm.com>
Date:   Tue Nov 3 14:59:24 2015 +0100

    Fix dojo/touch to not break native checkbox and radio on iOS and Android when dojoClick=true. Fixes #18352
---
 tests/functional/support/touch_dojoclick2.html | 42 ++++++++++++++++++++++++++
 tests/functional/touch.js                      | 42 ++++++++++++++++++++++++++
 touch.js                                       | 25 +++++++++++----
 3 files changed, 103 insertions(+), 6 deletions(-)

diff --git a/tests/functional/support/touch_dojoclick2.html b/tests/functional/support/touch_dojoclick2.html
new file mode 100755
index 0000000..9aef7cd
--- /dev/null
+++ b/tests/functional/support/touch_dojoclick2.html
@@ -0,0 +1,42 @@
+<!DOCTYPE html>
+<html>
+	<head>
+		<title>test dojo/touch dojoClick property with input of type checkbox and radio</title>
+		<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
+		<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no"/>
+		<meta name="apple-mobile-web-app-capable" content="yes"/>
+
+		<!-- Test for #18352 -->
+		<!-- Checks that dojo/touch with dojoClick=true does not break interaction with "native" HTML input -->
+		<!-- of type checkbox and radio (used to be broken on iOS and Android).	-->
+
+		<script src="../../../dojo.js" data-dojo-config="async: true, isDebug: true"></script>
+
+		<script>
+			document.dojoClick = true;
+			var ready = false;
+			// loading dojo/touch, along with setting document.dojoClick at true, triggers the bug
+			require(["dojo/touch", "dojo/domReady!"], function(){
+				ready = true;
+			});
+			
+		</script>
+	</head>
+	<body>
+		<h1>Test dojo/touch's dojoClick property with input of type checkbox and radio</h1>
+
+		<p>
+			<input type="checkbox" id="dojoClickCheckbox">
+			<label for="dojoClickCheckbox">dojoClick=true</label>
+		</p>
+
+		<p>
+			<input type="radio" id="dojoClickRadio1" name="dojoClickRadio" value="1" checked>
+			<label for="dojoClickRadio1">One</label>
+		</p>
+		<p>
+			<input type="radio" id="dojoClickRadio2" name="dojoClickRadio" value="2">
+			<label for="dojoClickRadio2">Two</label>
+		</p>
+	</body>
+</html>
diff --git a/tests/functional/touch.js b/tests/functional/touch.js
index fa36364..bb39c91 100644
--- a/tests/functional/touch.js
+++ b/tests/functional/touch.js
@@ -265,4 +265,46 @@ define([
 			}
 		};
 	});
+
+	// Tests for #18352
+	// Checks that dojo/touch with dojoClick=true does not break interaction with "native" HTML input
+	// of type checkbox and radio (used to be broken on iOS and Android).
+	registerSuite(function () {
+		var tapOrClick;
+
+		return {
+			name: 'dojo/touch dojoClick2 tests',
+
+			'before': function () {
+				// Not all browsers or drivers support touch events
+				tapOrClick = this.get('remote').environmentType.touchEnabled ?
+					tapElement :
+					clickElement;
+			},
+
+			'beforeEach': function () {
+				return ready(this.get('remote'), require.toUrl('./support/touch_dojoclick2.html'));
+			},
+
+			'press': function () {
+				return tapOrClick(this.get('remote').findById('dojoClickCheckbox'))
+					.execute(function () {
+						return dojoClickCheckbox.checked;
+					})
+					.then(function (result) {
+						assert.isTrue(result, 'dojoClicks2 - checkbox');
+					})
+					.end()
+					.findById('dojoClickRadio2')
+					.click()
+					.execute(function () {
+						return dojoClickRadio2.checked;
+					})
+					.then(function (result) {
+						assert.isTrue(result, 'dojoClicks2 - radio');
+					});
+			}
+		};
+	});
+
 });
\ No newline at end of file
diff --git a/touch.js b/touch.js
index 749f743..5a98d3c 100644
--- a/touch.js
+++ b/touch.js
@@ -196,16 +196,29 @@ function(dojo, aspect, dom, domClass, lang, on, has, mouse, domReady, win){
 						// sent shortly after ours, similar to what is done in dualEvent.
 						// The INPUT.dijitOffScreen test is for offscreen inputs used in dijit/form/Button, on which
 						// we call click() explicitly, we don't want to stop this event.
+						var target = e.target;
 						if(clickTracker && !e._dojo_click &&
 								(new Date()).getTime() <= clickTime + 1000 &&
-								!(e.target.tagName == "INPUT" && domClass.contains(e.target, "dijitOffScreen"))){
+								!(target.tagName == "INPUT" && domClass.contains(target, "dijitOffScreen"))){
 							e.stopPropagation();
 							e.stopImmediatePropagation && e.stopImmediatePropagation();
-							if(type == "click" && (e.target.tagName != "INPUT" || e.target.type == "radio" || e.target.type == "checkbox")
-								&& e.target.tagName != "TEXTAREA" && e.target.tagName != "AUDIO" && e.target.tagName != "VIDEO"){
-								 // preventDefault() breaks textual <input>s on android, keyboard doesn't popup,
-								 // but it is still needed for checkboxes and radio buttons, otherwise in some cases
-								 // the checked state becomes inconsistent with the widget's state
+							if(type == "click" &&
+								(target.tagName != "INPUT" ||
+								(target.type == "radio" &&
+									// #18352 Do not preventDefault for radios that are not dijit or
+									// dojox/mobile widgets.
+									// (The CSS class dijitCheckBoxInput holds for both checkboxes and radio buttons.)
+									(domClass.contains(target, "dijitCheckBoxInput") ||
+										domClass.contains(target, "mblRadioButton"))) ||
+								(target.type == "checkbox" &&
+									// #18352 Do not preventDefault for checkboxes that are not dijit or
+									// dojox/mobile widgets.
+									(domClass.contains(target, "dijitCheckBoxInput") ||
+										domClass.contains(target, "mblCheckBox")))) &&
+								target.tagName != "TEXTAREA" && target.tagName != "AUDIO" && target.tagName != "VIDEO"){
+								// preventDefault() breaks textual <input>s on android, keyboard doesn't popup,
+								// but it is still needed for checkboxes and radio buttons, otherwise in some cases
+								// the checked state becomes inconsistent with the widget's state
 								e.preventDefault();
 							}
 						}

-- 
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