Skip to content
This repository was archived by the owner on Feb 11, 2021. It is now read-only.

Commit 87199e3

Browse files
committed
Merge pull request #85 from azakus/master
Fix broken touch handlers
2 parents 4f83863 + db961d2 commit 87199e3

File tree

5 files changed

+12
-8
lines changed

5 files changed

+12
-8
lines changed

samples/scroller/index.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
scroller.setAttribute('touch-action', 'pan-y');
5151
}
5252
function scroll() {
53-
scroller.setAttribute('touch-action', 'scroll');
53+
scroller.setAttribute('touch-action', 'auto');
5454
}
5555
function none() {
5656
scroller.setAttribute('touch-action', 'none');
@@ -62,7 +62,7 @@
6262
'pointercancel'
6363
].forEach(function(e) {
6464
document.addEventListener(e, function(e) {
65-
console.log(e.type, e.clientX, e.clientY);
65+
console.log(e.type, e.target, e.clientX, e.clientY);
6666
});
6767
});
6868
</script>

src/dispatcher.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@
240240
setTouchAction: function(target, touchAction) {
241241
var st = this.touchActionToScrollType(touchAction);
242242
if (target.setAttribute) {
243-
target[(st ? 'set' : 'remove') + 'Attribute']('touch-action', st);
243+
target[(st ? 'set' : 'remove') + 'Attribute']('touch-action', touchAction);
244244
}
245245
this.scrollType[st ? 'set' : 'delete'](target, st);
246246
}

src/installer.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
var forEach = Array.prototype.forEach.call.bind(Array.prototype.forEach);
1616
var map = Array.prototype.map.call.bind(Array.prototype.map);
1717
var toArray = Array.prototype.slice.call.bind(Array.prototype.slice);
18+
var filter = Array.prototype.filter.call.bind(Array.prototype.filter);
1819
var MO = window.MutationObserver || window.WebKitMutationObserver;
1920
var SELECTOR = '[touch-action]';
2021
var OBSERVER_INIT = {
@@ -28,7 +29,7 @@
2829
this.addCallback = add.bind(binder);
2930
this.removeCallback = remove.bind(binder);
3031
if (MO) {
31-
this.observer = new MO(this.mutationHandler.bind(this));
32+
this.observer = new MO(this.mutationWatcher.bind(this));
3233
}
3334
}
3435

@@ -79,11 +80,14 @@
7980
installOnLoad: function() {
8081
document.addEventListener('DOMContentLoaded', this.installNewSubtree.bind(this, document));
8182
},
83+
isElement: function(n) {
84+
return n.nodeType === Node.ELEMENT_NODE;
85+
},
8286
flattenMutationTree: function(inNodes) {
8387
// find children with touch-action
8488
var tree = map(inNodes, this.findElements, this);
8589
// make sure the added nodes are accounted for
86-
tree.push(inNodes);
90+
tree.push(filter(inNodes, this.isElement));
8791
// flatten the list
8892
return tree.reduce(this.concatLists, []);
8993
},

src/platform-events.js

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
*/
1212
(function(scope) {
1313
var dispatcher = scope.dispatcher;
14-
var installer = scope.installer;
1514

1615
// only activate if this platform does not have pointer events
1716
if (window.navigator.pointerEnabled === undefined) {

src/touch.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
}
4141
},
4242
elementAdded: function(el) {
43-
var a = el.getAttribute && el.getAttribute(this.ATTRIB);
43+
var a = el.getAttribute && el.getAttribute(ATTRIB);
4444
var st = dispatcher.touchActionToScrollType(a);
4545
if (st) {
4646
scrollType.set(el, st);
@@ -49,8 +49,9 @@
4949
if (s) {
5050
scrollType.set(s, st);
5151
}
52+
// only listen if we have a defined touch-action
53+
dispatcher.listen(el, this.events);
5254
}
53-
dispatcher.listen(el, this.events);
5455
},
5556
elementRemoved: function(el) {
5657
scrollType.delete(el);

0 commit comments

Comments
 (0)