Skip to content

Commit

Permalink
fix tap penetration.Fixes kissyteam#533,kissyteam#532
Browse files Browse the repository at this point in the history
  • Loading branch information
yiminghe committed Dec 13, 2013
1 parent da96062 commit 443b733
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 50 deletions.
54 changes: 27 additions & 27 deletions build/event/dom/touch-min.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions build/event/dom/touch.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
Copyright 2013, KISSY v1.50
MIT Licensed
build time: Dec 12 22:19
build time: Dec 13 19:43
*/
/*
Combined processedModules by KISSY Module Compiler:
Expand Down Expand Up @@ -60,7 +60,7 @@ KISSY.add("event/dom/touch/tap", ["./handle-map", "event/dom/base", "./single-to
var touch = e.changedTouches[0];
var target = e.target;
var eventObject = new DomEventObject({type:event, target:target, currentTarget:target});
S.mix(eventObject, {pageX:touch.pageX, pageY:touch.pageY, which:1, touch:touch});
S.mix(eventObject, {pageX:touch.pageX, pageY:touch.pageY, originalEvent:e.originalEvent, which:1, touch:touch});
DomEvent.fire(target, event, eventObject);
if(eventObject.isDefaultPrevented()) {
DomEvent.on(target, "click", {fn:preventDefault, once:1})
Expand Down Expand Up @@ -544,7 +544,7 @@ KISSY.add("event/dom/touch/handle", ["dom", "./handle-map", "event/dom/base", ".
if(isPointerEvent(type)) {
self.updateTouch(event.originalEvent)
}else {
if(!isTouchEvent()) {
if(!isTouchEvent(type)) {
throw new Error("unrecognized touch event: " + event.type);
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/dom/sub-modules/base/src/base/selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* simple selector for dom
* @author yiminghe@gmail.com, lifesinger@gmail.com
*/
KISSY.add(function (S,require) {
KISSY.add(function (S, require) {
var Dom = require('./api');
var doc = S.Env.host.document,
docElem = doc.documentElement,
Expand Down Expand Up @@ -214,7 +214,8 @@ KISSY.add(function (S,require) {

function hasSingleClass(el, cls) {
// consider xml
var className = el && (el.className || getAttr(el, 'class'));
// https://github.com/kissyteam/kissy/issues/532
var className = el && getAttr(el, 'class');
return className &&
(className = className.replace(/[\r\t\n]/g, SPACE)) &&
(SPACE + className + SPACE).indexOf(SPACE + cls + SPACE) > -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ function visit41_255_1(result) {
function visit40_254_1(result) {
_$jscoverage['/touch/handle.js'].branchData['254'][1].ranCondition(result);
return result;
}_$jscoverage['/touch/handle.js'].branchData['244'][1].init(390, 15, '!isTouchEvent()');
}_$jscoverage['/touch/handle.js'].branchData['244'][1].init(390, 19, '!isTouchEvent(type)');
function visit39_244_1(result) {
_$jscoverage['/touch/handle.js'].branchData['244'][1].ranCondition(result);
return result;
Expand Down Expand Up @@ -1086,7 +1086,7 @@ KISSY.add(function(S, require) {
self.updateTouch(event.originalEvent);
} else {
_$jscoverage['/touch/handle.js'].lineData[244]++;
if (visit39_244_1(!isTouchEvent())) {
if (visit39_244_1(!isTouchEvent(type))) {
_$jscoverage['/touch/handle.js'].lineData[245]++;
throw new Error('unrecognized touch event: ' + event.type);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,11 @@ if (! _$jscoverage['/touch/tap.js']) {
_$jscoverage['/touch/tap.js'].lineData[40] = 0;
_$jscoverage['/touch/tap.js'].lineData[41] = 0;
_$jscoverage['/touch/tap.js'].lineData[46] = 0;
_$jscoverage['/touch/tap.js'].lineData[52] = 0;
_$jscoverage['/touch/tap.js'].lineData[53] = 0;
_$jscoverage['/touch/tap.js'].lineData[54] = 0;
_$jscoverage['/touch/tap.js'].lineData[62] = 0;
_$jscoverage['/touch/tap.js'].lineData[66] = 0;
_$jscoverage['/touch/tap.js'].lineData[55] = 0;
_$jscoverage['/touch/tap.js'].lineData[56] = 0;
_$jscoverage['/touch/tap.js'].lineData[64] = 0;
_$jscoverage['/touch/tap.js'].lineData[68] = 0;
}
if (! _$jscoverage['/touch/tap.js'].functionData) {
_$jscoverage['/touch/tap.js'].functionData = [];
Expand All @@ -273,12 +273,12 @@ if (! _$jscoverage['/touch/tap.js'].branchData) {
_$jscoverage['/touch/tap.js'].branchData['31'][2] = new BranchData();
_$jscoverage['/touch/tap.js'].branchData['32'] = [];
_$jscoverage['/touch/tap.js'].branchData['32'][1] = new BranchData();
_$jscoverage['/touch/tap.js'].branchData['53'] = [];
_$jscoverage['/touch/tap.js'].branchData['53'][1] = new BranchData();
_$jscoverage['/touch/tap.js'].branchData['55'] = [];
_$jscoverage['/touch/tap.js'].branchData['55'][1] = new BranchData();
}
_$jscoverage['/touch/tap.js'].branchData['53'][1].init(494, 32, 'eventObject.isDefaultPrevented()');
function visit110_53_1(result) {
_$jscoverage['/touch/tap.js'].branchData['53'][1].ranCondition(result);
_$jscoverage['/touch/tap.js'].branchData['55'][1].init(623, 32, 'eventObject.isDefaultPrevented()');
function visit110_55_1(result) {
_$jscoverage['/touch/tap.js'].branchData['55'][1].ranCondition(result);
return result;
}_$jscoverage['/touch/tap.js'].branchData['32'][1].init(82, 63, 'Math.abs(currentTouch.pageY - firstTouchXY.pageY) > sensitivity');
function visit109_32_1(result) {
Expand Down Expand Up @@ -354,21 +354,22 @@ KISSY.add(function(S, require) {
S.mix(eventObject, {
pageX: touch.pageX,
pageY: touch.pageY,
originalEvent: e.originalEvent,
which: 1,
touch: touch});
_$jscoverage['/touch/tap.js'].lineData[52]++;
_$jscoverage['/touch/tap.js'].lineData[54]++;
DomEvent.fire(target, event, eventObject);
_$jscoverage['/touch/tap.js'].lineData[53]++;
if (visit110_53_1(eventObject.isDefaultPrevented())) {
_$jscoverage['/touch/tap.js'].lineData[54]++;
_$jscoverage['/touch/tap.js'].lineData[55]++;
if (visit110_55_1(eventObject.isDefaultPrevented())) {
_$jscoverage['/touch/tap.js'].lineData[56]++;
DomEvent.on(target, 'click', {
fn: preventDefault,
once: 1});
}
}});
_$jscoverage['/touch/tap.js'].lineData[62]++;
_$jscoverage['/touch/tap.js'].lineData[64]++;
eventHandleMap[event] = {
handle: new Tap()};
_$jscoverage['/touch/tap.js'].lineData[66]++;
_$jscoverage['/touch/tap.js'].lineData[68]++;
return Tap;
});
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ KISSY.add(function (S, require) {
self.touches = [event.originalEvent];
} else if (isPointerEvent(type)) {
self.updateTouch(event.originalEvent);
} else if (!isTouchEvent()) {
} else if (!isTouchEvent(type)) {
throw new Error('unrecognized touch event: ' + event.type);
}
// no throttle! to allow preventDefault
Expand Down
2 changes: 2 additions & 0 deletions src/event/sub-modules/dom/sub-modules/touch/src/touch/tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ KISSY.add(function (S, require) {
S.mix(eventObject, {
pageX: touch.pageX,
pageY: touch.pageY,
// call e.preventDefault on tap event to prevent tap penetration
originalEvent: e.originalEvent,
which: 1,
touch: touch
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
<meta name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-touch-fullscreen" content="yes">
<script src="/kissy/build/seed.js" charset="utf-8"></script>
<script src="/kissy/src/package.js"></script>
<script src="/kissy/src/log.js"></script>
<style>
#upper {
position: absolute;
left:50px;
top:50px;
width:100px;
height: 100px;
border: 1px solid red;
background-color: #ffff00;
}

#under {
width:200px;
height: 200px;
border: 1px solid green;
background-color: #ffffff;
}
</style>
</head>
<body>
<div id="under"></div>
<div id="upper"></div>
<script>
KISSY.use('node', function (S, Node) {
var $=Node.all;
$('#upper').on('tap',function(e){
log('upper '+ e.type);
$(this).hide();
e.preventDefault();
});
$('#upper').on('click',function(e){
log('upper '+ e.type);
});
$('#under').on('tap click',function(e){
log('under '+ e.type);
});
});
</script>
</body>
</html>

0 comments on commit 443b733

Please sign in to comment.