Giter Club home page Giter Club logo

jquery-touch-events's Introduction

jQuery Touch Events

This is a series of plugins that create additional events that can be used in combination with jQuery when developing for mobile devices. The events are also compatible with desktop browsers to ensure ultimate compatibility for your projects. In time, we will update the Repository to include some very basic demonstrations to get you started with using the events, but for now, we've put together a list of the events that are provided, and what they do.

As explained, the events are each triggered by native touch events, or alternatively by click events. The plugin automatically detects whether the user's device is touch compatible, and will use the correct native events whenever required. It is hoped that these events will help to aid single-environment development with jQuery for mobile web app development.

Table of Contents:

  1. Version History
  2. Installation
  3. Usage
  4. Events
  5. Callback Data
  6. Defining Thresholds
  7. Utility Functions
  8. Demo
  9. Requirements
  10. License

1. Version History:

After almost 2 years in public beta, I am pleased to announce that the library is now officially launched as version 1.0.0. I'll be updating the version history over time with digests of fixes, features and improvements:

  • Version 2.0.3 (2020-04-23)
  • Version 2.0.2 (2020-04-21)
    • Fix for binding events to document and window.
  • Update NPM repo so that latest releases are detected.
  • Version 2.0.1 (2019-12-02)
  • Version 2.0.0 (2018-05-20)
    • Added two-finger tap event (tap2).
    • Added two-finger taphold event (taphold2).
    • Added setter functions to easily set thresholds globally.
    • Fixed a bug where the offset position of elements was sometimes incorrect.
    • Other minor bug fixes.
  • Version 1.0.9 (2017-06-07)
    • Fixes a bug where binding to multiple elements with the same selector caused issues with doubletap.
  • Version 1.0.8 (2017-02-01)
    • Fixes a bug where certain instances of Chrome on touch devices did not correctly fire events.
    • Added license info to minified script.
  • Version 1.0.7 (2017-02-01)
    • Added threshold support for taphold
  • Version 1.0.6 (2016-11-16)
    • Added slop factor for singletap
    • Fixed a bug where offset() was sometimes called on null (instead of window).
  • Version 1.0.5 (2015-11-13)
    • Fixed a major bug where the reported offset position of events was incorrect when inside of a parent element.
  • Version 1.0.4 (2015-11-12)
    • Regressed from MSPointerEvent for compatibility with IE11 and Edge
    • Removed multi-name event for tap.
  • Version 1.0.3 (2015-11-10)
    • Numerous minor bug fixes
    • Fixes a bug where the offset position returned by events relative to the current target, not the bound target.
  • Version 1.0.2 (2015-08-26)
    • Numerous bug fixes
    • Added support for MSPointerEvent
  • Version 1.0.1 (2015-08-21)
    • Added Bower package for easy install
    • Fixed a bug where Internet Explorer under Windows Mobile did not trigger certain events.
  • Version 1.0.0 (2015-07-18)
    • The library officially entered 1.0.0 after minor bug fixes and final adjustments.

2. Installation:

jQuery Touch Events, as the name suggests, require only the jQuery library (version 1.7+) to run. You should download the latest release from the src folder, and include the Javascript file within your project, after jQuery has been included. It is recommended to also wrap your code inside the DOMReady callback function of jQuery ($(function() { }), for example).

Manual installation:

Once you have downloaded the JS files from the master branch, you should include them using the following code:

<script type="text/javascript" src="path/to/jquery.mobile-events.min.js"></script>

The awesome guys over at cdnjs have kindly added the library to their CDN so you can include it as follows directly into your application:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-touch-events/1.0.5/jquery.mobile-events.js"></script>

Alternatively, you can also install jQuery-touch-events using Bower as follows:

$ bower install jquery-touch-events

jQuery Touch Events can also be installed using NPM as follows:

$ npm i @benmajor/jquery-touch-events

If you are installing the library via NPM, after running the npm i command above, you'll also need to ensure that you import the modules into you project files wherever you wish to use the events. Place the following line alongside your other imports:

import "@benmajor/jquery-touch-events";

3. Usage:

All of the events outlined above have been written using jQuery's event.special object, and so can be used in conjunction with jQuery's event handling functions, as well as shortcut wrappers. As a result, all of the events that are supported by this library may be handled using any of jQuery's own event-specific methods, such as on() and one().

