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

Commit c776f81

Browse files
committed
update for 1.0
1 parent deb8d13 commit c776f81

8 files changed

+61
-59
lines changed

.gitignore

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
components
21
node_modules
32
.DS_Store
4-
example/example.build.js
3+
example/example.build.js

README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,23 @@ This is a directive wrapper for Hammer.js 2.0.
88

99
### CommonJS
1010

11-
- Available through npm as `vue-touch`. For Duo/Component you can install as `vuejs/vue-touch`.
11+
- Available through npm as `vue-touch`.
1212

1313
``` js
14-
var vueTouch = require('vue-touch')
15-
Vue.use(vueTouch)
14+
var VueTouch = require('vue-touch')
15+
Vue.use(VueTouch)
1616
```
1717

1818
### Direct include
1919

20-
- You can also directly include it with a `<script>` tag when you have Vue itself included globally. It will automatically install itself, and will add a global `VueTouch`.
20+
- You can also directly include it with a `<script>` tag when you have Vue and Hammer.js already included globally. It will automatically install itself, and will add a global `VueTouch`.
2121

22-
### Use in templates
22+
### Using the `v-touch` directive
2323

2424
Then you can do this:
2525

2626
``` html
27-
<a v-touch="tap:onTap">Tap me!</a>
27+
<a v-touch:tap="onTap">Tap me!</a>
2828
```
2929

3030
### Register a custom event
@@ -41,7 +41,7 @@ VueTouch.registerCustomEvent('doubletap', {
4141

4242
See [Hammer.js documentation](http://hammerjs.github.io/getting-started/) for all available events.
4343

44-
See `/example` for a multi-event demo. To build the example, you need to have Browserify installed and then `npm run build`.
44+
See `/example` for a multi-event demo. To build it, run `npm install && npm run build`.
4545

4646
## License
4747

bower.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
{
22
"name": "vue-touch",
3-
"version": "0.1.2",
43
"main": "vue-touch.js",
54
"description": "Hammer.js based touch events plugin for Vue.js",
65
"authors": ["Evan You <[email protected]>"],
76
"license": "MIT",
87
"dependencies": {
9-
"hammerjs": "^2.0.1"
8+
"hammerjs": "^2.0.6"
109
},
1110
"ignore": [
1211
".*",
1312
"example",
1413
"*.json",
1514
"*.md"
1615
]
17-
}
16+
}

component.json

-14
This file was deleted.

example/example.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ new Vue({
2222
this.event = e.type
2323
}
2424
}
25-
})
25+
})

example/index.html

+26-14
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,31 @@
1-
<style>
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
6+
<title></title>
7+
<style>
28
div {
39
width: 300px;
410
height: 300px;
511
background-color: #f00;
612
}
7-
</style>
8-
9-
<div v-touch="
10-
tap:test,
11-
pan:test,
12-
press:test,
13-
swipe:test,
14-
pinch:test,
15-
rotate:test,
16-
doubletap: test
17-
" v-text="event"></div>
18-
19-
<script src="example.build.js"></script>
13+
</style>
14+
</head>
15+
<body>
16+
<div
17+
v-touch:tap="test"
18+
v-touch:pan="test"
19+
v-touch:press="test"
20+
v-touch:swipeLeft="test"
21+
v-touch:swipeRight="test"
22+
v-touch:swipeUp="test"
23+
v-touch:swipeDown="test"
24+
v-touch:pinch="test"
25+
v-touch:rotate="test"
26+
v-touch:doubletap="test"
27+
v-text="event">
28+
</div>
29+
<script src="example.build.js"></script>
30+
</body>
31+
</html>

package.json

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
{
22
"name": "vue-touch",
3-
"version": "0.1.2",
3+
"version": "1.0.0",
44
"main": "vue-touch.js",
5+
"files": [
6+
"vue-touch.js"
7+
],
58
"description": "Hammer.js based touch events plugin for Vue.js",
69
"license": "MIT",
710
"repository": {
@@ -10,13 +13,14 @@
1013
},
1114
"bugs": "https://github.com/vuejs/vue-touch/issues",
1215
"dependencies": {
13-
"hammerjs": "^2.0.1"
16+
"hammerjs": "^2.0.6"
1417
},
1518
"devDependencies": {
16-
"vue": "^0.10.5"
19+
"vue": "^1.0.16",
20+
"webpack": "^1.12.12"
1721
},
1822
"scripts": {
19-
"build": "browserify -e example/example.js -o example/example.build.js",
20-
"dev": "watchify -e example/example.js -o example/example.build.js"
23+
"build": "webpack example/example.js example/example.build.js",
24+
"dev": "webpack --watch example/example.js example/example.build.js"
2125
}
2226
}

vue-touch.js

+15-13
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
var gestures = ['tap', 'pan', 'pinch', 'press', 'rotate', 'swipe']
88
var customeEvents = {}
99

10+
if (!Hammer) {
11+
throw new Error('[vue-touch] cannot locate Hammer.js.')
12+
}
13+
1014
vueTouch.install = function (Vue) {
1115

1216
Vue.directive('touch', {
@@ -21,26 +25,28 @@
2125
var mc = this.mc = this.el.hammer
2226
// determine event type
2327
var event = this.arg
28+
if (!event) {
29+
console.warn('[vue-touch] event type argument is required.')
30+
}
2431
var recognizerType, recognizer
2532

26-
if (customeEvents[event]) { // custom event
27-
33+
if (customeEvents[event]) {
34+
// custom event
2835
var custom = customeEvents[event]
2936
recognizerType = custom.type
3037
recognizer = new Hammer[capitalize(recognizerType)](custom)
3138
recognizer.recognizeWith(mc.recognizers)
3239
mc.add(recognizer)
33-
34-
} else { // built-in event
35-
40+
} else {
41+
// built-in event
3642
for (var i = 0; i < gestures.length; i++) {
3743
if (event.indexOf(gestures[i]) === 0) {
3844
recognizerType = gestures[i]
3945
break
4046
}
4147
}
4248
if (!recognizerType) {
43-
console.warn('Invalid v-touch event: ' + event)
49+
console.warn('[vue-touch] invalid event type: ' + event)
4450
return
4551
}
4652
recognizer = mc.get(recognizerType)
@@ -51,7 +57,6 @@
5157
recognizer.recognizeWith(mc.recognizers)
5258
mc.add(recognizer)
5359
}
54-
5560
}
5661
},
5762

@@ -64,11 +69,8 @@
6469
mc.off(event, this.handler)
6570
}
6671
// define new handler
67-
this.handler = function (e) {
68-
e.targetVM = vm
69-
fn.call(vm, e)
70-
}
71-
mc.on(event, this.handler)
72+
this.handler = fn
73+
mc.on(event, fn)
7274
},
7375

7476
unbind: function () {
@@ -109,4 +111,4 @@
109111
Vue.use(vueTouch)
110112
}
111113

112-
})()
114+
})()

0 commit comments

Comments
 (0)