Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jaws ie click #25

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions dist/ractive-events-tap.es.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,23 @@ function TapHandler ( node, callback ) {
TapHandler.prototype = {
bind: function bind ( node ) {
// listen for mouse/pointer events...
if (window.navigator.pointerEnabled) {
if ( window.navigator.pointerEnabled ) {
node.addEventListener( 'pointerdown', handleMousedown, false );
} else if (window.navigator.msPointerEnabled) {
} else if ( window.navigator.msPointerEnabled ) {
node.addEventListener( 'MSPointerDown', handleMousedown, false );
} else {
node.addEventListener( 'mousedown', handleMousedown, false );

// ...and touch events
node.addEventListener( 'touchstart', handleTouchstart, false );
}

// ...and touch events
node.addEventListener( 'touchstart', handleTouchstart, false );

// ...and random click events
node.addEventListener( 'click', handleRealClick, false );

// native buttons, and <input type='button'> elements, should fire a tap event
// when the space key is pressed
if ( node.tagName === 'BUTTON' || node.type === 'button' ) {
if ( node.tagName === 'A' || node.tagName === 'BUTTON' || node.type === 'button' ) {
node.addEventListener( 'focus', handleFocus, false );
}

Expand All @@ -57,6 +60,9 @@ TapHandler.prototype = {
return;
}

// Remove click handler while normal mouse events in progress
this.node.removeEventListener( 'click', handleRealClick, false );

var x = event.clientX;
var y = event.clientY;

Expand All @@ -82,6 +88,12 @@ TapHandler.prototype = {
}
};

var cancelFakeClick = function () {
// remove this event and add back original event
this$1.node.removeEventListener( 'click', cancelFakeClick, false );
this$1.node.addEventListener( 'click', handleRealClick, false );
}

var cancel = function () {
this$1.node.removeEventListener( 'MSPointerUp', handleMouseup, false );
document.removeEventListener( 'MSPointerMove', handleMousemove, false );
Expand All @@ -91,6 +103,11 @@ TapHandler.prototype = {
document.removeEventListener( 'pointercancel', cancel, false );
this$1.node.removeEventListener( 'click', handleMouseup, false );
document.removeEventListener( 'mousemove', handleMousemove, false );

// prepare to add back real click handler when done
this$1.node.addEventListener( 'click', cancelFakeClick, false );
// if no click event fired then restore the real click event any way
setTimeout( cancelFakeClick, TIME_THRESHOLD );
};

if ( window.navigator.pointerEnabled ) {
Expand Down Expand Up @@ -184,6 +201,10 @@ function handleTouchstart ( event ) {
this.__tap_handler__.touchdown( event );
}

function handleRealClick ( event ) {
this.__tap_handler__.fire( event );
}

function handleFocus () {
this.addEventListener( 'keydown', handleKeydown, false );
this.addEventListener( 'blur', handleBlur, false );
Expand All @@ -195,7 +216,7 @@ function handleBlur () {
}

function handleKeydown ( event ) {
if ( event.which === 32 ) { // space key
if ( event.which === 32 || event.which === 13 ) { // space key
this.__tap_handler__.fire();
}
}
Expand Down
Loading