Skip to content
This repository was archived by the owner on Dec 26, 2018. It is now read-only.

Commit eb0678e

Browse files
committed
update to README docs
1 parent 291f30b commit eb0678e

File tree

1 file changed

+63
-48
lines changed

1 file changed

+63
-48
lines changed

README.md

Lines changed: 63 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@ This is a component wrapper for Hammer.js 2.0.
88

99
> This plugin requires Vue >= 2.0. For the Vue 1.\*-compatible version, see the `1.0` branch
1010
11-
#### CommonJS
1211

1312
- Available through npm as `vue-touch`.
1413

15-
``` js
16-
var Hammer = require('hammerjs')
17-
var VueTouch = require('vue-touch')
18-
Vue.use(VueTouch, {hammer: Hammer})
19-
```
14+
```Javascript
15+
var VueTouch = require('vue-touch')
16+
Vue.use(VueTouch, {name: 'v-touch'})
17+
```
18+
You can pass an options object as the second argument, which at the moment accepts one property, `name`. It's used to define the name of the component that is registered with Vue and defaults to `'v-touch'`.
2019

2120
#### Direct include
2221

@@ -36,7 +35,7 @@ This is a component wrapper for Hammer.js 2.0.
3635

3736
## API
3837

39-
### Events
38+
### Component Events
4039

4140
vue-touch supports all Hammer Events ot of the box, just bind a listener to the component with `v-on` and vue-touch will setup the Hammer Manager & Recognizer for you.
4241

@@ -49,22 +48,9 @@ vue-touch supports all Hammer Events ot of the box, just bind a listener to the
4948
|**Swipe**|`swipe`, `swipeleft`, `swiperight`, `swipeup`, `swipedown`|`v-on:swipeleft="callback"`|
5049
|**Tap**|`tap`|`v-on:tap="callback"`|
5150

52-
### Event Options
53-
54-
There are two ways to customize recognizer options such as `direction` and `threshold`.
55-
56-
#### Defining Global Options
57-
58-
``` js
59-
// change the threshold for all swipe recognizers
60-
VueTouch.config.swipe = {
61-
threshold: 200
62-
}
63-
```
64-
65-
#### Passing Options as props
51+
### Component Props
6652

67-
Or, you can use the matching `*-options` props to configure the behavior on a specific element:
53+
You can use the matching `*-options` props to pass Hammer options such as `direction` and `threshold`:
6854

6955
``` html
7056
<!-- detect only horizontal pans with a threshold of 100 -->
@@ -83,40 +69,21 @@ There's one prop per `Recognizer` available.
8369
|**Swipe**|`v-bind:swipe-options`|
8470
|**Tap**|`v-bind:tap-options`|
8571

86-
87-
These options will overwrite globally defined ones.
88-
8972
See [Hammer.js documentation](http://hammerjs.github.io/getting-started/) for all available options for events.
9073

91-
## Registering Custom Events
74+
#### Directions
9275

93-
You can register custom events with vue-touch.
94-
95-
``` js
96-
// example registering a custom doubletap event.
97-
// the `type` indicates the base recognizer to use from Hammer
98-
// all other options are Hammer recognizer options.
99-
VueTouch.registerCustomEvent('doubletap', {
100-
type: 'tap',
101-
taps: 2
102-
})
103-
```
104-
> **Warning**: You have to register your custom events *before* installing the plugin with `Vue.use(VueTouch)`.
105-
VueTouch will log a warning to the console (in dev mode) if you try to do that afterwards, and the event will not work.
76+
In the above example, not that we used `direction: 'horizontal'`. Hammer's directions interface is a little ugly (Hammer['DIRECTION_HORIZONTAL']).
10677

107-
This will make it possible to listen for this event on `<v-touch>`. Additionally, just like for "normal" events, you can pass further options as the corresponding prop.
78+
VueTouch keeps that from you and accepts simple strings as directions:
10879

109-
``` html
110-
<v-touch v-on:doubletap="onDoubleTap"></v-touch>
111-
<!-- with local options -->
112-
<v-touch v-on:doubletap="onDoubleTap" v-bind:doubletap-options="{intervall: 250}"></v-touch>
80+
```javascript
81+
const directions = ['up', 'down', 'left', 'right', 'horizontal', 'vertical', 'all']
11382
```
11483

115-
See `/example` for a multi-event demo. To build it, run `npm install && npm run build`.
84+
## Public Component Methods
11685

117-
## Public Methods
118-
119-
The vue-touch exposes a few convenience methods to enable and disable Recognizers:
86+
The component exposes a few convenience methods to enable and disable Recognizers:
12087

12188
|Method|Explanation|
12289
|------|-----------|
@@ -144,6 +111,54 @@ The vue-touch exposes a few convenience methods to enable and disable Recognizer
144111
</script>
145112
```
146113

114+
### Plugin Methods
115+
116+
#### Global Event Options
117+
118+
You can define global defaults for the builtin recognizers
119+
120+
``` js
121+
// change the threshold for all swipe recognizers
122+
VueTouch.config.swipe = {
123+
threshold: 200
124+
}
125+
```
126+
127+
#### Registering Custom Events
128+
129+
You can register custom events with vue-touch.
130+
131+
``` js
132+
// example registering a custom doubletap event.
133+
// the `type` indicates the base recognizer to use from Hammer
134+
// all other options are Hammer recognizer options.
135+
VueTouch.registerCustomEvent('doubletap', {
136+
type: 'tap',
137+
taps: 2
138+
})
139+
```
140+
> **Warning**: You have to register your custom events *before* installing the plugin with `Vue.use(VueTouch)`.
141+
VueTouch will log a warning to the console (in dev mode) if you try to do that afterwards, and the event will not work.
142+
143+
This will make it possible to listen for this event on `<v-touch>`. Additionally, just like for "normal" events, you can pass further options as the corresponding prop.
144+
145+
``` html
146+
<v-touch v-on:doubletap="onDoubleTap"></v-touch>
147+
<!-- with local options -->
148+
<v-touch v-on:doubletap="onDoubleTap" v-bind:doubletap-options="{intervall: 250}"></v-touch>
149+
```
150+
151+
See `/example` for a multi-event demo. To build it, run `npm install && npm run build`.
152+
153+
## Known Limitations & Bugs
154+
155+
* Curently, changing `-options` props will not change recogizer settings. The initial values will stay in place until the component is re-created.
156+
157+
## TODO
158+
159+
* [ ] Support updating recognizer options when props change.
160+
* [ ] Find out if e2e tests are possible(contribution welcome)
161+
147162
## License
148163

149164
[MIT](http://opensource.org/licenses/MIT)

0 commit comments

Comments
 (0)