Skip to content

Commit

Permalink
gallery-2014.04.02-20-01 tilomitra gallery-event-hammer
Browse files Browse the repository at this point in the history
  • Loading branch information
Clarence Leung committed Apr 2, 2014
1 parent d99c2af commit 781593c
Showing 17 changed files with 484 additions and 0 deletions.
6 changes: 6 additions & 0 deletions build/gallery-event-hammer/gallery-event-hammer-coverage.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 71 additions & 0 deletions build/gallery-event-hammer/gallery-event-hammer-debug.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
YUI.add('gallery-event-hammer', function (Y, NAME) {

/*
Copyright 2013 Yahoo! Inc.
Licensed under the BSD License.
http://yuilibrary.com/license/
*/

'use strict';
var HAMMER_GESTURES = [
'hold',
'tap',
'doubletap',
'drag',
'dragstart',
'dragend',
'dragup',
'dragdown',
'dragleft',
'dragright',
'swipe',
'swipeup',
'swipedown',
'swipeleft',
'swiperight',
'transform',
'transformstart',
'transformend',
'rotate',
'pinch',
'pinchin',
'pinchout',
'touch',
'release'
];

Y.Array.each(HAMMER_GESTURES, function (gesture) {
Y.Event.define(gesture, {
_hammer: undefined,
processArgs: function (args, isDelegate) {
// The args list will look like this coming in:
// [ type, callback, node, (extras...), [filter,] thisObj, arg0...argN ]
return args.splice(3,1)[0];
},
on: function (node, subscription, notifier) {
var params = subscription._extra,
self = this;

// Delegate the gesture event to HammerJS.
this._hammer = Hammer(node.getDOMNode(), params).on(gesture, function (ev) {
self.handleHammerEvent(ev, node, subscription, notifier);
});
},

handleHammerEvent: function (ev, node, subscription, notifier) {
//event facade normalization
notifier.fire(ev);
},

_off: function () {
this._hammer.off(this.type, this.handleHammerEvent);
},

detach: function () {
this._off();
}
});
});


}, 'gallery-2014.04.02-20-01', {"requires": ["node-base", "event-touch", "event-synthetic"]});
1 change: 1 addition & 0 deletions build/gallery-event-hammer/gallery-event-hammer-min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 71 additions & 0 deletions build/gallery-event-hammer/gallery-event-hammer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
YUI.add('gallery-event-hammer', function (Y, NAME) {

/*
Copyright 2013 Yahoo! Inc.
Licensed under the BSD License.
http://yuilibrary.com/license/
*/

'use strict';
var HAMMER_GESTURES = [
'hold',
'tap',
'doubletap',
'drag',
'dragstart',
'dragend',
'dragup',
'dragdown',
'dragleft',
'dragright',
'swipe',
'swipeup',
'swipedown',
'swipeleft',
'swiperight',
'transform',
'transformstart',
'transformend',
'rotate',
'pinch',
'pinchin',
'pinchout',
'touch',
'release'
];

Y.Array.each(HAMMER_GESTURES, function (gesture) {
Y.Event.define(gesture, {
_hammer: undefined,
processArgs: function (args, isDelegate) {
// The args list will look like this coming in:
// [ type, callback, node, (extras...), [filter,] thisObj, arg0...argN ]
return args.splice(3,1)[0];
},
on: function (node, subscription, notifier) {
var params = subscription._extra,
self = this;

// Delegate the gesture event to HammerJS.
this._hammer = Hammer(node.getDOMNode(), params).on(gesture, function (ev) {
self.handleHammerEvent(ev, node, subscription, notifier);
});
},

handleHammerEvent: function (ev, node, subscription, notifier) {
//event facade normalization
notifier.fire(ev);
},

_off: function () {
this._hammer.off(this.type, this.handleHammerEvent);
},

detach: function () {
this._off();
}
});
});


}, 'gallery-2014.04.02-20-01', {"requires": ["node-base", "event-touch", "event-synthetic"]});
7 changes: 7 additions & 0 deletions src/gallery-event-hammer/HISTORY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
gallery-event-hammer
====================

## 0.0.0 (2014-04-02)

* __[!]__ Initial Release - not ready for any serious development. Alpha version.

9 changes: 9 additions & 0 deletions src/gallery-event-hammer/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Copyright 2013 Yahoo! Inc.

Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of Yahoo! Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of Yahoo! Inc.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
95 changes: 95 additions & 0 deletions src/gallery-event-hammer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
gallery-event-hammer
====================

