Skip to content

Commit

Permalink
fix: add touchcancel handling as touchend for events coming from outside
Browse files Browse the repository at this point in the history
  • Loading branch information
yoannmoinet committed Dec 19, 2017
1 parent 45ec1d7 commit ebc501e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var events = {
touch: {
start: 'touchstart',
move: 'touchmove',
end: 'touchend'
end: 'touchend, touchcancel'
},
mouse: {
start: 'mousedown',
Expand Down
30 changes: 20 additions & 10 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,29 @@ u.degrees = function(a) {
return a * (180 / Math.PI);
};

u.bindEvt = function (el, type, handler) {
if (el.addEventListener) {
el.addEventListener(type, handler, false);
} else if (el.attachEvent) {
el.attachEvent(type, handler);
u.bindEvt = function (el, arg, handler) {
var types = arg.split(/[ ,]+/g);
var type;
for (var i = 0; i < types.length; i += 1) {
type = types[i];
if (el.addEventListener) {
el.addEventListener(type, handler, false);
} else if (el.attachEvent) {
el.attachEvent(type, handler);
}
}
};

u.unbindEvt = function (el, type, handler) {
if (el.removeEventListener) {
el.removeEventListener(type, handler);
} else if (el.detachEvent) {
el.detachEvent(type, handler);
u.unbindEvt = function (el, arg, handler) {
var types = arg.split(/[ ,]+/g);
var type;
for (var i = 0; i < types.length; i += 1) {
type = types[i];
if (el.removeEventListener) {
el.removeEventListener(type, handler);
} else if (el.detachEvent) {
el.detachEvent(type, handler);
}
}
};

Expand Down

0 comments on commit ebc501e

Please sign in to comment.