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

Commit

Permalink
Merge pull request #85 from azakus/master
Browse files Browse the repository at this point in the history
Fix broken touch handlers
  • Loading branch information
dfreedm committed Jun 26, 2013
2 parents 4f83863 + db961d2 commit 87199e3
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions samples/scroller/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
scroller.setAttribute('touch-action', 'pan-y');
}
function scroll() {
scroller.setAttribute('touch-action', 'scroll');
scroller.setAttribute('touch-action', 'auto');
}
function none() {
scroller.setAttribute('touch-action', 'none');
Expand All @@ -62,7 +62,7 @@
'pointercancel'
].forEach(function(e) {
document.addEventListener(e, function(e) {
console.log(e.type, e.clientX, e.clientY);
console.log(e.type, e.target, e.clientX, e.clientY);
});
});
</script>
Expand Down
2 changes: 1 addition & 1 deletion src/dispatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@
setTouchAction: function(target, touchAction) {
var st = this.touchActionToScrollType(touchAction);
if (target.setAttribute) {
target[(st ? 'set' : 'remove') + 'Attribute']('touch-action', st);
target[(st ? 'set' : 'remove') + 'Attribute']('touch-action', touchAction);
}
this.scrollType[st ? 'set' : 'delete'](target, st);
}
Expand Down
8 changes: 6 additions & 2 deletions src/installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
var forEach = Array.prototype.forEach.call.bind(Array.prototype.forEach);
var map = Array.prototype.map.call.bind(Array.prototype.map);
var toArray = Array.prototype.slice.call.bind(Array.prototype.slice);
var filter = Array.prototype.filter.call.bind(Array.prototype.filter);
var MO = window.MutationObserver || window.WebKitMutationObserver;
var SELECTOR = '[touch-action]';
var OBSERVER_INIT = {
Expand All @@ -28,7 +29,7 @@
this.addCallback = add.bind(binder);
this.removeCallback = remove.bind(binder);
if (MO) {
this.observer = new MO(this.mutationHandler.bind(this));
this.observer = new MO(this.mutationWatcher.bind(this));
}
}

Expand Down Expand Up @@ -79,11 +80,14 @@
installOnLoad: function() {
document.addEventListener('DOMContentLoaded', this.installNewSubtree.bind(this, document));
},
isElement: function(n) {
return n.nodeType === Node.ELEMENT_NODE;
},
flattenMutationTree: function(inNodes) {
// find children with touch-action
var tree = map(inNodes, this.findElements, this);
// make sure the added nodes are accounted for
tree.push(inNodes);
tree.push(filter(inNodes, this.isElement));
// flatten the list
return tree.reduce(this.concatLists, []);
},
Expand Down
1 change: 0 additions & 1 deletion src/platform-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
*/
(function(scope) {
var dispatcher = scope.dispatcher;
var installer = scope.installer;

// only activate if this platform does not have pointer events
if (window.navigator.pointerEnabled === undefined) {
Expand Down
5 changes: 3 additions & 2 deletions src/touch.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
}
},
elementAdded: function(el) {
var a = el.getAttribute && el.getAttribute(this.ATTRIB);
var a = el.getAttribute && el.getAttribute(ATTRIB);
var st = dispatcher.touchActionToScrollType(a);
if (st) {
scrollType.set(el, st);
Expand All @@ -49,8 +49,9 @@
if (s) {
scrollType.set(s, st);
}
// only listen if we have a defined touch-action
dispatcher.listen(el, this.events);
}
dispatcher.listen(el, this.events);
},
elementRemoved: function(el) {
scrollType.delete(el);
Expand Down

0 comments on commit 87199e3

Please sign in to comment.