touchsweep
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -1,221 +0,130 @@ | ||
(function webpackUniversalModuleDefinition(root, factory) { | ||
if(typeof exports === 'object' && typeof module === 'object') | ||
module.exports = factory(); | ||
else if(typeof define === 'function' && define.amd) | ||
define([], factory); | ||
else if(typeof exports === 'object') | ||
exports["TouchSweep"] = factory(); | ||
else | ||
root["TouchSweep"] = factory(); | ||
})(window, function() { | ||
return /******/ (function(modules) { // webpackBootstrap | ||
/******/ // The module cache | ||
/******/ var installedModules = {}; | ||
/******/ | ||
/******/ // The require function | ||
/******/ function __webpack_require__(moduleId) { | ||
/******/ | ||
/******/ // Check if module is in cache | ||
/******/ if(installedModules[moduleId]) { | ||
/******/ return installedModules[moduleId].exports; | ||
/******/ } | ||
/******/ // Create a new module (and put it into the cache) | ||
/******/ var module = installedModules[moduleId] = { | ||
/******/ i: moduleId, | ||
/******/ l: false, | ||
/******/ exports: {} | ||
/******/ }; | ||
/******/ | ||
/******/ // Execute the module function | ||
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); | ||
/******/ | ||
/******/ // Flag the module as loaded | ||
/******/ module.l = true; | ||
/******/ | ||
/******/ // Return the exports of the module | ||
/******/ return module.exports; | ||
/******/ } | ||
/******/ | ||
/******/ | ||
/******/ // expose the modules object (__webpack_modules__) | ||
/******/ __webpack_require__.m = modules; | ||
/******/ | ||
/******/ // expose the module cache | ||
/******/ __webpack_require__.c = installedModules; | ||
/******/ | ||
/******/ // define getter function for harmony exports | ||
/******/ __webpack_require__.d = function(exports, name, getter) { | ||
/******/ if(!__webpack_require__.o(exports, name)) { | ||
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); | ||
/******/ } | ||
/******/ }; | ||
/******/ | ||
/******/ // define __esModule on exports | ||
/******/ __webpack_require__.r = function(exports) { | ||
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { | ||
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); | ||
/******/ } | ||
/******/ Object.defineProperty(exports, '__esModule', { value: true }); | ||
/******/ }; | ||
/******/ | ||
/******/ // create a fake namespace object | ||
/******/ // mode & 1: value is a module id, require it | ||
/******/ // mode & 2: merge all properties of value into the ns | ||
/******/ // mode & 4: return value when already ns object | ||
/******/ // mode & 8|1: behave like require | ||
/******/ __webpack_require__.t = function(value, mode) { | ||
/******/ if(mode & 1) value = __webpack_require__(value); | ||
/******/ if(mode & 8) return value; | ||
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; | ||
/******/ var ns = Object.create(null); | ||
/******/ __webpack_require__.r(ns); | ||
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); | ||
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); | ||
/******/ return ns; | ||
/******/ }; | ||
/******/ | ||
/******/ // getDefaultExport function for compatibility with non-harmony modules | ||
/******/ __webpack_require__.n = function(module) { | ||
/******/ var getter = module && module.__esModule ? | ||
/******/ function getDefault() { return module['default']; } : | ||
/******/ function getModuleExports() { return module; }; | ||
/******/ __webpack_require__.d(getter, 'a', getter); | ||
/******/ return getter; | ||
/******/ }; | ||
/******/ | ||
/******/ // Object.prototype.hasOwnProperty.call | ||
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; | ||
/******/ | ||
/******/ // __webpack_public_path__ | ||
/******/ __webpack_require__.p = ""; | ||
/******/ | ||
/******/ | ||
/******/ // Load entry module and return exports | ||
/******/ return __webpack_require__(__webpack_require__.s = 0); | ||
/******/ }) | ||
/************************************************************************/ | ||
/******/ ([ | ||
/* 0 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
(function (global, factory) { | ||
if (typeof define === "function" && define.amd) { | ||
define(["exports"], factory); | ||
} else if (typeof exports !== "undefined") { | ||
factory(exports); | ||
} else { | ||
var mod = { | ||
exports: {} | ||
}; | ||
factory(mod.exports); | ||
global.touchsweep = mod.exports; | ||
} | ||
})(this, function (_exports) { | ||
"use strict"; | ||
"use strict"; | ||
Object.defineProperty(_exports, "__esModule", { | ||
value: true | ||
}); | ||
_exports.default = void 0; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
var TouchSweep = | ||
/*#__PURE__*/ | ||
function () { | ||
function TouchSweep() { | ||
var element = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document.body; | ||
var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var threshold = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 40; | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
_classCallCheck(this, TouchSweep); | ||
var TouchSweep = | ||
/*#__PURE__*/ | ||
function () { | ||
function TouchSweep() { | ||
var element = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document.body; | ||
var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var threshold = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 40; | ||
_classCallCheck(this, TouchSweep); | ||
this.element = element; | ||
this.eventData = data; | ||
this.threshold = threshold; | ||
this.coords = { | ||
startX: 0, | ||
startY: 0, | ||
endX: 0, | ||
endY: 0 | ||
}; | ||
this.onStart = this.onStart.bind(this); | ||
this.onEnd = this.onEnd.bind(this); | ||
this.bind(); | ||
return this; | ||
} | ||
_createClass(TouchSweep, [{ | ||
key: "onStart", | ||
value: function onStart(event) { | ||
this.coords.startX = event.changedTouches[0].screenX; | ||
this.coords.startY = event.changedTouches[0].screenY; | ||
this.element = element; | ||
this.eventData = data; | ||
this.threshold = threshold; | ||
this.coords = { | ||
startX: 0, | ||
startY: 0, | ||
endX: 0, | ||
endY: 0 | ||
}; | ||
this.onStart = this.onStart.bind(this); | ||
this.onEnd = this.onEnd.bind(this); | ||
this.bind(); | ||
return this; | ||
} | ||
}, { | ||
key: "onEnd", | ||
value: function onEnd(event) { | ||
this.coords.endX = event.changedTouches[0].screenX; | ||
this.coords.endY = event.changedTouches[0].screenY; | ||
this.dispatch(); | ||
} | ||
}, { | ||
key: "bind", | ||
value: function bind() { | ||
this.element.addEventListener('touchstart', this.onStart, false); | ||
this.element.addEventListener('touchend', this.onEnd, false); | ||
} | ||
}, { | ||
key: "unbind", | ||
value: function unbind() { | ||
this.element.removeEventListener('touchstart', this.onStart, false); | ||
this.element.removeEventListener('touchend', this.onEnd, false); | ||
} | ||
}, { | ||
key: "getEventName", | ||
value: function getEventName() { | ||
var threshold = this.threshold; | ||
var _this$coords = this.coords, | ||
startX = _this$coords.startX, | ||
startY = _this$coords.startY, | ||
endX = _this$coords.endX, | ||
endY = _this$coords.endY; | ||
if (endX < startX && Math.abs(endY - startY) < threshold) { | ||
return 'swipeleft'; | ||
_createClass(TouchSweep, [{ | ||
key: "onStart", | ||
value: function onStart(event) { | ||
this.coords.startX = event.changedTouches[0].screenX; | ||
this.coords.startY = event.changedTouches[0].screenY; | ||
} | ||
if (endX > startX && Math.abs(endX - startX) > threshold) { | ||
return 'swiperight'; | ||
}, { | ||
key: "onEnd", | ||
value: function onEnd(event) { | ||
this.coords.endX = event.changedTouches[0].screenX; | ||
this.coords.endY = event.changedTouches[0].screenY; | ||
this.dispatch(); | ||
} | ||
if (endY < startY && Math.abs(endX - startX) < threshold) { | ||
return 'swipeup'; | ||
}, { | ||
key: "bind", | ||
value: function bind() { | ||
this.element.addEventListener('touchstart', this.onStart, false); | ||
this.element.addEventListener('touchend', this.onEnd, false); | ||
} | ||
if (endY > startY && Math.abs(endY - startY) > threshold) { | ||
return 'swipedown'; | ||
}, { | ||
key: "unbind", | ||
value: function unbind() { | ||
this.element.removeEventListener('touchstart', this.onStart, false); | ||
this.element.removeEventListener('touchend', this.onEnd, false); | ||
} | ||
}, { | ||
key: "getEventName", | ||
value: function getEventName() { | ||
var threshold = this.threshold; | ||
var _this$coords = this.coords, | ||
startX = _this$coords.startX, | ||
startY = _this$coords.startY, | ||
endX = _this$coords.endX, | ||
endY = _this$coords.endY; | ||
if (endY === startY && endX === startX) { | ||
return 'tap'; | ||
} | ||
if (endX < startX && Math.abs(endY - startY) < threshold) { | ||
return 'swipeleft'; | ||
} | ||
return ''; | ||
} | ||
}, { | ||
key: "dispatch", | ||
value: function dispatch() { | ||
var eventName = this.getEventName(); | ||
if (endX > startX && Math.abs(endX - startX) > threshold) { | ||
return 'swiperight'; | ||
} | ||
if (!eventName) { | ||
return; | ||
} // TODO: Check browser support | ||
if (endY < startY && Math.abs(endX - startX) < threshold) { | ||
return 'swipeup'; | ||
} | ||
if (endY > startY && Math.abs(endY - startY) > threshold) { | ||
return 'swipedown'; | ||
} | ||
var event = new CustomEvent(eventName, { | ||
detail: this.eventData | ||
}); | ||
this.element.dispatchEvent(event); | ||
} | ||
}]); | ||
if (endY === startY && endX === startX) { | ||
return 'tap'; | ||
} | ||
return TouchSweep; | ||
}(); | ||
return ''; | ||
} | ||
}, { | ||
key: "dispatch", | ||
value: function dispatch() { | ||
var eventName = this.getEventName(); | ||
exports.default = TouchSweep; | ||
if (!eventName) { | ||
return; | ||
} // TODO: Check browser support | ||
/***/ }) | ||
/******/ ])["default"]; | ||
}); | ||
var event = new CustomEvent(eventName, { | ||
detail: this.eventData | ||
}); | ||
this.element.dispatchEvent(event); | ||
} | ||
}]); | ||
return TouchSweep; | ||
}(); | ||
_exports.default = TouchSweep; | ||
}); |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.TouchSweep=t():e.TouchSweep=t()}(window,function(){return function(e){var t={};function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(o,r,function(t){return e[t]}.bind(null,r));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";function o(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var r=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:document.body,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:40;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.element=t,this.eventData=n,this.threshold=o,this.coords={startX:0,startY:0,endX:0,endY:0},this.onStart=this.onStart.bind(this),this.onEnd=this.onEnd.bind(this),this.bind(),this}return function(e,t,n){t&&o(e.prototype,t),n&&o(e,n)}(e,[{key:"onStart",value:function(e){this.coords.startX=e.changedTouches[0].screenX,this.coords.startY=e.changedTouches[0].screenY}},{key:"onEnd",value:function(e){this.coords.endX=e.changedTouches[0].screenX,this.coords.endY=e.changedTouches[0].screenY,this.dispatch()}},{key:"bind",value:function(){this.element.addEventListener("touchstart",this.onStart,!1),this.element.addEventListener("touchend",this.onEnd,!1)}},{key:"unbind",value:function(){this.element.removeEventListener("touchstart",this.onStart,!1),this.element.removeEventListener("touchend",this.onEnd,!1)}},{key:"getEventName",value:function(){var e=this.threshold,t=this.coords,n=t.startX,o=t.startY,r=t.endX,i=t.endY;return r<n&&Math.abs(i-o)<e?"swipeleft":r>n&&Math.abs(r-n)>e?"swiperight":i<o&&Math.abs(r-n)<e?"swipeup":i>o&&Math.abs(i-o)>e?"swipedown":i===o&&r===n?"tap":""}},{key:"dispatch",value:function(){var e=this.getEventName();if(e){var t=new CustomEvent(e,{detail:this.eventData});this.element.dispatchEvent(t)}}}]),e}();t.default=r}]).default}); | ||
(function(a,b){if("function"==typeof define&&define.amd)define(["exports"],b);else if("undefined"!=typeof exports)b(exports);else{var c={exports:{}};b(c.exports),a.touchsweep=c.exports}})(this,function(a){"use strict";function b(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function c(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}function d(a,b,d){return b&&c(a.prototype,b),d&&c(a,d),a}Object.defineProperty(a,"__esModule",{value:!0}),a.default=void 0;var e=function(){function a(){var c=0<arguments.length&&void 0!==arguments[0]?arguments[0]:document.body,d=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},e=2<arguments.length&&void 0!==arguments[2]?arguments[2]:40;return b(this,a),this.element=c,this.eventData=d,this.threshold=e,this.coords={startX:0,startY:0,endX:0,endY:0},this.onStart=this.onStart.bind(this),this.onEnd=this.onEnd.bind(this),this.bind(),this}return d(a,[{key:"onStart",value:function b(a){this.coords.startX=a.changedTouches[0].screenX,this.coords.startY=a.changedTouches[0].screenY}},{key:"onEnd",value:function b(a){this.coords.endX=a.changedTouches[0].screenX,this.coords.endY=a.changedTouches[0].screenY,this.dispatch()}},{key:"bind",value:function a(){this.element.addEventListener("touchstart",this.onStart,!1),this.element.addEventListener("touchend",this.onEnd,!1)}},{key:"unbind",value:function a(){this.element.removeEventListener("touchstart",this.onStart,!1),this.element.removeEventListener("touchend",this.onEnd,!1)}},{key:"getEventName",value:function h(){var a=Math.abs,b=this.threshold,c=this.coords,d=c.startX,e=c.startY,f=c.endX,g=c.endY;return f<d&&a(g-e)<b?"swipeleft":f>d&&a(f-d)>b?"swiperight":g<e&&a(f-d)<b?"swipeup":g>e&&a(g-e)>b?"swipedown":g===e&&f===d?"tap":""}},{key:"dispatch",value:function c(){var a=this.getEventName();if(a){var b=new CustomEvent(a,{detail:this.eventData});this.element.dispatchEvent(b)}}}]),a}();a.default=e}); |
{ | ||
"name": "touchsweep", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Super tiny vanilla JS module to detect swipe direction", | ||
@@ -16,3 +16,5 @@ "keywords": [ | ||
"scripts": { | ||
"build": "webpack" | ||
"dist": "babel src/touchsweep.js --out-file dist/touchsweep.js", | ||
"minify": "babel src/touchsweep.js --out-file dist/touchsweep.min.js --presets minify,@babel/env", | ||
"build": "npm run dist && npm run minify" | ||
}, | ||
@@ -27,11 +29,19 @@ "repository": "git@github.com:scriptex/touchsweep.git", | ||
"devDependencies": { | ||
"@babel/cli": "^7.0.0-beta.51", | ||
"@babel/core": "^7.0.0-beta.51", | ||
"@babel/preset-env": "^7.0.0-beta.51", | ||
"@babel/preset-stage-2": "^7.0.0-beta.51", | ||
"babel-loader": "^8.0.0-beta", | ||
"unminified-webpack-plugin": "^2.0.0", | ||
"webpack": "^4.12.0", | ||
"webpack-cli": "^3.0.8" | ||
} | ||
"@babel/cli": "^7.0.0-rc.1", | ||
"@babel/core": "^7.0.0-rc.1", | ||
"@babel/plugin-proposal-class-properties": "7.0.0-rc.1", | ||
"@babel/plugin-proposal-decorators": "7.0.0-rc.1", | ||
"@babel/plugin-proposal-export-namespace-from": "7.0.0-rc.1", | ||
"@babel/plugin-proposal-function-sent": "7.0.0-rc.1", | ||
"@babel/plugin-proposal-json-strings": "7.0.0-rc.1", | ||
"@babel/plugin-proposal-numeric-separator": "7.0.0-rc.1", | ||
"@babel/plugin-proposal-throw-expressions": "7.0.0-rc.1", | ||
"@babel/plugin-syntax-dynamic-import": "7.0.0-rc.1", | ||
"@babel/plugin-syntax-import-meta": "7.0.0-rc.1", | ||
"@babel/plugin-transform-modules-umd": "^7.0.0-rc.1", | ||
"@babel/preset-env": "^7.0.0-rc.1", | ||
"babel-loader": "^8.0.0-beta.0", | ||
"babel-minify": "^0.4.3" | ||
}, | ||
"dependencies": {} | ||
} |
@@ -1,3 +0,1 @@ | ||
[![GitHub stars](https://img.shields.io/github/stars/scriptex/touchsweep.svg?style=social&label=Stars)](https://github.com/scriptex/touchsweep) | ||
[![GitHub forks](https://img.shields.io/github/forks/scriptex/touchsweep.svg?style=social&label=Fork)](https://github.com/scriptex/touchsweep/network#fork-destination-box) | ||
[![GitHub release](https://img.shields.io/github/release/scriptex/touchsweep.svg)](https://github.com/scriptex/touchsweep/releases/latest) | ||
@@ -10,10 +8,5 @@ [![GitHub issues](https://img.shields.io/github/issues/scriptex/touchsweep.svg)](https://github.com/scriptex/touchsweep/issues) | ||
[![npm](https://img.shields.io/npm/v/touchsweep.svg)](https://www.npmjs.com/package/touchsweep) | ||
[![license](https://img.shields.io/github/license/scriptex/touchsweep.svg)](https://github.com/scriptex/touchsweep) | ||
[![Analytics](https://ga-beacon.appspot.com/UA-83446952-1/github.com/scriptex/touchsweep/README.md)](https://github.com/scriptex/touchsweep/) | ||
[![Open Source Love svg1](https://badges.frapsoft.com/os/v1/open-source.svg?v=103)](https://github.com/scriptex/touchsweep/) | ||
[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://github.com/scriptex/touchsweep/graphs/commit-activity) | ||
[![Greenkeeper badge](https://badges.greenkeeper.io/scriptex/touchsweep.svg)](https://greenkeeper.io/) | ||
[![ForTheBadge built-with-love](http://ForTheBadge.com/images/badges/built-with-love.svg)](https://github.com/scriptex/) | ||
# TouchSweep | ||
@@ -97,5 +90,5 @@ | ||
There is a simple demo illustrating how the AnimateMe library works. | ||
There is a simple demo illustrating how the TouchSweep library works. | ||
Check it out [here](https://github.com/scriptex/animateme/blob/master/demo/index.html) | ||
Check it out [here](https://github.com/scriptex/touchsweep/blob/master/demo/index.html) | ||
@@ -102,0 +95,0 @@ ## LICENSE |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
0
16127
15
8
185
96