Skip to content

Commit

Permalink
Add disableClick option back and release v2.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jerrybendy committed Nov 9, 2019
1 parent 5deaaeb commit 2f42a75
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,20 @@ In your `.vue` file:

```js
Vue.use(Vue2TouchEvents, {
disableClick: false,
touchClass: '',
tapTolerance: 10,
swipeTolerance: 30,
longTapTimeInterval: 400
})
```

* `disableClick` default `false`. Use touch event only, will not trigger click event.

You should keep this value default if you use your website on both mobile and PC.

If your website uses on mobile only, it's a good choice to set this value to `true` to get a better user experience, and it can resolve some touch pass-through issue.

* `touchClass` default: `''`. Add an extra CSS class when touch start, and remove it when touch end.

This is a global config, and you can use `v-touch-class` directive to overwrite this setting in a single component.
Expand Down
24 changes: 14 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,13 @@ var vueTouchEvents = {
$el.addEventListener('touchcancel', touchCancelEvent)
$el.addEventListener('touchend', touchEndEvent)

$el.addEventListener('mousedown', touchStartEvent)
$el.addEventListener('mousemove', touchMoveEvent)
$el.addEventListener('mouseup', touchEndEvent)
$el.addEventListener('mouseenter', mouseEnterEvent)
$el.addEventListener('mouseleave', mouseLeaveEvent)
if (!options.disableClick) {
$el.addEventListener('mousedown', touchStartEvent)
$el.addEventListener('mousemove', touchMoveEvent)
$el.addEventListener('mouseup', touchEndEvent)
$el.addEventListener('mouseenter', mouseEnterEvent)
$el.addEventListener('mouseleave', mouseLeaveEvent)
}

// set bind mark to true
$el.$$touchObj.hasBindTouchEvents = true
Expand All @@ -285,11 +287,13 @@ var vueTouchEvents = {
$el.removeEventListener('touchcancel', touchCancelEvent)
$el.removeEventListener('touchend', touchEndEvent)

$el.removeEventListener('mousedown', touchStartEvent)
$el.removeEventListener('mousemove', touchMoveEvent)
$el.removeEventListener('mouseup', touchEndEvent)
$el.removeEventListener('mouseenter', mouseEnterEvent)
$el.removeEventListener('mouseleave', mouseLeaveEvent)
if (!options.disableClick) {
$el.removeEventListener('mousedown', touchStartEvent)
$el.removeEventListener('mousemove', touchMoveEvent)
$el.removeEventListener('mouseup', touchEndEvent)
$el.removeEventListener('mouseenter', mouseEnterEvent)
$el.removeEventListener('mouseleave', mouseLeaveEvent)
}

// remove vars
delete $el.$$touchObj
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue2-touch-events",
"version": "2.0.0",
"version": "2.0.1",
"description": "Simple touch events support for vueJS2",
"main": "index.js",
"types": "index.d.ts",
Expand Down

0 comments on commit 2f42a75

Please sign in to comment.