hammerjs-rails 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 10755e389c9d153cf0f51a60cbcc45eb1f0449db
|
4
|
+
data.tar.gz: 4d4a37e7fa403777eab43211216d2defbfc33aa6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f75eb586431eba4676e7cfc776df0e092bcc8933cc04be757098c12e7aa39ef0107b3435601a1e247a7f53ee1df889a73372302ac597d76828e1a3adbecd38f
|
7
|
+
data.tar.gz: f373317e6aab9ca844a4c2f6562efe76425e5881483831654c1a145ea53d96fdbeb2ecb8534d1c2a4a452d1f9a5e0c673ef59eae0d0a0c0508f887433d976f73
|
data/.gitignore
CHANGED
@@ -1 +1,2 @@
|
|
1
|
-
Gemfile.lock
|
1
|
+
Gemfile.lock
|
2
|
+
*.gem
|
data/README.md
CHANGED
@@ -11,10 +11,10 @@ Add this line to your application's Gemfile:
|
|
11
11
|
gem 'hammerjs-rails'
|
12
12
|
```
|
13
13
|
|
14
|
-
Add
|
14
|
+
Add update your Javascript manifest file (application.js):
|
15
15
|
|
16
16
|
```js
|
17
|
-
//= require
|
17
|
+
//= require hammer
|
18
18
|
```
|
19
19
|
|
20
20
|
## Contributing
|
@@ -0,0 +1,81 @@
|
|
1
|
+
(function(Hammer) {
|
2
|
+
/**
|
3
|
+
* enable multitouch on the desktop by pressing the shiftkey
|
4
|
+
* the other touch goes in the opposite direction so the center keeps at its place
|
5
|
+
* it's recommended to enable Hammer.debug.showTouches for this one
|
6
|
+
*/
|
7
|
+
Hammer.plugins.fakeMultitouch = function() {
|
8
|
+
// keeps the start position to keep it centered
|
9
|
+
var start_pos = false;
|
10
|
+
|
11
|
+
// test for msMaxTouchPoints to enable this for IE10 with only one pointer (a mouse in all/most cases)
|
12
|
+
Hammer.HAS_POINTEREVENTS = navigator.msPointerEnabled &&
|
13
|
+
navigator.msMaxTouchPoints && navigator.msMaxTouchPoints >= 1;
|
14
|
+
|
15
|
+
/**
|
16
|
+
* overwrites Hammer.event.getTouchList.
|
17
|
+
* @param {Event} ev
|
18
|
+
* @param TOUCHTYPE type
|
19
|
+
* @return {Array} Touches
|
20
|
+
*/
|
21
|
+
Hammer.event.getTouchList = function(ev, eventType) {
|
22
|
+
// get the fake pointerEvent touchlist
|
23
|
+
if(Hammer.HAS_POINTEREVENTS) {
|
24
|
+
return Hammer.PointerEvent.getTouchList();
|
25
|
+
}
|
26
|
+
// get the touchlist
|
27
|
+
else if(ev.touches) {
|
28
|
+
return ev.touches;
|
29
|
+
}
|
30
|
+
|
31
|
+
// reset on start of a new touch
|
32
|
+
if(eventType == Hammer.EVENT_START) {
|
33
|
+
start_pos = false;
|
34
|
+
}
|
35
|
+
|
36
|
+
// when the shift key is pressed, multitouch is possible on desktop
|
37
|
+
// why shift? because ctrl and alt are taken by osx and linux
|
38
|
+
if(ev.shiftKey) {
|
39
|
+
// on touchstart we store the position of the mouse for multitouch
|
40
|
+
if(!start_pos) {
|
41
|
+
start_pos = {
|
42
|
+
pageX: ev.pageX,
|
43
|
+
pageY: ev.pageY
|
44
|
+
};
|
45
|
+
}
|
46
|
+
|
47
|
+
var distance_x = start_pos.pageX - ev.pageX;
|
48
|
+
var distance_y = start_pos.pageY - ev.pageY;
|
49
|
+
|
50
|
+
// fake second touch in the opposite direction
|
51
|
+
return [
|
52
|
+
{
|
53
|
+
identifier: 1,
|
54
|
+
pageX : start_pos.pageX - distance_x - 50,
|
55
|
+
pageY : start_pos.pageY - distance_y - -50,
|
56
|
+
target : ev.target
|
57
|
+
},
|
58
|
+
{
|
59
|
+
identifier: 2,
|
60
|
+
pageX : start_pos.pageX + distance_x - -50,
|
61
|
+
pageY : start_pos.pageY + distance_y - 50,
|
62
|
+
target : ev.target
|
63
|
+
}
|
64
|
+
];
|
65
|
+
}
|
66
|
+
// normal single touch
|
67
|
+
else {
|
68
|
+
start_pos = false;
|
69
|
+
return [
|
70
|
+
{
|
71
|
+
identifier: 1,
|
72
|
+
pageX : ev.pageX,
|
73
|
+
pageY : ev.pageY,
|
74
|
+
target : ev.target
|
75
|
+
}
|
76
|
+
];
|
77
|
+
}
|
78
|
+
};
|
79
|
+
};
|
80
|
+
|
81
|
+
})(window.Hammer);
|
@@ -0,0 +1,70 @@
|
|
1
|
+
(function(Hammer) {
|
2
|
+
/**
|
3
|
+
* ShowTouches gesture
|
4
|
+
* show all touch on the screen by placing elements at there pageX and pageY
|
5
|
+
* @param {Boolean} [force]
|
6
|
+
*/
|
7
|
+
Hammer.plugins.showTouches = function(force) {
|
8
|
+
// the circles under your fingers
|
9
|
+
var template_style = 'position:absolute;z-index:9999;left:0;top:0;height:14px;width:14px;border:solid 2px #777;' +
|
10
|
+
'background:rgba(255,255,255,.7);border-radius:20px;pointer-events:none;' +
|
11
|
+
'margin-top:-9px;margin-left:-9px;';
|
12
|
+
|
13
|
+
// elements by identifier
|
14
|
+
var touch_elements = {};
|
15
|
+
var touches_index = {};
|
16
|
+
|
17
|
+
/**
|
18
|
+
* remove unused touch elements
|
19
|
+
*/
|
20
|
+
function removeUnusedElements() {
|
21
|
+
// remove unused touch elements
|
22
|
+
for(var key in touch_elements) {
|
23
|
+
if(touch_elements.hasOwnProperty(key) && !touches_index[key]) {
|
24
|
+
document.body.removeChild(touch_elements[key]);
|
25
|
+
delete touch_elements[key];
|
26
|
+
}
|
27
|
+
}
|
28
|
+
}
|
29
|
+
|
30
|
+
Hammer.detection.register({
|
31
|
+
name : 'show_touches',
|
32
|
+
priority: 0,
|
33
|
+
handler : function(ev, inst) {
|
34
|
+
touches_index = {};
|
35
|
+
|
36
|
+
// clear old elements when not using a mouse
|
37
|
+
if(ev.pointerType != Hammer.POINTER_MOUSE && !force) {
|
38
|
+
removeUnusedElements();
|
39
|
+
return;
|
40
|
+
}
|
41
|
+
|
42
|
+
// place touches by index
|
43
|
+
for(var t = 0, total_touches = ev.touches.length; t < total_touches; t++) {
|
44
|
+
var touch = ev.touches[t];
|
45
|
+
|
46
|
+
var id = touch.identifier;
|
47
|
+
touches_index[id] = touch;
|
48
|
+
|
49
|
+
// new touch element
|
50
|
+
if(!touch_elements[id]) {
|
51
|
+
// create new element and attach base styles
|
52
|
+
var template = document.createElement('div');
|
53
|
+
template.setAttribute('style', template_style);
|
54
|
+
|
55
|
+
// append element to body
|
56
|
+
document.body.appendChild(template);
|
57
|
+
|
58
|
+
touch_elements[id] = template;
|
59
|
+
}
|
60
|
+
|
61
|
+
// Paul Irish says that translate is faster then left/top
|
62
|
+
touch_elements[id].style.left = touch.pageX + 'px';
|
63
|
+
touch_elements[id].style.top = touch.pageY + 'px';
|
64
|
+
}
|
65
|
+
|
66
|
+
removeUnusedElements();
|
67
|
+
}
|
68
|
+
});
|
69
|
+
};
|
70
|
+
})(window.Hammer);
|
@@ -0,0 +1,115 @@
|
|
1
|
+
/*! jQuery plugin for Hammer.JS - v1.0.0 - 2013-11-03
|
2
|
+
* http://eightmedia.github.com/hammer.js
|
3
|
+
*
|
4
|
+
* Copyright (c) 2013 Jorik Tangelder <j.tangelder@gmail.com>;
|
5
|
+
* Licensed under the MIT license */
|
6
|
+
|
7
|
+
(function(window, undefined) {
|
8
|
+
'use strict';
|
9
|
+
|
10
|
+
function setup(Hammer, $) {
|
11
|
+
/**
|
12
|
+
* bind dom events
|
13
|
+
* this overwrites addEventListener
|
14
|
+
* @param {HTMLElement} element
|
15
|
+
* @param {String} eventTypes
|
16
|
+
* @param {Function} handler
|
17
|
+
*/
|
18
|
+
Hammer.event.bindDom = function(element, eventTypes, handler) {
|
19
|
+
$(element).on(eventTypes, function(ev) {
|
20
|
+
var data = ev.originalEvent || ev;
|
21
|
+
|
22
|
+
if(data.pageX === undefined) {
|
23
|
+
data.pageX = ev.pageX;
|
24
|
+
data.pageY = ev.pageY;
|
25
|
+
}
|
26
|
+
|
27
|
+
if(!data.target) {
|
28
|
+
data.target = ev.target;
|
29
|
+
}
|
30
|
+
|
31
|
+
if(data.which === undefined) {
|
32
|
+
data.which = data.button;
|
33
|
+
}
|
34
|
+
|
35
|
+
if(!data.preventDefault) {
|
36
|
+
data.preventDefault = ev.preventDefault;
|
37
|
+
}
|
38
|
+
|
39
|
+
if(!data.stopPropagation) {
|
40
|
+
data.stopPropagation = ev.stopPropagation;
|
41
|
+
}
|
42
|
+
|
43
|
+
handler.call(this, data);
|
44
|
+
});
|
45
|
+
};
|
46
|
+
|
47
|
+
/**
|
48
|
+
* the methods are called by the instance, but with the jquery plugin
|
49
|
+
* we use the jquery event methods instead.
|
50
|
+
* @this {Hammer.Instance}
|
51
|
+
* @return {jQuery}
|
52
|
+
*/
|
53
|
+
Hammer.Instance.prototype.on = function(types, handler) {
|
54
|
+
return $(this.element).on(types, handler);
|
55
|
+
};
|
56
|
+
Hammer.Instance.prototype.off = function(types, handler) {
|
57
|
+
return $(this.element).off(types, handler);
|
58
|
+
};
|
59
|
+
|
60
|
+
|
61
|
+
/**
|
62
|
+
* trigger events
|
63
|
+
* this is called by the gestures to trigger an event like 'tap'
|
64
|
+
* @this {Hammer.Instance}
|
65
|
+
* @param {String} gesture
|
66
|
+
* @param {Object} eventData
|
67
|
+
* @return {jQuery}
|
68
|
+
*/
|
69
|
+
Hammer.Instance.prototype.trigger = function(gesture, eventData) {
|
70
|
+
var el = $(this.element);
|
71
|
+
if(el.has(eventData.target).length) {
|
72
|
+
el = $(eventData.target);
|
73
|
+
}
|
74
|
+
|
75
|
+
return el.trigger({
|
76
|
+
type : gesture,
|
77
|
+
gesture: eventData
|
78
|
+
});
|
79
|
+
};
|
80
|
+
|
81
|
+
|
82
|
+
/**
|
83
|
+
* jQuery plugin
|
84
|
+
* create instance of Hammer and watch for gestures,
|
85
|
+
* and when called again you can change the options
|
86
|
+
* @param {Object} [options={}]
|
87
|
+
* @return {jQuery}
|
88
|
+
*/
|
89
|
+
$.fn.hammer = function(options) {
|
90
|
+
return this.each(function() {
|
91
|
+
var el = $(this);
|
92
|
+
var inst = el.data('hammer');
|
93
|
+
// start new hammer instance
|
94
|
+
if(!inst) {
|
95
|
+
el.data('hammer', new Hammer(this, options || {}));
|
96
|
+
}
|
97
|
+
// change the options
|
98
|
+
else if(inst && options) {
|
99
|
+
Hammer.utils.extend(inst.options, options);
|
100
|
+
}
|
101
|
+
});
|
102
|
+
};
|
103
|
+
}
|
104
|
+
|
105
|
+
// Based off Lo-Dash's excellent UMD wrapper (slightly modified) - https://github.com/bestiejs/lodash/blob/master/lodash.js#L5515-L5543
|
106
|
+
// some AMD build optimizers, like r.js, check for specific condition patterns like the following:
|
107
|
+
if(typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
|
108
|
+
// define as an anonymous module
|
109
|
+
define(['hammer', 'jquery'], setup);
|
110
|
+
|
111
|
+
}
|
112
|
+
else {
|
113
|
+
setup(window.Hammer, window.jQuery || window.Zepto);
|
114
|
+
}
|
115
|
+
})(this);
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hammerjs-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vincent Pochet
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,7 +52,10 @@ files:
|
|
52
52
|
- hammerjs-rails.gemspec
|
53
53
|
- lib/hammerjs-rails.rb
|
54
54
|
- lib/hammerjs/rails/version.rb
|
55
|
+
- vendor/assets/javascripts/hammer.fakemultitouch.js
|
55
56
|
- vendor/assets/javascripts/hammer.js
|
57
|
+
- vendor/assets/javascripts/hammer.showtouches.js
|
58
|
+
- vendor/assets/javascripts/jquery.hammer.js
|
56
59
|
homepage: https://github.com/vincent-pochet/hammerjs-rails
|
57
60
|
licenses:
|
58
61
|
- MIT
|
@@ -73,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
76
|
version: '0'
|
74
77
|
requirements: []
|
75
78
|
rubyforge_project:
|
76
|
-
rubygems_version: 2.
|
79
|
+
rubygems_version: 2.1.11
|
77
80
|
signing_key:
|
78
81
|
specification_version: 4
|
79
82
|
summary: hammerjs packaged for Rails assets pipeline
|