Skip to content

Commit

Permalink
new implementation of pointerclick for IOS only (closes #1253)
Browse files Browse the repository at this point in the history
  • Loading branch information
veged authored and dfilatov committed Apr 29, 2016
1 parent e15aa92 commit 6c57644
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,

This comment has been minimized.

Copy link
@tadatuta

tadatuta Apr 29, 2016

Member

shouldn't it be ua to provide such info?

This comment has been minimized.

Copy link
@narqo

narqo Apr 29, 2016

Member

It doesn't have such functionality on the common level. We may change this part after #1223 in 4.x.

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 6c57644

Please sign in to comment.