swiped-events
Advanced tools
Comparing version 1.1.1 to 1.1.2
/*! | ||
* swiped-events.js - v1.1.1 | ||
* swiped-events.js - v1.1.2 | ||
* Pure JavaScript swipe events | ||
@@ -9,2 +9,2 @@ * https://github.com/john-doherty/swiped-events | ||
*/ | ||
!function(t,e){"use strict";"function"!=typeof t.CustomEvent&&(t.CustomEvent=function(t,n){n=n||{bubbles:!1,cancelable:!1,detail:void 0};var a=e.createEvent("CustomEvent");return a.initCustomEvent(t,n.bubbles,n.cancelable,n.detail),a},t.CustomEvent.prototype=t.Event.prototype),e.addEventListener("touchstart",function(t){if("true"===t.target.getAttribute("data-swipe-ignore"))return;s=t.target,r=Date.now(),n=t.touches[0].clientX,a=t.touches[0].clientY,u=0,i=0},!1),e.addEventListener("touchmove",function(t){if(!n||!a)return;var e=t.touches[0].clientX,r=t.touches[0].clientY;u=n-e,i=a-r},!1),e.addEventListener("touchend",function(t){if(s!==t.target)return;var e=parseInt(s.getAttribute("data-swipe-threshold")||"20",10),l=parseInt(s.getAttribute("data-swipe-timeout")||"500",10),o=Date.now()-r,c="",d=t.changedTouches||t.touches||[];Math.abs(u)>Math.abs(i)?Math.abs(u)>e&&o<l&&(c=u>0?"swiped-left":"swiped-right"):Math.abs(i)>e&&o<l&&(c=i>0?"swiped-up":"swiped-down");if(""!==c){var p={dir:c.replace(/swiped-/,""),xStart:parseInt(n,10),xEnd:parseInt((d[0]||{}).clientX||-1,10),yStart:parseInt(a,10),yEnd:parseInt((d[0]||{}).clientY||-1,10)};s.dispatchEvent(new CustomEvent(c,{bubbles:!0,cancelable:!0,detail:p}))}n=null,a=null,r=null},!1);var n=null,a=null,u=null,i=null,r=null,s=null}(window,document); | ||
!function(t,e){"use strict";"function"!=typeof t.CustomEvent&&(t.CustomEvent=function(t,n){n=n||{bubbles:!1,cancelable:!1,detail:void 0};var a=e.createEvent("CustomEvent");return a.initCustomEvent(t,n.bubbles,n.cancelable,n.detail),a},t.CustomEvent.prototype=t.Event.prototype),e.addEventListener("touchstart",function(t){if("true"===t.target.getAttribute("data-swipe-ignore"))return;l=t.target,s=Date.now(),n=t.touches[0].clientX,a=t.touches[0].clientY,u=0,i=0},!1),e.addEventListener("touchmove",function(t){if(!n||!a)return;var e=t.touches[0].clientX,s=t.touches[0].clientY;u=n-e,i=a-s},!1),e.addEventListener("touchend",function(t){if(l!==t.target)return;var e=parseInt(l.getAttribute("data-swipe-threshold")||"20",10),r=parseInt(l.getAttribute("data-swipe-timeout")||"500",10),o=Date.now()-s,c="",d=t.changedTouches||t.touches||[];Math.abs(u)>Math.abs(i)?Math.abs(u)>e&&o<r&&(c=u>0?"swiped-left":"swiped-right"):Math.abs(i)>e&&o<r&&(c=i>0?"swiped-up":"swiped-down");if(""!==c){var p={dir:c.replace(/swiped-/,""),xStart:parseInt(n,10),xEnd:parseInt((d[0]||{}).clientX||-1,10),yStart:parseInt(a,10),yEnd:parseInt((d[0]||{}).clientY||-1,10)};l.dispatchEvent(new CustomEvent("swiped",{bubbles:!0,cancelable:!0,detail:p})),l.dispatchEvent(new CustomEvent(c,{bubbles:!0,cancelable:!0,detail:p}))}n=null,a=null,s=null},!1);var n=null,a=null,u=null,i=null,s=null,l=null}(window,document); |
{ | ||
"name": "swiped-events", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "A 0.7k script that adds swipe events to the DOM for touch enabled devices", | ||
@@ -5,0 +5,0 @@ "main": "src/swiped-events.js", |
@@ -47,2 +47,12 @@ # swiped-events | ||
### swiped | ||
```js | ||
document.addEventListener('swiped', function(e) { | ||
console.log(e.target); // element that was swiped | ||
console.log(e.detail); // event data { dir: 'down', xStart: 196, xEnd: 230, yStart: 196, yEnd: 4 } | ||
console.log(e.detail.dir); // swipe direction | ||
}); | ||
``` | ||
### Configure | ||
@@ -49,0 +59,0 @@ |
@@ -84,6 +84,7 @@ /*! | ||
// fire event on the element that started the swipe | ||
// fire `swiped` event event on the element that started the swipe | ||
startEl.dispatchEvent(new CustomEvent('swiped', { bubbles: true, cancelable: true, detail: eventData })); | ||
// fire `swiped-dir` event on the element that started the swipe | ||
startEl.dispatchEvent(new CustomEvent(eventType, { bubbles: true, cancelable: true, detail: eventData })); | ||
// if (console && console.log) console.log(eventType + ' fired on ' + startEl.tagName); | ||
} | ||
@@ -90,0 +91,0 @@ |
Sorry, the diff of this file is not supported yet
222351
163
116