Skip to content

Commit

Permalink
Merge pull request #1339 from /issues/1253@v3
Browse files Browse the repository at this point in the history
New implementation of pointerclick for IOS only (closes #1253)
  • Loading branch information
dfilatov committed Apr 29, 2016
2 parents e15aa92 + 6c57644 commit 54aff0e
Showing 1 changed file with 55 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,22 +1,62 @@
modules.define('jquery', function(provide, $) {
modules.define('jquery', ['next-tick'], function(provide, nextTick, $) {

var event = $.event.special.pointerclick = {
setup : function() {
$(this).on('click', event.handler);
},
var isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream,
event = $.event.special.pointerclick = {
setup : function() {
if(isIOS) {
$(this)
.on('pointerdown', event.onPointerdown)
.on('pointerup', event.onPointerup)
.on('pointerleave pointercancel', event.onPointerleave);
} else {
$(this).on('click', event.handler);
}
},

teardown : function() {
$(this).off('click', event.handler);
},
teardown : function() {
if(isIOS) {
$(this)
.off('pointerdown', event.onPointerdown)
.off('pointerup', event.onPointerup)
.off('pointerleave pointercancel', event.onPointerleave);
} else {
$(this).off('click', event.handler);
}
},

handler : function(e) {
if(!e.button) {
var type = e.type;
e.type = 'pointerclick';
$.event.dispatch.apply(this, arguments);
e.type = type;
}
},

onPointerdown : function(e) {
pointerdownEvent = e;
},

handler : function(e) {
if(!e.button) {
e.type = 'pointerclick';
$.event.dispatch.apply(this, arguments);
e.type = 'click';
onPointerleave : function() {
pointerdownEvent = null;
},

onPointerup : function(e) {
if(!pointerdownEvent) return;

if(!pointerDownUpInProgress) {
nextTick(function() {
pointerDownUpInProgress = false;
pointerdownEvent = null;
});
pointerDownUpInProgress = true;
}

event.handler.apply(this, arguments);
}
}
};
},
pointerDownUpInProgress = false,
pointerdownEvent;

provide($);

Expand Down

0 comments on commit 54aff0e

Please sign in to comment.