pukhalski / tap

1Kb library for easy unified handling of user interactions such as mouse, touch and pointer events.
https://github.com/pukhalski/tap/archive/master.zip
MIT License
527 stars 45 forks source link
delay pointer-events tap touch touch-events

TAP.JS [DEPRECATED]

Tap is a Javascript library for easy unified handling of user interactions such as mouse, touch and pointer events.

Installation

If you are using Bower:

bower install tap

For npm users:

npm install tapjs

Otherwise just download the library.

Include it anywhere in your html file (it does not matter where — in <head> or not):

<script src="https://github.com/pukhalski/tap/raw/master/bower_components/tap/dist/tap.min.js"></script>

Usage

Using Tap is super easy. Just handle the 'tap' event in a way you are familiar with:

document.getElementById('any-element').addEventListener('tap', function (e) {
    // All the magic happens here
});

With jQuery

$('#any-element').on('tap', function (e) {
    // All the magic happens here
});

With Zepto

$('#any-element').on('tap', function (e) {
    // All the magic happens here
});

With Dojo

var myButton = dojo.byId('any-element');
dojo.connect(myButton, 'tap', function(e){
    // All the magic happens here
});

With YUI

YUI().use('event', 'node', function (Y) {
    Y.one('#any-element').on('tap', function(e) {
        // All the magic happens here
    });
});

With ExtJS

Ext.get('any-element').on('tap', function (e) {
    // All the magic happens here
});

With Meteor

First, install Meteor package:

meteor add jimbog:tap

Then, the tap event is used just like any other event in Meteor, here is an example for an anchor element:

Template.MyTemplate.events({
    'tap a': function(evt, tmpl){
        evt.preventDefault();
        console.log('you tapped the link');
    }
})

With Angular

Just add the code below or dist/tap.angular.js to your project, and use ng-tap insted of ng-click. Do not forget add ngTap as a dependency.

angular.module('ngTap', []).directive('ngTap', function() {
    return function(scope, element, attrs) {
        element.bind('tap', function() {
            scope.$apply(attrs['ngTap'], element);
        });
    };
});

With Knockout

tap is not in the list of known events for Knockout, so use custom event binding to handle tap event:

<button data-bind="event: {tap: onAddToCart}">Add to cart</button>

Browser Support

Tap was tested on the wide range of devices:

And browsers:

It doesn't mean that all other platforms and browsers (or older versions of them) are not supported.

LICENSE

Tap is distributed under MIT license. Enjoy!

Bitdeli Badge