The following code snippets showcase some basic usage with jQuery:

Binding a tap event to an element:

When binding, you should use jQuery's on() function as follows (avoid the use of live() and bind() as these are now deprecated and will be removed from future versions of jQuery).

$('#myElement').on('tap', function(e) { 
    console.log('User tapped #myElement'); 
});

Triggering the event:

$('#myElement').trigger('tap');

Removing the event:

$('#myElement').off('tap', handler);

Using method wrapper:

$('#myElement').tap(function(e) { 
    console.log('User tapped #myElement'); 
});

Method chaining:
Chaining has also been preserved, so you can easily use these events in conjunction with other jQuery functions, or attach multiple events in a single, chained LOC:

$('#myElement').singletap(function() { 
    console.log('singletap');
}).doubletap(function() { 
    console.log('doubletap'); 
});

4. The Events:

  • tapstart
    Fired as soon as the user begins touching an element (or clicking, for desktop environments).
  • tapend
    Fired after the user releases their finger from the target element (or releases their mouse button on desktops).
  • tapmove
    Fired as soon as the user begins moving their finger on an element (or moving their mouse, for desktop environments).
  • tap
    This event is fired whenever the user taps and releases their finger on the target element. Caution should be observed when using this event in conjunction with tap events, especially doubletap. This event will be fired twice when doubletap is used, so it is recommended to use singletap in this case.
  • singletap
    Unlike tap this event is only triggered once we are certain the user has only tapped the target element a single time. This will not be triggered by doubletap or taphold, unlike tap. Since we need to run some tests to make sure the user isn't double tapping or holding a tap on the target element, this event is fired with a short delay (currently of 500 milliseconds).
  • doubletap
    Triggered whenever the user double taps on the target element. The threshold (time between taps) is currently set at 500 milliseconds.
  • taphold
    This event is triggered whenever the user taps on the target element and leaves their finger on the element for at least 750 milliseconds.
  • swipe
    This is called whenever the user swipes their finger on the target element. It is not direction-dependent, and is fired regardless of the direction the user swiped.
  • swipeup
    Similar to swipe, except only called when the user swipes their finger in an upward direction on the target element (i.e. bottom to top)
  • swiperight
    Similar to swipe, but triggered only when the user swipes their finger left to right on the target element.
  • swipedown
    Similar to swipe, but triggered only when the user swipes their finger top to bottom on the target element.
  • swipeleft
    Similar to swipe, but triggered only when the user swipes their finger from right to left.
  • swipeend
    The swipeend event is trigged whenever a swipe event ends (i.e. the user finished moving their finger / cursor and released it). This event should be used to handle custom functions, since it will be triggered only when the swipe ends, rather than triggering immediately when the threshold has been met.
  • scrollstart
    Triggered as soon as scrolling begins on the target element.
  • scrollend
    Triggered as soon as scrolling is stopped on the target element.
  • orientationchange
    This event is triggered when the orientation of the device is changed. Please note that it uses throttling for non-mobile devices, or devices which do not support the native orientationchange event. In the latter instance, a detection of the viewport size change occurs.

5. Callback Data:

Each event now features a second argument that can be passed to the specified callback function. This argument includes some basic data relating specifically to the event, and can be accessed as a standard JavaScript object. To hook into this parameter, you should use the following code:

$(element).swipeend(function(e, touch) {  });

Given the example above, touch will now contain some basic data that can be accessed through touch.. The first argument will represent the last native event that occurred (the names used for these two arguments is irrelevant).

Each event provides different callback data. The following shows the numerous data that are passed back to the callback function inside the second parameter:

tapstart, tapend, tapmove, tap, singletap:

offset - object containing the X and Y positions of the event relative to the element to which is was bound. Accessed through offset.x and offset.y respectively.

position - object containing the X and Y positions of the event relative to the screen. Accessed through position.x and position.y respectively.

target - the jQuery object from which the event was triggered.

time - JavaScript timestamp the event occurred (milliseconds since the Unix Epoch)

taphold:

duration: the time in milliseconds that the user tapped for.

endOffset - object containing the X and Y positions of the end event (i.e. when the user released their finger or mouse) relative to the element to which the event was bound. Accessed through endOffset.x and endOffset.y respectively.

endPosition - object containing the X and Y positions of the end event (i.e. when the user released their finger or mouse) relative to the screen. Accessed through endPosition.x and endPosition.y respectively.

endTime - JavaScript timestamp the taphold was triggered (milliseconds since the Unix Epoch). This will ordinarily be equal to the startTime + taphold threshold.

startOffset - object containing the X and Y positions of the start event (i.e. when the user pressed their finger or mouse) relative to the element to which the event was bound. Accessed through endOffset.x and endOffset.y respectively.

startPosition - object containing the X and Y positions of the start event (i.e. when the user pressed their finger or mouse) relative to the screen. Accessed through endPosition.x and endPosition.y respectively.

startTime - JavaScript timestamp the taphold started (milliseconds since the Unix Epoch).

target - the jQuery object from which the event was triggered.

doubletap:

firstTap - Object containing the same data as a tap event, but for the first tap to occur.

secondTap - Object containing the same data as a tap event, but for the second (i.e. final) tap to occur.

interval - the time in milliseconds between the two tap.

swipe, swipeup, swiperight, swipedown, swipeleft, swipeend:

direction - string representing the swipe direction (either up, right, down or left).

duration - the time in milliseconds over which the swipe took place (for best results, use with swipeend only, as this will typically be equal to the defined swipe-threshold.

xAmount - number of pixels the swipe occupied on the X-axis (returned regardless of direction).

yAmount - number of pixels the swipe occupied on the Y-axis (returned regardless of direction).

startEvnt - Object containing the same data as a tap event, but captured when swiping begins.

endEvent - Object containing the same data as a tap event, but captured when swiping is complete.

6. Defining Thresholds:

You can also define custom thresholds to be used for swipe events (swipeup, swiperight, swipedown and swipeleft) to prevent interference with scrolling and other events. To do so, simply assign a data-xthreshold or data-ythreshold to the target element as follows:

<div id="mySwiper" data-xthreshold="500"></div>

The value you define is the difference in pixels that the user must move before the event is triggered on the target element. If no threshold is defined, a default of 50px will be used.

data-xthreshold defines the horizontal threshold.

data-ythreshold defines the vertical threshold.

Update as of 1.0.7: Following requests from users and contributors, as of 1.0.7 it is now possible to also define the doubletap threshold via jQuery's data- attributes as follows:

data-threshold defines the amount of time (in milliseconds) after which the doubletap event is fired on the target element.

7. Utility Functions:

In addition to the numerous additional events that are provided, the library also includes a number of utility functions that can be used to further leverage the power of native events within your website or application. These utility functions can be used for unifying basic events, such as tapstart or mousedown.

The following utility functions are provided (each function is registered to the jQuery namespace, and should be called with $.funcName() (or jQuery.funcName() for compatibility):

  • isTouchCapable():
    Returns true or false depending upon whether touch events are supported.
  • getStartEvent():
    Returns touchstart for touch-enabled devices, or mousedown for standard environments.
  • getEndEvent():
    Returns touchend for touch-enabled devices, or mouseup for standard environments.
  • getMoveEvent():
    Returns touchmove for touch-enabled devices, or mousemove for standard environments.
  • getTapEvent():
    Returns tap for touch-enabled devices, or click for standard environments.
  • getScrollEvent():
    Returns touchmove for touch-enabled devices, or scroll for standard environments. Caution should be exercised when using this function, since some mobile browsers will correctly bind to scroll as well as touchmove.

8. Demo:

I have put together a simple demo application that shows the numerous events in action. The console on the left hand side is used to show information about the events that have been called. You can examine the code easily by viewing the page's source to lear more about how this works. Please click on the below to check out the demo:

http://lincweb.co.uk/labs/jquery-touch-events/demo/

Please be aware that this demonstration uses Google's hosted jQuery file, and also pulls the latest version of the events library from GitHub. It is a great place to check the status of the library. Since this demo uses the vanilla code, it is a good idea to check the library functionality here for your own reference. If you're running into problems with the library, please check this demonstration using your device in the first instance. You can scan in the QR below to go directly to the web page:

Demonstration QR Code

9. Requirements:

The library works with jQuery 1.7.0+. All major browsers have been tested without problem. The library is not compatible with jQuery < 1.7.

10. License:

Licensed under the MIT License:

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

jquery-touch-events's People

Contributors

4lg4 avatar benmajor avatar benmcmaster avatar ckgrafico avatar elob avatar hachigoro avatar imbrish avatar jumplink avatar kristianm avatar orthographic-pedant avatar pao avatar philbob avatar spadin avatar trostli avatar vheemstra avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jquery-touch-events's Issues

Swiping on a PlayBook

I previously reported that I needed to add a 100ms pause to enable swiping on a PlayBook. This fix worked in the Jan 20 version. However, this didn't work in the Jan 21 version, so I restored the Jan 20 version of lines 37-41 (startevent ... scrollevent), and swiping worked.

I can also get this to work by removing the mouse events from these statements. E.g. change
startevent : 'touchstart mousedown'
to
startevent : 'touchstart'
So it looks like the PlayBook doesn't like mousedown etc.

I am currently using the Jan 28 version, with the aforementioned regression to the Jan 20 version, and my own pause. Both of these fixes are required to allow swiping on a PlayBook.

Erroneous Chrome desktop detection

The detection for Chrome desktop (isChromeDesktop) gives a false positive for mobile browsers which correctly identify Chrome as mobile but contain the word 'linux' (or 'windows', etc).

For example, this is a user agent from Chrome on the Galaxy Note III:

mozilla/5.0 (linux; android 4.3; samsung-sm-n900a build/jss15j) applewebkit/537.36 (khtml, like gecko) chrome/32.0.1700.99 mobile safari/537.36

isChromeDesktop finds 'chrome' and 'linux' and flags the client as Chrome desktop even though the agent has self-identified with chrome mobile.

I'm not familiar enough with user agent strings to suggest a reliable solution, but perhaps you could test for the word 'mobile' in the agent.

Double Tap not working in iPhone 5S Safari iOS

Using JQuery version 1.10.2

Using jquery.mobile-events.min.js from this GitHub source

Using this code:
$(".list-group-item").on('doubletap', function (e) {
alert('double tap');
});

This works on the desktop / laptop by reporting when I double click (it alerts 'double tap')

This fails in the iPhone 5S when I double tap

Doubletap interval is not correct after second, third and so on taps

Hi! realy greate code! But I've mentioned that the interval is not correct if you do the 2. doubletap(3., 4. and so on). It seems to be that the tap time from the 1.tap of 1.doubletap is not resetted by the 2.doubletap. So if you do doubletap for the first time for example you have interval of 500 millisecond and then if you will wait 5 second and then do the doubletap one more time the interval will be 5500 seconds(and it should be 500).

Chrome on Android is only firing taps, no swipes.

First of all, you are awesome and we love you.

Second, looks like it's working fantastically on everything we've tested except Android Chrome browser. Works great on iOS Chrome.

Our Nexus 7 and Nexus 4 Android Chrome browsers only register the taps, swipes aren't taking.

THANK YOU! Hope this helps!

Tap vs touchend Speed

Hi benmajor

I've been using your plugin, and it has been super helpful. Thanks.

I have experienced slow and inconsistent response on Android tap listeners.

I do see that there is a 500 ms delay that is part of it.

For me doubletap isn't important, tap on Android is inconsistent, and I wanted a faster tap response. I started to use touchend, but had conflicts with swipe, so I did this little override:

// custom quicktap event
var swiped = false;
$(document).on("swipeend", function(){
swiped = true;
});
$(document).on("touchend", function(e){
if (!swiped) $(e.target).trigger("quicktap");
swiped = false;
});

I thought I'd share to see if you want to integrate it somehow.

IE8 incompatibility

In today's release, in IE8, I get this error.

Message: Object doesn't support this property or method
Line: 280
Char: 5
Code: 0
URI: file:///C:/Documents%20and%20Settings/Chris/My%20Documents/Web%20Sites/Chris/eastcoastride_test/res/jquery.mobile-events.min.js

Also a semicolon should be added on lines 77, 90, 129, 217.

touchmove Not Working

Whenever the touchmove event is used, the following error is given in the console:

element.tapmove is not a function

Events not working on delegated handlers

I noticed you are memoizing thisObject in your special events functions, then triggering events such as swipe on that memoized object. This pattern doesn't work for delegated events.

For example with the following markup:

<html>
  <body>
    <span class="my-span"></span>
  </body>
</html>

This event works as expected:

$(".my-span").on("swipe", function(event) {
  console.log("swipe", event)
});

However, this event will never be triggered:

$("body").on("swipe", ".my-span", function(event) {
  console.log("swipe", event)
});

The reason for this is because you are triggering the event on the body element instead of the element in which the event occurred, which would then allow the event to bubble up and be caught.

The reason this came up for me is because in Backbone, events are added in the fashion of the second example, so when I attach a handler to a child element in a view, the event is never triggered for me.

A quick solution would be to trigger the event on $(e.target) instead of $(thisObject)

This may only be an issue on the swipe events. Those are the only events I have been using.

add delegate example in README.md

Hi

great lib.

important point for me is, events can be delegated, that is, they can be assigned to elements that are added dynamically to the page later. it doesnt specifically say so in the docs, had to test it .. but it seems to work just fine

$(document).on('tap','.photo',function() { alert('you tapped on a photo that wasnt here when i bound this event'); });

Swiping still not fixed

Concerning the previous issue, the latest code fix does not work for me. I have deployed the updated version, and now swiping right does not work.

Concerning JSLint, I was not concerned about whitespace, but there are a few missing semicolons. When I run JSLint, I disable the options, "messy whitespace", "== and !=", "misordered definitions", and "many var statements per function". This prevents it from terminating part way through the file, and produces a more manageable error report.

e.preventDefault is not working

First, thanks for this wonderful plugin. I'm not sure if this is supported, but when clicking a anchor tag that serves as a button, for example <a href="#">Next</a>, preventDefault(); or even return false is not working. Thanks.

$(element).on('tap',function(e){
   e.preventDefault();
});

EDIT: sorry for duplicate question : #2

Docs Confusion Regarding Event Names

For example, getEndEvent() returns mouseup or touchend, but the "provided events" list only shows tapend and not touchend as a provided event. I realize that tapend is the event this library provides, but maybe I don't understand why the utility wouldn't return that instead of touch.

Related, I am having some trouble trying to fully understand some of the docs around movements. I'm trying to use touchmove as a drop-in replacement for mousemove but that doesn't seem to be the correct event. There doesn't seem to be a tapmove event, only taphold which has a slightly different api than mousemove

Does not work on Galaxy S3?

Tried latest code and your link to your Action area/console on my Galaxy S3 using the Chrome browser and it doesn't :(

Event gets bubble to parent after child event is done

In my scenario I need to bind the taphold for parent div and child div inside. Each binding will execute different functions. For example:

function parentFunction(e){
    //parent code
};

function childFunction(e){
    //child code
};

$('.parent').bind('taphold', parentFunction);
$('.child').bind('taphold', childFunction);

Things work well if I tap on parent div. But when I tap on child div both function will get executed.

I want to have only childFunction execute when child div is tapped. I've been trying with event.stopPropagation() but it make everything stop working.

Please help.

Many thanks.

Doesn't work with iScroll 4

The problem seems to be line #298 e.stopPropagation();

It does not allow the touchmove event to bubble up, which prevents scrolling in iScroll. So by changing to e.preventDefault(); I got it to work as expected.

doubletap not working iPhone4 IOS7

On your demo page I'm not getting the doubletap notification.

I see as output (of course in reverse order):

Mobile Events library loaded. 14:52:47
"tapstart" called 14:52:50
"tapend" called 14:52:50
"tap" called 14:52:50
"tapstart" called 14:52:50
"tapend" called 14:52:50
"tap" called 14:52:50
"taphold" called 14:52:51

Oddly enough the doubletap registers fine on my desktop with a double click. Any suggestions. I was really hoping this was going to be useful for detecting a double tap on the phone. I'll check with my wife's phone and tablet later and see if it is different.

Thanks for any advice in this matter.

'singletap' does not get triggered on desktop browsers

I implemented jQuery-Mobile-Events, and 'singletap' is not getting triggered from desktop browsers. It is, however, getting called from my iPhone. I used the demo provided in the github description, and 'singletap' also didn't get called... so it doesn't have anything to do with my configuration.

use of deprecated attr

Whilst migrating to 1.9.1 the migrate plugin highlighted the use of attr to access data-xthreshold and data-ythreshold. Means that plugin can only be used between >1.7 as stated in documention and < 1.9.* which has now removed attr completely (unless you include the migrate plugin)

should use .data('xthreshold') and .data('ythreshold') instead.

Bug when unbinding events

When im doing:
$('#button').bind("tapend", function() {console.log("Test")});
$('#button').unbind("tapend");
It works fine i can see "Test" displayed once and then the event is unbinded, but if i do this again :
$('#button').bind("tapend", function() {console.log("Test")});
i'm seeing "Test" 2 times.
Doing the same with event 'click' works fine.

Stopping a link doesn't seem to work

Doing something like -

$('a.someclass').live('singletap', function(e) {
    //some code
    e.preventDefault();
    return false;
});

Doesn't seem to have any effect on canceling out the page redirect. This particular test I did was using jQuery 1.7.2

Object doesn't support this property or method

In IE8, I get this error:

Line: 272
Error: Object doesn't support this property or method

The statement that fails is:
thisObject.addEventListener(settings.startevent, touchStart, false);

This is called from:
$('#slide').on('swipeleft', function(e) { location = document.getElementById('bprev').href; });

The URL that fails is
http://ctwist.jalbum.net/mirage_videos/index.html
If you click on any of the thumbnails and the subsequent navigation buttons, this same error appears on each page.

This works correctly in Firefox, Chrome & Safari.

Double check for delta value

Hi,
thank you for providing this library. Looking at your code I accidentally found if (delta < settings.doubletap_int && delta > 0 && (e.target == origTarget) && delta > 100) {. Looks like your checking for delta twice.

singletap can't be used without doubletap

Hi. I tested your plugin. If we will bind to 'singletap' but not bind to the 'doubletap' and we will double tap on the element then 'singletap' event will be raised twice. I.e. if we have
$element.bind('singletap', function (event) { console.log('stap'); });
and we will double tap on the $element then we will have "stap stap" on console. But there should be nothing.
But in this case:
$element.bind('doubletap', function (event) { }).bind('singletap', function (event) { console.log('stap'); });
if we will double tap then nothing will be in the console

As I understand the problem is that $this.data('doubletapped') changed only when we bind to doubletap event and that's why verification if (!$this.data('doubletapped') && ... which is inside singletap event body is always True.

tapend on an element

Scenarios is I have a carousel with left and right arrows. I used tapstart and tapend events to detect the hold on one of the arrows. It works fine. But, if user tap and hold and then before releasing it drag upwards or downwards. tapend event does not fire resulting an hold state forever.

Other than that Nice Work!

Swiping on a Playbook

The latest version still doesn't let me swipe on a Playbook. It does work if I apply the fix that I described in issue #7.

Void element error

$('#slide').on('swipeleft', function() { document.location = document.getElementById('bnext').href; });
$('#slide').on('swiperight', function() { document.location = document.getElementById('bprev').href; });

If bnext is void, swipeleft behaves like swiperight. I would expect it to do nothing.

Yes, I know I should test for void, but I think you should handle this as well.

BTW If bprev is void, it behaves correctly; a swiperight does nothing.

BTW I am testing mouse gestures, not swiping.

Swiping disables scrolling

I have a situation where horizontal swiping disables vertical scrolling. The code that causes the problem is
if (vPrevPath)
{ $('#index').on('swiperight', function() { document.location = vPrevPath; });
}

An example of this is at
http://ctwist.jalbum.net/temp/index.html

On the first page, vertical scrolling works; vPrevPath is null, so swiperight is not invoked.

Now click on the Demo icon. This opens a page where vPrevPath is not null, so swiperight is invoked, and it works as intended. However, vertical scrolling is disabled. There are no other functions that could affect this. I am using jQuery 1.8.3. The method that fails is fIndexSwipe in http://ctwist.jalbum.net/temp/res/index.js

I think this is a bug. Any suggestions?

isChromeDesktop is always false

isChromeDesktop flag is always false.

change (line: 45):

    isChromeDesktop = ((agent.indexOf('chrome') > -1) && ((agent.indexOf('windows') > -1) || (agent.indexOf('macintosh') > -1) || (agent.indexOf('linux') > -1)) && agent.indexOf('chrome') < 0),

to:

    isChromeDesktop = ((agent.indexOf('chrome') > -1) && ((agent.indexOf('windows') > -1) || (agent.indexOf('macintosh') > -1) || (agent.indexOf('linux') > -1))),

Touch Pixel Range

Hey Ben,

since Android 4.3 your plugin won't trigger the tap event.
I've found out between touchstart and touchend the pixel coordinates change in a range of 5 pixel. I think the resolution of the devices is to big to look on the condition when x-start == x-end && y-start == y-end.

I've fixxed by my self.
Here my fix for tap:

in init:

var settings = {

tap_pixel_range: 5,

in touchend:

var end_x = (e.originalEvent.targetTouches) ? e.originalEvent.changedTouches[0].pageX : e.pageX,
end_y = (e.originalEvent.targetTouches) ? e.originalEvent.changedTouches[0].pageY : e.pageY;
diff_x = (start_pos.x - end_x),
diff_y = (start_pos.y - end_y);

if (
origTarget == e.target && started &&
((new Date().getTime() - start_time) < settings.taphold_threshold) &&
( (start_pos.x == end_x && start_pos.y == end_y) ||
(diff_x >= -(settings.tap_pixel_range) && diff_x <= settings.tap_pixel_range &&
diff_y >= -(settings.tap_pixel_range) && diff_y <= settings.tap_pixel_range))

){

cheers dutscher

swipeleft/swiperight blocking page scroll

Hey Ben. Awesome library.

However, the swipeleft/right events on some screen-width elements are blocking my page scroll. I've run into this in the past with another library and solved it by changing x/y thresholds, but I don't seem to be able to override your settings without changing the script itself.

Can you give me an idea how I'd override the threshold settings? Thanks!

chrome mobiel not workin?

hi there,
i scanned the qr-code link and opened teh link in chrome (latest version in play store).
sadly i get a message in the console "Mobile Events library not found". In chrome on my desktop it works quite right. Are there any known issues on this?

double tap bug

Hi,
if you try to associate double tap event at an element, using .on() (for example):

  • first time that you doubletap it works ok (if you tap doesn't fire the event but if you double tap it's fired)
  • second time (after one double tap) if you tap just one time the doubletap event is fired and of course it's no good.

esample code:

$('#test').on('doubletap.test', function(e){alert(e.type)});

EDIT: there is this issue only if you use some meta for viewport, for example:

meta name="viewport" content="width=device-width, user-scalable=no"
OR
meta name="viewport" content="user-scalable=no"
OR
meta name="viewport" content="width=device-width"

with all of this 3 meta i see the bug. without meta i can use the doubletap event but it zoom the page too.

I'm testing with ipad 3.

Tap doesn't work after scrolling

Hi,

I got an issue while working with the plugin.
The tap event fires perfectly but doesn't when I scroll in my app.

Everytime I bind the event to a DOM element, the tap succeed but if I scroll on my page, then the tap event seems to be disabled and I can't figure out why it happens and how can I resolve this.

Any idea please ?

swipeend is rarely working on Android

I've tested this on two phones and one tablet. The event will trigger if the swipe is fast but not when an average speed. swipeleft and swiperight work fine at any speed.

event is not defined

Hi,

First, thanks for this amazing script, you did a really great job but I found an issue when I'm trying to trigger a "tap" event. I got this error :

"event is not defined". ( line 224 )

It seems that you used event object rather than e. This issue only appear on FF.

If we replace

if(origTarget == event.target && ...

By

if(origTarget == e.target && ...

Everything seems to work fine.

Regards,

swipe events no working

Hi Ben, great work on the library.

I can't get any events to work other than touchstart and touchend. I'm using iPhone 4S, iOS 1.6.2 with Safari and Chrome. I've tried my own example and they demo you provided.

hasOwnProperty not supported in IE8

Recent changes have caused in incompatibility with IE8; hasOwnProperty is not supported.

Message: Object doesn't support this property or method
Line: 38
Char: 9

Second call of double tap if you click 3 times with same interval

Hi! Thx for fixing the bug with interval, but I've found another problem:
if you try to tap 3 times with same intervals it triggers "double tap" two times. And you cannot distinguish tap from double tap too, because if you do 3 taps it calls: "tap tap doubletap tap doubletap"(I cannot define 2 different functions for this both events).

jQuery 1.9.0 NOT SUPPORTED!

Please note that there are some errors now occurring due to updates and changes in the latest release of jQuery (1.9.0 and 2.0 Beta). I am looking into fixing them as we speak, and will report back once the library is safe for use with jQuery 1.9.0+.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.