You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+36-20Lines changed: 36 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
A smart-package for integrating with [Hammer.js](https://github.com/hammerjs/hammer.js) for multi-touch gesture support in your Templates.
4
4
5
-
*From version `4.0.0` onwards, there is a new API. For help migrating your existing implementation over to the new API, see [MIGRATION.md](https://github.com/chriswessels/meteor-hammer/blob/master/MIGRATION.md).*
5
+
Out of the box it supports Panning, Pinching, (Long) Pressing, Rotating, Swiping and Tapping. You can also register and use custom compound gestures.
6
6
7
7
## Basic Usage
8
8
@@ -24,7 +24,7 @@ Template.foo.helpers({
24
24
'swipeleft ul li':function (event, templateInstance) {
25
25
/* `event` is the Hammer.js event object */
26
26
/* `templateInstance` is the `Blaze.TemplateInstance` */
27
-
/* `this` is the data context of the element in your template, so in this case the iteree from someArray in the template */
27
+
/* `this` is the data context of the element in your template, so in this case `someField` from `someArray` in the template */
28
28
}
29
29
}
30
30
});
@@ -40,32 +40,44 @@ In your Meteor.js project directory, run
40
40
41
41
## API
42
42
43
-
The `HammerTouchArea` template block helper is your interface for enabling multi-touch gestures in your templates. Generally, you only need one occurrence of `HammerTouchArea` in each template you want to specify gestural behaviour for.
43
+
The `HammerTouchArea` template block helper is your interface for enabling gestures in your templates. Generally, you only need one occurrence of `HammerTouchArea` in each template you want to specify gestural behaviour for.
44
44
45
-
A template block helper consists of a start tag and an end tag. The start tag looks like this, `{{#HammerTouchArea property1=value1 property2=value2}}` (where `property1` and `property2` are properties being set on the helper), and the end tag looks like this, `{{/HammerTouchArea}}`. In between the start and end tags, you can put your own template code.
45
+
### HammerTouchArea
46
46
47
-
You will need to pass an object into `HammerTouchArea` via the `gestureMap` property that maps selectors to callbacks. This is a required property and a warning will be printed to the browser console if you leave it out.
47
+
In order to define which gestures you want to attach behaviour to, you'll need to pass an object into `HammerTouchArea` via the `gestureMap` property.
48
48
49
-
The API for this object, a gesture map, is identical to the event map that you pass into `Template.foo.events`. The object keys should follow the format `gestureName cssSelector` (or multiple strings in this format separated by a comma, e.g. `tap .foo, swiperight .bar`) and the value should be a callback function that is executed when the specified gestures are performed on the element(s) matching the CSS selector(s). Example of a gesture map object:
49
+
An instance of `HammerTouchArea` looks like this in your HTML:
<!-- Gestures on HTML in here will register in your gestureMap. See below. -->
57
+
</div>
58
+
{{/HammerTouchArea}}
59
+
<!-- HammerTouchArea end tag above -->
60
+
</div>
61
+
```
62
+
63
+
### Gesture Maps
64
+
65
+
A gesture map object ties selector strings to callback functions. It lets you specify which elements inside the `HammerTouchArea` you want to attach behaviour to, and which code should run when those touch gestures are detected. It follows exactly the same format as the object you pass into `Template.fooBar.events`.
66
+
67
+
The object's keys should follow the format `gestureName cssSelector` (or multiple strings in this format separated by a comma, e.g. `tap .foo, swiperight .bar`) and the value should be a callback function that is executed when the specified gestures are performed on the element(s) matching the CSS selector(s).
68
+
69
+
Generally you should define your gesture map as a template helper so that you can pass it into the `gestureMap` property of your `HammerTouchArea`.
63
70
64
-
/* This is a gesture map being returned by a helper: */
71
+
Example of defining a gesture map object as a helper:
72
+
73
+
```javascript
74
+
/* This is a gesture map being returned by a helper named `templateGestures`: */
@@ -169,6 +181,10 @@ If you have provided a `configureCallback`, this is callback executed and passed
169
181
170
182
The gesture map that you pass into `HammerTouchArea` via the `gestureMap` property is parsed, and a series of generic gesture callbacks are attached to the `Hammer.Manager` instance. When these fire (as a result of touch actions being performed on the template DOM), they determine whether any of the current touch behaviour matches the selectors you specified in the gesture map, and if so, your callbacks are fired.
171
183
184
+
## Migrating from < 4.0.0
185
+
186
+
From version `4.0.0` onwards, there is a new API. For help migrating your existing implementation over to the new API, see [MIGRATION.md](https://github.com/chriswessels/meteor-hammer/blob/master/MIGRATION.md).
187
+
172
188
## License
173
189
174
190
Please see the `LICENSE` file for more information.
0 commit comments