fastclick-rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c1a419e6b2534033b89876908ca7e3ebf882db73
4
+ data.tar.gz: c1f8a7b65bb3ea51c0cfa45626ef1d738333579b
5
+ SHA512:
6
+ metadata.gz: 3c11ecfb60dde7ef22dcb46fca785707eb239057b0db6abba27d97092ca93f2aa7568c3ee4066fa5a6bc874b8312cd94b7aa8f7412f84f1ed72cf3a984d4fc17
7
+ data.tar.gz: 23845cf065bb9b27505ee08a36ffb214e5418ac6246518905fbfd8da528320620698cec9c5e1716fe31ff76d9d19267e1fa9cbafbcd9d36b45a9c45d0e3e9704
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fastclick-rails.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Masaki Komagata
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,31 @@
1
+ # fastclick-rails
2
+
3
+ gem for [fastclick.js](https://github.com/ftlabs/fastclick)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'fastclick-rails'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install fastclick-rails
18
+
19
+ ## Usage
20
+
21
+ Add the follow line in app/assets/javascripts/application.js
22
+
23
+ //= require fastclick
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fastclick-rails'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fastclick-rails"
8
+ spec.version = Fastclick::Rails::VERSION
9
+ spec.authors = ["Masaki Komagata"]
10
+ spec.email = ["komagata@gmail.com"]
11
+ spec.description = %q{gem for fastclick.js}
12
+ spec.summary = %q{gem for fastclick.js}
13
+ spec.homepage = "https://github.com/komagata/fastclick-rails"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rails"
24
+ end
@@ -0,0 +1,9 @@
1
+ require 'rails/engine'
2
+
3
+ module Fastclick
4
+ module Rails
5
+ VERSION = "0.0.1"
6
+ class Engine < ::Rails::Engine
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,714 @@
1
+ /**
2
+ * @preserve FastClick: polyfill to remove click delays on browsers with touch UIs.
3
+ *
4
+ * @version 0.6.5
5
+ * @codingstandard ftlabs-jsv2
6
+ * @copyright The Financial Times Limited [All Rights Reserved]
7
+ * @license MIT License (see LICENSE.txt)
8
+ */
9
+
10
+ /*jslint browser:true, node:true*/
11
+ /*global define, Event, Node*/
12
+
13
+
14
+ /**
15
+ * Instantiate fast-clicking listeners on the specificed layer.
16
+ *
17
+ * @constructor
18
+ * @param {Element} layer The layer to listen on
19
+ */
20
+ function FastClick(layer) {
21
+ 'use strict';
22
+ var oldOnClick, self = this;
23
+
24
+
25
+ /**
26
+ * Whether a click is currently being tracked.
27
+ *
28
+ * @type boolean
29
+ */
30
+ this.trackingClick = false;
31
+
32
+
33
+ /**
34
+ * Timestamp for when when click tracking started.
35
+ *
36
+ * @type number
37
+ */
38
+ this.trackingClickStart = 0;
39
+
40
+
41
+ /**
42
+ * The element being tracked for a click.
43
+ *
44
+ * @type EventTarget
45
+ */
46
+ this.targetElement = null;
47
+
48
+
49
+ /**
50
+ * X-coordinate of touch start event.
51
+ *
52
+ * @type number
53
+ */
54
+ this.touchStartX = 0;
55
+
56
+
57
+ /**
58
+ * Y-coordinate of touch start event.
59
+ *
60
+ * @type number
61
+ */
62
+ this.touchStartY = 0;
63
+
64
+
65
+ /**
66
+ * ID of the last touch, retrieved from Touch.identifier.
67
+ *
68
+ * @type number
69
+ */
70
+ this.lastTouchIdentifier = 0;
71
+
72
+
73
+ /**
74
+ * The FastClick layer.
75
+ *
76
+ * @type Element
77
+ */
78
+ this.layer = layer;
79
+
80
+ if (!layer || !layer.nodeType) {
81
+ throw new TypeError('Layer must be a document node');
82
+ }
83
+
84
+ /** @type function() */
85
+ this.onClick = function() { return FastClick.prototype.onClick.apply(self, arguments); };
86
+
87
+ /** @type function() */
88
+ this.onMouse = function() { return FastClick.prototype.onMouse.apply(self, arguments); };
89
+
90
+ /** @type function() */
91
+ this.onTouchStart = function() { return FastClick.prototype.onTouchStart.apply(self, arguments); };
92
+
93
+ /** @type function() */
94
+ this.onTouchEnd = function() { return FastClick.prototype.onTouchEnd.apply(self, arguments); };
95
+
96
+ /** @type function() */
97
+ this.onTouchCancel = function() { return FastClick.prototype.onTouchCancel.apply(self, arguments); };
98
+
99
+ if (FastClick.notNeeded()) {
100
+ return;
101
+ }
102
+
103
+ // Set up event handlers as required
104
+ if (this.deviceIsAndroid) {
105
+ layer.addEventListener('mouseover', this.onMouse, true);
106
+ layer.addEventListener('mousedown', this.onMouse, true);
107
+ layer.addEventListener('mouseup', this.onMouse, true);
108
+ }
109
+
110
+ layer.addEventListener('click', this.onClick, true);
111
+ layer.addEventListener('touchstart', this.onTouchStart, false);
112
+ layer.addEventListener('touchend', this.onTouchEnd, false);
113
+ layer.addEventListener('touchcancel', this.onTouchCancel, false);
114
+
115
+ // Hack is required for browsers that don't support Event#stopImmediatePropagation (e.g. Android 2)
116
+ // which is how FastClick normally stops click events bubbling to callbacks registered on the FastClick
117
+ // layer when they are cancelled.
118
+ if (!Event.prototype.stopImmediatePropagation) {
119
+ layer.removeEventListener = function(type, callback, capture) {
120
+ var rmv = Node.prototype.removeEventListener;
121
+ if (type === 'click') {
122
+ rmv.call(layer, type, callback.hijacked || callback, capture);
123
+ } else {
124
+ rmv.call(layer, type, callback, capture);
125
+ }
126
+ };
127
+
128
+ layer.addEventListener = function(type, callback, capture) {
129
+ var adv = Node.prototype.addEventListener;
130
+ if (type === 'click') {
131
+ adv.call(layer, type, callback.hijacked || (callback.hijacked = function(event) {
132
+ if (!event.propagationStopped) {
133
+ callback(event);
134
+ }
135
+ }), capture);
136
+ } else {
137
+ adv.call(layer, type, callback, capture);
138
+ }
139
+ };
140
+ }
141
+
142
+ // If a handler is already declared in the element's onclick attribute, it will be fired before
143
+ // FastClick's onClick handler. Fix this by pulling out the user-defined handler function and
144
+ // adding it as listener.
145
+ if (typeof layer.onclick === 'function') {
146
+
147
+ // Android browser on at least 3.2 requires a new reference to the function in layer.onclick
148
+ // - the old one won't work if passed to addEventListener directly.
149
+ oldOnClick = layer.onclick;
150
+ layer.addEventListener('click', function(event) {
151
+ oldOnClick(event);
152
+ }, false);
153
+ layer.onclick = null;
154
+ }
155
+ }
156
+
157
+
158
+ /**
159
+ * Android requires exceptions.
160
+ *
161
+ * @type boolean
162
+ */
163
+ FastClick.prototype.deviceIsAndroid = navigator.userAgent.indexOf('Android') > 0;
164
+
165
+
166
+ /**
167
+ * iOS requires exceptions.
168
+ *
169
+ * @type boolean
170
+ */
171
+ FastClick.prototype.deviceIsIOS = /iP(ad|hone|od)/.test(navigator.userAgent);
172
+
173
+
174
+ /**
175
+ * iOS 4 requires an exception for select elements.
176
+ *
177
+ * @type boolean
178
+ */
179
+ FastClick.prototype.deviceIsIOS4 = FastClick.prototype.deviceIsIOS && (/OS 4_\d(_\d)?/).test(navigator.userAgent);
180
+
181
+
182
+ /**
183
+ * iOS 6.0(+?) requires the target element to be manually derived
184
+ *
185
+ * @type boolean
186
+ */
187
+ FastClick.prototype.deviceIsIOSWithBadTarget = FastClick.prototype.deviceIsIOS && (/OS ([6-9]|\d{2})_\d/).test(navigator.userAgent);
188
+
189
+
190
+ /**
191
+ * Determine whether a given element requires a native click.
192
+ *
193
+ * @param {EventTarget|Element} target Target DOM element
194
+ * @returns {boolean} Returns true if the element needs a native click
195
+ */
196
+ FastClick.prototype.needsClick = function(target) {
197
+ 'use strict';
198
+ switch (target.nodeName.toLowerCase()) {
199
+
200
+ // Don't send a synthetic click to disabled inputs (issue #62)
201
+ case 'button':
202
+ case 'select':
203
+ case 'textarea':
204
+ if (target.disabled) {
205
+ return true;
206
+ }
207
+
208
+ break;
209
+ case 'input':
210
+
211
+ // File inputs need real clicks on iOS 6 due to a browser bug (issue #68)
212
+ if ((this.deviceIsIOS && target.type === 'file') || target.disabled) {
213
+ return true;
214
+ }
215
+
216
+ break;
217
+ case 'label':
218
+ case 'video':
219
+ return true;
220
+ }
221
+
222
+ return (/\bneedsclick\b/).test(target.className);
223
+ };
224
+
225
+
226
+ /**
227
+ * Determine whether a given element requires a call to focus to simulate click into element.
228
+ *
229
+ * @param {EventTarget|Element} target Target DOM element
230
+ * @returns {boolean} Returns true if the element requires a call to focus to simulate native click.
231
+ */
232
+ FastClick.prototype.needsFocus = function(target) {
233
+ 'use strict';
234
+ switch (target.nodeName.toLowerCase()) {
235
+ case 'textarea':
236
+ case 'select':
237
+ return true;
238
+ case 'input':
239
+ switch (target.type) {
240
+ case 'button':
241
+ case 'checkbox':
242
+ case 'file':
243
+ case 'image':
244
+ case 'radio':
245
+ case 'submit':
246
+ return false;
247
+ }
248
+
249
+ // No point in attempting to focus disabled inputs
250
+ return !target.disabled && !target.readOnly;
251
+ default:
252
+ return (/\bneedsfocus\b/).test(target.className);
253
+ }
254
+ };
255
+
256
+
257
+ /**
258
+ * Send a click event to the specified element.
259
+ *
260
+ * @param {EventTarget|Element} targetElement
261
+ * @param {Event} event
262
+ */
263
+ FastClick.prototype.sendClick = function(targetElement, event) {
264
+ 'use strict';
265
+ var clickEvent, touch;
266
+
267
+ // On some Android devices activeElement needs to be blurred otherwise the synthetic click will have no effect (#24)
268
+ if (document.activeElement && document.activeElement !== targetElement) {
269
+ document.activeElement.blur();
270
+ }
271
+
272
+ touch = event.changedTouches[0];
273
+
274
+ // Synthesise a click event, with an extra attribute so it can be tracked
275
+ clickEvent = document.createEvent('MouseEvents');
276
+ clickEvent.initMouseEvent('click', true, true, window, 1, touch.screenX, touch.screenY, touch.clientX, touch.clientY, false, false, false, false, 0, null);
277
+ clickEvent.forwardedTouchEvent = true;
278
+ targetElement.dispatchEvent(clickEvent);
279
+ };
280
+
281
+
282
+ /**
283
+ * @param {EventTarget|Element} targetElement
284
+ */
285
+ FastClick.prototype.focus = function(targetElement) {
286
+ 'use strict';
287
+ var length;
288
+
289
+ if (this.deviceIsIOS && targetElement.setSelectionRange) {
290
+ length = targetElement.value.length;
291
+ targetElement.setSelectionRange(length, length);
292
+ } else {
293
+ targetElement.focus();
294
+ }
295
+ };
296
+
297
+
298
+ /**
299
+ * Check whether the given target element is a child of a scrollable layer and if so, set a flag on it.
300
+ *
301
+ * @param {EventTarget|Element} targetElement
302
+ */
303
+ FastClick.prototype.updateScrollParent = function(targetElement) {
304
+ 'use strict';
305
+ var scrollParent, parentElement;
306
+
307
+ scrollParent = targetElement.fastClickScrollParent;
308
+
309
+ // Attempt to discover whether the target element is contained within a scrollable layer. Re-check if the
310
+ // target element was moved to another parent.
311
+ if (!scrollParent || !scrollParent.contains(targetElement)) {
312
+ parentElement = targetElement;
313
+ do {
314
+ if (parentElement.scrollHeight > parentElement.offsetHeight) {
315
+ scrollParent = parentElement;
316
+ targetElement.fastClickScrollParent = parentElement;
317
+ break;
318
+ }
319
+
320
+ parentElement = parentElement.parentElement;
321
+ } while (parentElement);
322
+ }
323
+
324
+ // Always update the scroll top tracker if possible.
325
+ if (scrollParent) {
326
+ scrollParent.fastClickLastScrollTop = scrollParent.scrollTop;
327
+ }
328
+ };
329
+
330
+
331
+ /**
332
+ * @param {EventTarget} targetElement
333
+ * @returns {Element|EventTarget}
334
+ */
335
+ FastClick.prototype.getTargetElementFromEventTarget = function(eventTarget) {
336
+ 'use strict';
337
+
338
+ // On some older browsers (notably Safari on iOS 4.1 - see issue #56) the event target may be a text node.
339
+ if (eventTarget.nodeType === Node.TEXT_NODE) {
340
+ return eventTarget.parentNode;
341
+ }
342
+
343
+ return eventTarget;
344
+ };
345
+
346
+
347
+ /**
348
+ * On touch start, record the position and scroll offset.
349
+ *
350
+ * @param {Event} event
351
+ * @returns {boolean}
352
+ */
353
+ FastClick.prototype.onTouchStart = function(event) {
354
+ 'use strict';
355
+ var targetElement, touch, selection;
356
+
357
+ targetElement = this.getTargetElementFromEventTarget(event.target);
358
+ touch = event.targetTouches[0];
359
+
360
+ if (this.deviceIsIOS) {
361
+
362
+ // Only trusted events will deselect text on iOS (issue #49)
363
+ selection = window.getSelection();
364
+ if (selection.rangeCount && !selection.isCollapsed) {
365
+ return true;
366
+ }
367
+
368
+ if (!this.deviceIsIOS4) {
369
+
370
+ // Weird things happen on iOS when an alert or confirm dialog is opened from a click event callback (issue #23):
371
+ // when the user next taps anywhere else on the page, new touchstart and touchend events are dispatched
372
+ // with the same identifier as the touch event that previously triggered the click that triggered the alert.
373
+ // Sadly, there is an issue on iOS 4 that causes some normal touch events to have the same identifier as an
374
+ // immediately preceeding touch event (issue #52), so this fix is unavailable on that platform.
375
+ if (touch.identifier === this.lastTouchIdentifier) {
376
+ event.preventDefault();
377
+ return false;
378
+ }
379
+
380
+ this.lastTouchIdentifier = touch.identifier;
381
+
382
+ // If the target element is a child of a scrollable layer (using -webkit-overflow-scrolling: touch) and:
383
+ // 1) the user does a fling scroll on the scrollable layer
384
+ // 2) the user stops the fling scroll with another tap
385
+ // then the event.target of the last 'touchend' event will be the element that was under the user's finger
386
+ // when the fling scroll was started, causing FastClick to send a click event to that layer - unless a check
387
+ // is made to ensure that a parent layer was not scrolled before sending a synthetic click (issue #42).
388
+ this.updateScrollParent(targetElement);
389
+ }
390
+ }
391
+
392
+ this.trackingClick = true;
393
+ this.trackingClickStart = event.timeStamp;
394
+ this.targetElement = targetElement;
395
+
396
+ this.touchStartX = touch.pageX;
397
+ this.touchStartY = touch.pageY;
398
+
399
+ // Prevent phantom clicks on fast double-tap (issue #36)
400
+ if ((event.timeStamp - this.lastClickTime) < 200) {
401
+ event.preventDefault();
402
+ }
403
+
404
+ return true;
405
+ };
406
+
407
+
408
+ /**
409
+ * Based on a touchmove event object, check whether the touch has moved past a boundary since it started.
410
+ *
411
+ * @param {Event} event
412
+ * @returns {boolean}
413
+ */
414
+ FastClick.prototype.touchHasMoved = function(event) {
415
+ 'use strict';
416
+ var touch = event.changedTouches[0];
417
+
418
+ if (Math.abs(touch.pageX - this.touchStartX) > 10 || Math.abs(touch.pageY - this.touchStartY) > 10) {
419
+ return true;
420
+ }
421
+
422
+ return false;
423
+ };
424
+
425
+
426
+ /**
427
+ * Attempt to find the labelled control for the given label element.
428
+ *
429
+ * @param {EventTarget|HTMLLabelElement} labelElement
430
+ * @returns {Element|null}
431
+ */
432
+ FastClick.prototype.findControl = function(labelElement) {
433
+ 'use strict';
434
+
435
+ // Fast path for newer browsers supporting the HTML5 control attribute
436
+ if (labelElement.control !== undefined) {
437
+ return labelElement.control;
438
+ }
439
+
440
+ // All browsers under test that support touch events also support the HTML5 htmlFor attribute
441
+ if (labelElement.htmlFor) {
442
+ return document.getElementById(labelElement.htmlFor);
443
+ }
444
+
445
+ // If no for attribute exists, attempt to retrieve the first labellable descendant element
446
+ // the list of which is defined here: http://www.w3.org/TR/html5/forms.html#category-label
447
+ return labelElement.querySelector('button, input:not([type=hidden]), keygen, meter, output, progress, select, textarea');
448
+ };
449
+
450
+
451
+ /**
452
+ * On touch end, determine whether to send a click event at once.
453
+ *
454
+ * @param {Event} event
455
+ * @returns {boolean}
456
+ */
457
+ FastClick.prototype.onTouchEnd = function(event) {
458
+ 'use strict';
459
+ var forElement, trackingClickStart, targetTagName, scrollParent, touch, targetElement = this.targetElement;
460
+
461
+ // If the touch has moved, cancel the click tracking
462
+ if (this.touchHasMoved(event)) {
463
+ this.trackingClick = false;
464
+ this.targetElement = null;
465
+ }
466
+
467
+ if (!this.trackingClick) {
468
+ return true;
469
+ }
470
+
471
+ // Prevent phantom clicks on fast double-tap (issue #36)
472
+ if ((event.timeStamp - this.lastClickTime) < 200) {
473
+ this.cancelNextClick = true;
474
+ return true;
475
+ }
476
+
477
+ this.lastClickTime = event.timeStamp;
478
+
479
+ trackingClickStart = this.trackingClickStart;
480
+ this.trackingClick = false;
481
+ this.trackingClickStart = 0;
482
+
483
+ // On some iOS devices, the targetElement supplied with the event is invalid if the layer
484
+ // is performing a transition or scroll, and has to be re-detected manually. Note that
485
+ // for this to function correctly, it must be called *after* the event target is checked!
486
+ // See issue #57; also filed as rdar://13048589 .
487
+ if (this.deviceIsIOSWithBadTarget) {
488
+ touch = event.changedTouches[0];
489
+ targetElement = document.elementFromPoint(touch.pageX - window.pageXOffset, touch.pageY - window.pageYOffset);
490
+ }
491
+
492
+ targetTagName = targetElement.tagName.toLowerCase();
493
+ if (targetTagName === 'label') {
494
+ forElement = this.findControl(targetElement);
495
+ if (forElement) {
496
+ this.focus(targetElement);
497
+ if (this.deviceIsAndroid) {
498
+ return false;
499
+ }
500
+
501
+ targetElement = forElement;
502
+ }
503
+ } else if (this.needsFocus(targetElement)) {
504
+
505
+ // Case 1: If the touch started a while ago (best guess is 100ms based on tests for issue #36) then focus will be triggered anyway. Return early and unset the target element reference so that the subsequent click will be allowed through.
506
+ // Case 2: Without this exception for input elements tapped when the document is contained in an iframe, then any inputted text won't be visible even though the value attribute is updated as the user types (issue #37).
507
+ if ((event.timeStamp - trackingClickStart) > 100 || (this.deviceIsIOS && window.top !== window && targetTagName === 'input')) {
508
+ this.targetElement = null;
509
+ return false;
510
+ }
511
+
512
+ this.focus(targetElement);
513
+
514
+ // Select elements need the event to go through on iOS 4, otherwise the selector menu won't open.
515
+ if (!this.deviceIsIOS4 || targetTagName !== 'select') {
516
+ this.targetElement = null;
517
+ event.preventDefault();
518
+ }
519
+
520
+ return false;
521
+ }
522
+
523
+ if (this.deviceIsIOS && !this.deviceIsIOS4) {
524
+
525
+ // Don't send a synthetic click event if the target element is contained within a parent layer that was scrolled
526
+ // and this tap is being used to stop the scrolling (usually initiated by a fling - issue #42).
527
+ scrollParent = targetElement.fastClickScrollParent;
528
+ if (scrollParent && scrollParent.fastClickLastScrollTop !== scrollParent.scrollTop) {
529
+ return true;
530
+ }
531
+ }
532
+
533
+ // Prevent the actual click from going though - unless the target node is marked as requiring
534
+ // real clicks or if it is in the whitelist in which case only non-programmatic clicks are permitted.
535
+ if (!this.needsClick(targetElement)) {
536
+ event.preventDefault();
537
+ this.sendClick(targetElement, event);
538
+ }
539
+
540
+ return false;
541
+ };
542
+
543
+
544
+ /**
545
+ * On touch cancel, stop tracking the click.
546
+ *
547
+ * @returns {void}
548
+ */
549
+ FastClick.prototype.onTouchCancel = function() {
550
+ 'use strict';
551
+ this.trackingClick = false;
552
+ this.targetElement = null;
553
+ };
554
+
555
+
556
+ /**
557
+ * Determine mouse events which should be permitted.
558
+ *
559
+ * @param {Event} event
560
+ * @returns {boolean}
561
+ */
562
+ FastClick.prototype.onMouse = function(event) {
563
+ 'use strict';
564
+
565
+ // If a target element was never set (because a touch event was never fired) allow the event
566
+ if (!this.targetElement) {
567
+ return true;
568
+ }
569
+
570
+ if (event.forwardedTouchEvent) {
571
+ return true;
572
+ }
573
+
574
+ // Programmatically generated events targeting a specific element should be permitted
575
+ if (!event.cancelable) {
576
+ return true;
577
+ }
578
+
579
+ // Derive and check the target element to see whether the mouse event needs to be permitted;
580
+ // unless explicitly enabled, prevent non-touch click events from triggering actions,
581
+ // to prevent ghost/doubleclicks.
582
+ if (!this.needsClick(this.targetElement) || this.cancelNextClick) {
583
+
584
+ // Prevent any user-added listeners declared on FastClick element from being fired.
585
+ if (event.stopImmediatePropagation) {
586
+ event.stopImmediatePropagation();
587
+ } else {
588
+
589
+ // Part of the hack for browsers that don't support Event#stopImmediatePropagation (e.g. Android 2)
590
+ event.propagationStopped = true;
591
+ }
592
+
593
+ // Cancel the event
594
+ event.stopPropagation();
595
+ event.preventDefault();
596
+
597
+ return false;
598
+ }
599
+
600
+ // If the mouse event is permitted, return true for the action to go through.
601
+ return true;
602
+ };
603
+
604
+
605
+ /**
606
+ * On actual clicks, determine whether this is a touch-generated click, a click action occurring
607
+ * naturally after a delay after a touch (which needs to be cancelled to avoid duplication), or
608
+ * an actual click which should be permitted.
609
+ *
610
+ * @param {Event} event
611
+ * @returns {boolean}
612
+ */
613
+ FastClick.prototype.onClick = function(event) {
614
+ 'use strict';
615
+ var permitted;
616
+
617
+ // It's possible for another FastClick-like library delivered with third-party code to fire a click event before FastClick does (issue #44). In that case, set the click-tracking flag back to false and return early. This will cause onTouchEnd to return early.
618
+ if (this.trackingClick) {
619
+ this.targetElement = null;
620
+ this.trackingClick = false;
621
+ return true;
622
+ }
623
+
624
+ // Very odd behaviour on iOS (issue #18): if a submit element is present inside a form and the user hits enter in the iOS simulator or clicks the Go button on the pop-up OS keyboard the a kind of 'fake' click event will be triggered with the submit-type input element as the target.
625
+ if (event.target.type === 'submit' && event.detail === 0) {
626
+ return true;
627
+ }
628
+
629
+ permitted = this.onMouse(event);
630
+
631
+ // Only unset targetElement if the click is not permitted. This will ensure that the check for !targetElement in onMouse fails and the browser's click doesn't go through.
632
+ if (!permitted) {
633
+ this.targetElement = null;
634
+ }
635
+
636
+ // If clicks are permitted, return true for the action to go through.
637
+ return permitted;
638
+ };
639
+
640
+
641
+ /**
642
+ * Remove all FastClick's event listeners.
643
+ *
644
+ * @returns {void}
645
+ */
646
+ FastClick.prototype.destroy = function() {
647
+ 'use strict';
648
+ var layer = this.layer;
649
+
650
+ if (this.deviceIsAndroid) {
651
+ layer.removeEventListener('mouseover', this.onMouse, true);
652
+ layer.removeEventListener('mousedown', this.onMouse, true);
653
+ layer.removeEventListener('mouseup', this.onMouse, true);
654
+ }
655
+
656
+ layer.removeEventListener('click', this.onClick, true);
657
+ layer.removeEventListener('touchstart', this.onTouchStart, false);
658
+ layer.removeEventListener('touchend', this.onTouchEnd, false);
659
+ layer.removeEventListener('touchcancel', this.onTouchCancel, false);
660
+ };
661
+
662
+
663
+ FastClick.notNeeded = function() {
664
+ 'use strict';
665
+ var metaViewport;
666
+
667
+ // Devices that don't support touch don't need FastClick
668
+ if (typeof window.ontouchstart === 'undefined') {
669
+ return true;
670
+ }
671
+
672
+ if ((/Chrome\/[0-9]+/).test(navigator.userAgent)) {
673
+
674
+ // Chrome on Android with user-scalable="no" doesn't need FastClick (issue #89)
675
+ if (FastClick.prototype.deviceIsAndroid) {
676
+ metaViewport = document.querySelector('meta[name=viewport]');
677
+ if (metaViewport && metaViewport.content.indexOf('user-scalable=no') !== -1) {
678
+ return true;
679
+ }
680
+
681
+ // Chrome desktop doesn't need FastClick (issue #15)
682
+ } else {
683
+ return true;
684
+ }
685
+ }
686
+
687
+ return false;
688
+ };
689
+
690
+
691
+ /**
692
+ * Factory method for creating a FastClick object
693
+ *
694
+ * @param {Element} layer The layer to listen on
695
+ */
696
+ FastClick.attach = function(layer) {
697
+ 'use strict';
698
+ return new FastClick(layer);
699
+ };
700
+
701
+
702
+ if (typeof define !== 'undefined' && define.amd) {
703
+
704
+ // AMD. Register as an anonymous module.
705
+ define(function() {
706
+ 'use strict';
707
+ return FastClick;
708
+ });
709
+ } else if (typeof module !== 'undefined' && module.exports) {
710
+ module.exports = FastClick.attach;
711
+ module.exports.FastClick = FastClick;
712
+ } else {
713
+ window.FastClick = FastClick;
714
+ }
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fastclick-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Masaki Komagata
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-05-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: gem for fastclick.js
56
+ email:
57
+ - komagata@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - fastclick-rails.gemspec
68
+ - lib/fastclick-rails.rb
69
+ - vendor/assets/javascripts/fastclick.js
70
+ homepage: https://github.com/komagata/fastclick-rails
71
+ licenses:
72
+ - MIT
73
+ metadata: {}
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 2.0.0
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: gem for fastclick.js
94
+ test_files: []
95
+ has_rdoc: