Skip to content

Commit f558028

Browse files
author
John Doherty
committed
Added swiped event to make it easier to implement
1 parent c5fa9b2 commit f558028

File tree

5 files changed

+25
-6
lines changed

5 files changed

+25
-6
lines changed

README.MD

+10
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ document.addEventListener('swiped-down', function(e) {
4444
});
4545
```
4646

47+
### swiped
48+
49+
```js
50+
document.addEventListener('swiped', function(e) {
51+
console.log(e.target); // element that was swiped
52+
console.log(e.detail); // event data { dir: 'down', xStart: 196, xEnd: 230, yStart: 196, yEnd: 4 }
53+
console.log(e.detail.dir); // swipe direction
54+
});
55+
```
56+
4757
### Configure
4858

4959
You can _optionally_ configure how [swiped-events](https://github.com/john-doherty/swiped-events) works using the following HTML attributes:

dist/swiped-events.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.html

+8
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@
3636

3737
window.onload = function() {
3838

39+
document.addEventListener('swiped', function(e) {
40+
console.log(e.type);
41+
console.log(e.target);
42+
console.log(e.detail);
43+
console.log(e.dir);
44+
e.target.innerHTML = e.type;
45+
});
46+
3947
document.addEventListener('swiped-left', function(e) {
4048
console.log(e.type);
4149
console.log(e.target);

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "swiped-events",
3-
"version": "1.1.1",
3+
"version": "1.1.2",
44
"description": "A 0.7k script that adds swipe events to the DOM for touch enabled devices",
55
"main": "src/swiped-events.js",
66
"scripts": {

src/swiped-events.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,11 @@
8181
yEnd: parseInt((changedTouches[0] || {}).clientY || -1, 10)
8282
};
8383

84-
// fire event on the element that started the swipe
85-
startEl.dispatchEvent(new CustomEvent(eventType, { bubbles: true, cancelable: true, detail: eventData }));
84+
// fire `swiped` event event on the element that started the swipe
85+
startEl.dispatchEvent(new CustomEvent('swiped', { bubbles: true, cancelable: true, detail: eventData }));
8686

87-
// if (console && console.log) console.log(eventType + ' fired on ' + startEl.tagName);
87+
// fire `swiped-dir` event on the element that started the swipe
88+
startEl.dispatchEvent(new CustomEvent(eventType, { bubbles: true, cancelable: true, detail: eventData }));
8889
}
8990

9091
// reset values

0 commit comments

Comments
 (0)