Skip to content

Commit

Permalink
refs #15878. Let applications set win.doc.dojoClick to false, and gen…
Browse files Browse the repository at this point in the history
…erate synthetic clicks like in 1.8 in that case. !strict

git-svn-id: http://svn.dojotoolkit.org/src/dojox/trunk@31244 560b804f-0ae3-0310-86f3-f6aa0a117693
  • Loading branch information
Eric Durocher committed Apr 15, 2013
1 parent 059f9bf commit f1d3990
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
7 changes: 6 additions & 1 deletion mobile/Switch.js
Expand Up @@ -13,8 +13,9 @@ define([
"dijit/_WidgetBase",
"./sniff",
"./_maskUtils",
"./common",
"dojo/has!dojo-bidi?dojox/mobile/bidi/Switch"
], function(array, connect, declare, event, win, domClass, domConstruct, domStyle, domAttr, touch, Contained, WidgetBase, has, maskUtils, BidiSwitch){
], function(array, connect, declare, event, win, domClass, domConstruct, domStyle, domAttr, touch, Contained, WidgetBase, has, maskUtils, dm, BidiSwitch){

// module:
// dojox/mobile/Switch
Expand Down Expand Up @@ -236,6 +237,10 @@ define([
array.forEach(this._conn, connect.disconnect);
this._conn = null;
if(this.innerStartX == this.inner.offsetLeft){
// need to send a synthetic click?
if(has("touch") && has("clicks-prevented")){
dm._sendClick(this.inner, e);
}
return;
}
var newState = (this.inner.offsetLeft < -(this._width/2)) ? "off" : "on";
Expand Down
21 changes: 21 additions & 0 deletions mobile/common.js
Expand Up @@ -22,6 +22,27 @@ define([
// tell dojo/touch to generate synthetic clicks immediately
// and regardless of preventDefault() calls on touch events
win.doc.dojoClick = true;
/// ... but let user disable this by removing dojoClick from the document
if(has("touch")){
// Do we need to send synthetic clicks when preventDefault() is called on touch events?
// This is normally true on anything except Android 4.1+ and IE10, but users reported
// exceptions like Galaxy Note 2. So let's use a has("clicks-prevented") flag, and let
// applications override it through data-dojo-config="has:{'clicks-prevented':true}" if needed.
has.add("clicks-prevented", !(has("android") >= 4.1 || has("ie") >= 10));
if(has("clicks-prevented")){
dm._sendClick = function(target, e){
// dojo/touch will send a click if dojoClick is set, so don't do it again.
for(var node = target; node; node = node.parentNode){
if(node.dojoClick){
return;
}
}
var ev = win.doc.createEvent("MouseEvents");
ev.initMouseEvent("click", true, true, win.global, 1, e.screenX, e.screenY, e.clientX, e.clientY);
target.dispatchEvent(ev);
};
}
}

dm.getScreenSize = function(){
// summary:
Expand Down
10 changes: 10 additions & 0 deletions mobile/scrollable.js
Expand Up @@ -547,6 +547,16 @@ define([
if(clicked){ // clicked, not dragged or flicked
this.hideScrollBar();
this.removeCover();
// need to send a synthetic click?
if(has("touch") && has("clicks-prevented") && !this.isFormElement(e.target)){
var elem = e.target;
if(elem.nodeType != 1){
elem = elem.parentNode;
}
setTimeout(function(){
dm._sendClick(elem, e);
});
}
return;
}
speed = this._speed = this.getSpeed();
Expand Down
6 changes: 5 additions & 1 deletion mobile/tests/test_html-form-controls.html
Expand Up @@ -11,11 +11,15 @@

<script type="text/javascript">
require([
"dojo/_base/window",
"dojox/mobile/parser",
"dojox/mobile",
"dojox/mobile/compat",
"dojox/mobile/ScrollableView"
]);
], function(win){
// disable synthetic clicks from dojo/touch
win.doc.dojoClick = false;
});
</script>

<style>
Expand Down

0 comments on commit f1d3990

Please sign in to comment.