This module lets you leverage all gesture events from [HammerJS](eightmedia.github.io/hammer.js/).

## Usage

First, add HammerJS and YUI on the page. HammerJS must be loaded separately as it is not bundled with this module.

```html
<script src="http://yui.yahooapis.com/3.15.0/build/yui/yui-min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/hammer.js/1.0.6/hammer.min.js"></script>
```

Then, you can add `gallery-event-hammer` in your `YUI().use()` statement.

```js
YUI().use('node', 'gallery-event-hammer', function (Y) {

//Use all the HammerJS gesture goodness
Y.one('#myNode').on('swipeleft', function (ev) {
console.log(ev.gesture);
console.log('swiping left!')
});

});
```

## Passing in options
You can also pass in [all the options](https://github.com/EightMedia/hammer.js/wiki/Getting-Started#gesture-options) that HammerJS supports in an optional 3rd argument to `on()`:

```js
Y.one('#myNode').on(['drag', 'swipe'], function (ev) {

if (ev.type === 'drag')
console.log('dragging!');
else
console.log('swiping!');

}, {prevent_default: true, drag_block_vertical: true});
```


## Supported Gestures

All of these:

```js
var HAMMER_GESTURES = [
'hold',
'tap',
'doubletap',
'drag',
'dragstart',
'dragend',
'dragup',
'dragdown',
'dragleft',
'dragright',
'swipe',
'swipeup',
'swipedown',
'swipeleft',
'swiperight',
'transform',
'transformstart',
'transformend',
'rotate',
'pinch',
'pinchin',
'pinchout',
'touch',
'release'
];
```

## Tested on

* **HammerJS 1.0.9**
* Latest Safari
* Latest Chrome
* Latest Firefox
* Android 4.3
* iOS 7.1

## TODO

* Event Delegation
* Lots of code cleanup
* Performance Work around multiple Hammer instances
* Figure out how HammerJS options and YUI Synthetic Event options would work together

## Note

This is more of an experiment for now. Do not use it in code that is important.
10 changes: 10 additions & 0 deletions src/gallery-event-hammer/build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "gallery-event-hammer",
"builds": {
"gallery-event-hammer": {
"jsfiles": [
"js/gallery-event-hammer.js"
]
}
}
}
11 changes: 11 additions & 0 deletions src/gallery-event-hammer/docs/component.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name" : "gallery-event-hammer",
"displayName": "Gallery: gallery-event-hammer",
"description": "Use HammerJS gesture events in YUI 3.",
"author" : [ "tilomitra" ],
"use" : [ "gallery-event-hammer" ],

"tags": [ "gallery" ],

"examples": []
}
16 changes: 16 additions & 0 deletions src/gallery-event-hammer/docs/index.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<div class="intro">
<p>
Check the README.md for now!
</p>
</div>

{{>getting-started}}

<h2>Docs coming soon</h2>

<p>Check the README.md!</p>

```
//Module example code
```

66 changes: 66 additions & 0 deletions src/gallery-event-hammer/js/gallery-event-hammer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
Copyright 2013 Yahoo! Inc.
Licensed under the BSD License.
http://yuilibrary.com/license/
*/

'use strict';
var HAMMER_GESTURES = [
'hold',
'tap',
'doubletap',
'drag',
'dragstart',
'dragend',
'dragup',
'dragdown',
'dragleft',
'dragright',
'swipe',
'swipeup',
'swipedown',
'swipeleft',
'swiperight',
'transform',
'transformstart',
'transformend',
'rotate',
'pinch',
'pinchin',
'pinchout',
'touch',
'release'
];

Y.Array.each(HAMMER_GESTURES, function (gesture) {
Y.Event.define(gesture, {
_hammer: undefined,
processArgs: function (args, isDelegate) {
// The args list will look like this coming in:
// [ type, callback, node, (extras...), [filter,] thisObj, arg0...argN ]
return args.splice(3,1)[0];
},
on: function (node, subscription, notifier) {
var params = subscription._extra,
self = this;

// Delegate the gesture event to HammerJS.
this._hammer = Hammer(node.getDOMNode(), params).on(gesture, function (ev) {
self.handleHammerEvent(ev, node, subscription, notifier);
});
},

handleHammerEvent: function (ev, node, subscription, notifier) {
//event facade normalization
notifier.fire(ev);
},

_off: function () {
this._hammer.off(this.type, this.handleHammerEvent);
},

detach: function () {
this._off();
}
});
});
Loading

0 comments on commit 781593c

Please sign in to comment.