New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ractive-events-tap

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ractive-events-tap - npm Package Compare versions

Comparing version 0.3.0 to 0.3.1

dist/ractive-events-tap.es.js

4

CHANGELOG.md
# changelog
## 0.3.1
* Fix `touchdown` handler error
## 0.3.0

@@ -4,0 +8,0 @@

175

dist/ractive-events-tap.umd.js
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
global.Ractive.events.tap = factory();
(global.Ractive = global.Ractive || {}, global.Ractive.events = global.Ractive.events || {}, global.Ractive.events.tap = factory());
}(this, function () { 'use strict';
var DISTANCE_THRESHOLD = 5; // maximum pixels pointer can move before cancel
var TIME_THRESHOLD = 400; // maximum milliseconds between down and up before cancel
var TIME_THRESHOLD = 400; // maximum milliseconds between down and up before cancel
function tap(node, callback) {
return new TapHandler(node, callback);
function tap ( node, callback ) {
return new TapHandler( node, callback );
}
function TapHandler(node, callback) {
function TapHandler ( node, callback ) {
this.node = node;

@@ -20,23 +20,23 @@ this.callback = callback;

this.bind(node);
this.bind( node );
}
TapHandler.prototype = {
bind: function bind(node) {
bind: function bind ( node ) {
// listen for mouse/pointer events...
if (window.navigator.pointerEnabled) {
node.addEventListener('pointerdown', handleMousedown, false);
node.addEventListener( 'pointerdown', handleMousedown, false );
} else if (window.navigator.msPointerEnabled) {
node.addEventListener('MSPointerDown', handleMousedown, false);
node.addEventListener( 'MSPointerDown', handleMousedown, false );
} else {
node.addEventListener('mousedown', handleMousedown, false);
node.addEventListener( 'mousedown', handleMousedown, false );
// ...and touch events
node.addEventListener( 'touchstart', handleTouchstart, false );
}
// ...and touch events
node.addEventListener('touchstart', handleTouchstart, 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') {
node.addEventListener('focus', handleFocus, false);
if ( node.tagName === 'BUTTON' || node.type === 'button' ) {
node.addEventListener( 'focus', handleFocus, false );
}

@@ -46,3 +46,4 @@

},
fire: function fire(event, x, y) {
fire: function fire ( event, x, y ) {
this.callback({

@@ -55,10 +56,11 @@ node: this.node,

},
mousedown: function mousedown(event) {
var _this = this;
if (this.preventMousedownEvents) {
mousedown: function mousedown ( event ) {
var this$1 = this;
if ( this.preventMousedownEvents ) {
return;
}
if (event.which !== undefined && event.which !== 1) {
if ( event.which !== undefined && event.which !== 1 ) {
return;

@@ -73,17 +75,17 @@ }

var handleMouseup = function handleMouseup(event) {
if (event.pointerId != pointerId) {
var handleMouseup = function (event) {
if ( event.pointerId != pointerId ) {
return;
}
_this.fire(event, x, y);
this$1.fire( event, x, y );
cancel();
};
var handleMousemove = function handleMousemove(event) {
if (event.pointerId != pointerId) {
var handleMousemove = function (event) {
if ( event.pointerId != pointerId ) {
return;
}
if (Math.abs(event.clientX - x) >= DISTANCE_THRESHOLD || Math.abs(event.clientY - y) >= DISTANCE_THRESHOLD) {
if ( ( Math.abs( event.clientX - x ) >= DISTANCE_THRESHOLD ) || ( Math.abs( event.clientY - y ) >= DISTANCE_THRESHOLD ) ) {
cancel();

@@ -93,31 +95,32 @@ }

var cancel = function cancel() {
_this.node.removeEventListener('MSPointerUp', handleMouseup, false);
document.removeEventListener('MSPointerMove', handleMousemove, false);
document.removeEventListener('MSPointerCancel', cancel, false);
_this.node.removeEventListener('pointerup', handleMouseup, false);
document.removeEventListener('pointermove', handleMousemove, false);
document.removeEventListener('pointercancel', cancel, false);
_this.node.removeEventListener('click', handleMouseup, false);
document.removeEventListener('mousemove', handleMousemove, false);
var cancel = function () {
this$1.node.removeEventListener( 'MSPointerUp', handleMouseup, false );
document.removeEventListener( 'MSPointerMove', handleMousemove, false );
document.removeEventListener( 'MSPointerCancel', cancel, false );
this$1.node.removeEventListener( 'pointerup', handleMouseup, false );
document.removeEventListener( 'pointermove', handleMousemove, false );
document.removeEventListener( 'pointercancel', cancel, false );
this$1.node.removeEventListener( 'click', handleMouseup, false );
document.removeEventListener( 'mousemove', handleMousemove, false );
};
if (window.navigator.pointerEnabled) {
this.node.addEventListener('pointerup', handleMouseup, false);
document.addEventListener('pointermove', handleMousemove, false);
document.addEventListener('pointercancel', cancel, false);
} else if (window.navigator.msPointerEnabled) {
this.node.addEventListener('MSPointerUp', handleMouseup, false);
document.addEventListener('MSPointerMove', handleMousemove, false);
document.addEventListener('MSPointerCancel', cancel, false);
if ( window.navigator.pointerEnabled ) {
this.node.addEventListener( 'pointerup', handleMouseup, false );
document.addEventListener( 'pointermove', handleMousemove, false );
document.addEventListener( 'pointercancel', cancel, false );
} else if ( window.navigator.msPointerEnabled ) {
this.node.addEventListener( 'MSPointerUp', handleMouseup, false );
document.addEventListener( 'MSPointerMove', handleMousemove, false );
document.addEventListener( 'MSPointerCancel', cancel, false );
} else {
this.node.addEventListener('click', handleMouseup, false);
document.addEventListener('mousemove', handleMousemove, false);
this.node.addEventListener( 'click', handleMouseup, false );
document.addEventListener( 'mousemove', handleMousemove, false );
}
setTimeout(cancel, TIME_THRESHOLD);
setTimeout( cancel, TIME_THRESHOLD );
},
touchdown: function touchdown() {
var _this2 = this;
touchdown: function touchdown ( event ) {
var this$1 = this;
var touch = event.touches[0];

@@ -130,6 +133,6 @@

var handleTouchup = function handleTouchup(event) {
var handleTouchup = function (event) {
var touch = event.changedTouches[0];
if (touch.identifier !== finger) {
if ( touch.identifier !== finger ) {
cancel();

@@ -142,15 +145,15 @@ return;

// for the benefit of mobile Firefox and old Android browsers, we need this absurd hack.
_this2.preventMousedownEvents = true;
clearTimeout(_this2.preventMousedownTimeout);
this$1.preventMousedownEvents = true;
clearTimeout( this$1.preventMousedownTimeout );
_this2.preventMousedownTimeout = setTimeout(function () {
_this2.preventMousedownEvents = false;
}, 400);
this$1.preventMousedownTimeout = setTimeout( function () {
this$1.preventMousedownEvents = false;
}, 400 );
_this2.fire(event, x, y);
this$1.fire( event, x, y );
cancel();
};
var handleTouchmove = function handleTouchmove(event) {
if (event.touches.length !== 1 || event.touches[0].identifier !== finger) {
var handleTouchmove = function (event) {
if ( event.touches.length !== 1 || event.touches[0].identifier !== finger ) {
cancel();

@@ -160,3 +163,3 @@ }

var touch = event.touches[0];
if (Math.abs(touch.clientX - x) >= DISTANCE_THRESHOLD || Math.abs(touch.clientY - y) >= DISTANCE_THRESHOLD) {
if ( ( Math.abs( touch.clientX - x ) >= DISTANCE_THRESHOLD ) || ( Math.abs( touch.clientY - y ) >= DISTANCE_THRESHOLD ) ) {
cancel();

@@ -166,46 +169,46 @@ }

var cancel = function cancel() {
_this2.node.removeEventListener('touchend', handleTouchup, false);
window.removeEventListener('touchmove', handleTouchmove, false);
window.removeEventListener('touchcancel', cancel, false);
var cancel = function () {
this$1.node.removeEventListener( 'touchend', handleTouchup, false );
window.removeEventListener( 'touchmove', handleTouchmove, false );
window.removeEventListener( 'touchcancel', cancel, false );
};
this.node.addEventListener('touchend', handleTouchup, false);
window.addEventListener('touchmove', handleTouchmove, false);
window.addEventListener('touchcancel', cancel, false);
this.node.addEventListener( 'touchend', handleTouchup, false );
window.addEventListener( 'touchmove', handleTouchmove, false );
window.addEventListener( 'touchcancel', cancel, false );
setTimeout(cancel, TIME_THRESHOLD);
setTimeout( cancel, TIME_THRESHOLD );
},
teardown: function teardown() {
teardown: function teardown () {
var node = this.node;
node.removeEventListener('pointerdown', handleMousedown, false);
node.removeEventListener('MSPointerDown', handleMousedown, false);
node.removeEventListener('mousedown', handleMousedown, false);
node.removeEventListener('touchstart', handleTouchstart, false);
node.removeEventListener('focus', handleFocus, false);
node.removeEventListener( 'pointerdown', handleMousedown, false );
node.removeEventListener( 'MSPointerDown', handleMousedown, false );
node.removeEventListener( 'mousedown', handleMousedown, false );
node.removeEventListener( 'touchstart', handleTouchstart, false );
node.removeEventListener( 'focus', handleFocus, false );
}
};
function handleMousedown(event) {
this.__tap_handler__.mousedown(event);
function handleMousedown ( event ) {
this.__tap_handler__.mousedown( event );
}
function handleTouchstart(event) {
this.__tap_handler__.touchdown(event);
function handleTouchstart ( event ) {
this.__tap_handler__.touchdown( event );
}
function handleFocus() {
this.addEventListener('keydown', handleKeydown, false);
this.addEventListener('blur', handleBlur, false);
function handleFocus () {
this.addEventListener( 'keydown', handleKeydown, false );
this.addEventListener( 'blur', handleBlur, false );
}
function handleBlur() {
this.removeEventListener('keydown', handleKeydown, false);
this.removeEventListener('blur', handleBlur, false);
function handleBlur () {
this.removeEventListener( 'keydown', handleKeydown, false );
this.removeEventListener( 'blur', handleBlur, false );
}
function handleKeydown(event) {
if (event.which === 32) {
// space key
function handleKeydown ( event ) {
if ( event.which === 32 ) { // space key
this.__tap_handler__.fire();

@@ -212,0 +215,0 @@ }

{
"name": "ractive-events-tap",
"version": "0.3.0",
"version": "0.3.1",
"author": "Rich Harris",

@@ -8,16 +8,16 @@ "license": "MIT",

"main": "dist/ractive-events-tap.umd.js",
"jsnext:main": "dist/ractive-events-tap.es6.js",
"jsnext:main": "dist/ractive-events-tap.es.js",
"module": "dist/ractive-events-tap.es.js",
"description": "Tap/fastclick event plugin for Ractive.js",
"devDependencies": {
"babel-preset-es2015-rollup": "^1.0.0",
"chai": "^3.4.1",
"eslint": "^1.10.2",
"mocha": "^2.3.4",
"chai": "^3.5.0",
"eslint": "^3.2.2",
"mocha": "^3.0.1",
"ractive": "^0.7.3",
"rollup": "^0.21.1",
"rollup-plugin-babel": "^2.2.0",
"simulant": "^0.1.5"
"rollup": "^0.34.5",
"rollup-plugin-buble": "^0.12.1",
"simulant": "^0.2.2"
},
"scripts": {
"build": "rm -rf dist && rollup -c -f umd -o dist/ractive-events-tap.umd.js && rollup -c -f es6 -o dist/ractive-events-tap.es6.js",
"build": "rm -rf dist && rollup -c",
"prepublish": "npm run build",

@@ -24,0 +24,0 @@ "lint": "eslint src",

@@ -1,7 +0,11 @@

import babel from 'rollup-plugin-babel';
import buble from 'rollup-plugin-buble';
export default {
entry: 'src/ractive-events-tap.js',
plugins: [ babel() ],
moduleName: 'Ractive.events.tap'
plugins: [ buble() ],
moduleName: 'Ractive.events.tap',
targets: [
{ dest: 'dist/ractive-events-tap.es.js', format: 'es' },
{ dest: 'dist/ractive-events-tap.umd.js', format: 'umd' }
]
};

@@ -20,13 +20,13 @@ const DISTANCE_THRESHOLD = 5; // maximum pixels pointer can move before cancel

// 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 );
// native buttons, and <input type='button'> elements, should fire a tap event

@@ -111,3 +111,3 @@ // when the space key is pressed

touchdown () {
touchdown ( event ) {
const touch = event.touches[0];

@@ -114,0 +114,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc