rasputin 0.12.1 → 0.13.1

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.
@@ -1,1303 +0,0 @@
1
- (function(exports) {
2
- // ==========================================================================
3
- // Project: Ember Runtime
4
- // Copyright: ©2011 Strobe Inc. and contributors.
5
- // License: Licensed under MIT license (see license.js)
6
- // ==========================================================================
7
-
8
- var get = Ember.get;
9
- var set = Ember.set;
10
-
11
- /**
12
- @class
13
-
14
- Registry of known gestures in the system. This is a singleton class, and is
15
- used by Ember.View to analyze instances of Ember.View for gesture support.
16
-
17
- You will not use this class yourself. Rather, gesture recognizers will call
18
- Ember.Gestures.register(name, recognizer) when they want to make the system aware
19
- of them.
20
-
21
- @private
22
- @extends Ember.Object
23
- */
24
- Ember.Gestures = Ember.Object.create(
25
- /** @scope Ember.Gestures.prototype */{
26
-
27
- _registeredGestures: null,
28
-
29
- init: function() {
30
- this._registeredGestures = {};
31
-
32
- return this._super();
33
- },
34
-
35
- /**
36
- Registers a gesture recognizer to the system. The gesture recognizer is
37
- identified by the name parameter, which must be globally unique.
38
- */
39
- register: function(name, recognizer) {
40
- var registeredGestures = this._registeredGestures;
41
-
42
- if (registeredGestures[name] !== undefined) {
43
- throw new Ember.Error(name+" already exists as a registered gesture recognizers. Gesture recognizers must have globally unique names.");
44
- }
45
-
46
- registeredGestures[name] = recognizer;
47
- },
48
-
49
- unregister: function(name) {
50
- var registeredGestures = this._registeredGestures;
51
-
52
- if (registeredGestures[name] !== undefined) {
53
- registeredGestures[name] = undefined;
54
- }
55
- },
56
-
57
- /**
58
- Registers a gesture recognizer to the system. The gesture recognizer is
59
- identified by the name parameter, which must be unique across the system.
60
- */
61
- knownGestures: function() {
62
- var registeredGestures = this._registeredGestures;
63
-
64
- return (registeredGestures)? registeredGestures : {};
65
- }
66
-
67
- });
68
-
69
-
70
- })({});
71
-
72
-
73
- (function(exports) {
74
- // ==========================================================================
75
- // Project: SproutCore Runtime
76
- // Copyright: ©2011 Strobe Inc. and contributors.
77
- // License: Licensed under MIT license (see license.js)
78
- // ==========================================================================
79
-
80
- var get = Ember.get;
81
- var set = Ember.set;
82
-
83
- /**
84
- @class
85
-
86
- Manages multiplegesture recognizers that are associated with a view.
87
- This class is instantiated automatically by Ember.View and you wouldn't
88
- interact with it yourself.
89
-
90
- Ember.GestureManager mainly acts as a composite for the multiple gesture
91
- recognizers associated with a view. Whenever it gets a touch event, it
92
- relays it to the gestures. The other main resposibility of
93
- Ember.GestureManager is to handle re-dispatching of events to the view.
94
-
95
- @extends Ember.Object
96
- */
97
- Ember.GestureManager = Ember.Object.extend({
98
-
99
- /**
100
- An array containing all the gesture recognizers associated with a
101
- view. This is set automatically by Ember.View.
102
-
103
- @default null
104
- @type Array
105
- */
106
- gestures: null,
107
-
108
- /**
109
- Internal hash used to keep a list of the events that need to be
110
- re-dispatched to the views. It's used so we don't re-dispatch
111
- the same event multiple times to the same view.
112
-
113
- @default null
114
- @type Array
115
- */
116
- _redispatchQueue: null,
117
-
118
- _redispatchToNearestParentViewWaitingForTouches: function(evt, view) {
119
- var foundManager = null,
120
- successful = false;
121
- view = get(view, 'parentView');
122
-
123
- while(view) {
124
- var manager = get(view, 'eventManager');
125
-
126
- if (manager !== undefined && manager !== null) {
127
- var gestures = get(manager, 'gestures');
128
-
129
- for (var i=0, l=gestures.length; i<l; i++) {
130
- if (get(gestures[i], 'state') === Ember.Gesture.WAITING_FOR_TOUCHES) {
131
- foundManager = manager;
132
- }
133
- }
134
-
135
- if (foundManager) {
136
- successful = true;
137
- foundManager.touchStart(evt, view);
138
- break;
139
- }
140
- }
141
-
142
- view = get(view, 'parentView');
143
- }
144
-
145
- return successful;
146
- },
147
-
148
- /**
149
- Relays touchStart events to all the gesture recognizers to the
150
- specified view
151
-
152
- @return Boolen
153
- */
154
- touchStart: function(evt, view) {
155
- if (this._redispatchToNearestParentViewWaitingForTouches(evt, view)) {
156
- return;
157
- }
158
-
159
- return this._invokeEvent('touchStart',evt, view);
160
- },
161
-
162
- /**
163
- Relays touchMove events to all the gesture recognizers to the
164
- specified view
165
-
166
- @return Boolen
167
- */
168
- touchMove: function(evt, view) {
169
- return this._invokeEvent('touchMove',evt, view);
170
- },
171
-
172
- /**
173
- Relays touchEnd events to all the gesture recognizers to the
174
- specified view
175
-
176
- @return Boolen
177
- */
178
- touchEnd: function(evt, view) {
179
- return this._invokeEvent('touchEnd',evt, view);
180
- },
181
-
182
- /**
183
- Relays touchCancel events to all the gesture recognizers to the
184
- specified view
185
-
186
- @return Boolen
187
- */
188
- touchCancel: function(evt, view) {
189
- return this._invokeEvent('touchCancel',evt, view);
190
- },
191
-
192
- /**
193
- Relays an event to the gesture recognizers. Used internally
194
- by the touch event listeners.
195
-
196
- @private
197
- @return Boolean
198
- */
199
- _invokeEvent: function(eventName, eventObject, view) {
200
- var gestures = get(this, 'gestures'),
201
- gesture, result = true;
202
-
203
- this._redispatchQueue = {};
204
-
205
- for (var i=0, l=gestures.length; i < l; i++) {
206
- gesture = gestures[i];
207
- handler = gesture[eventName];
208
-
209
- if (Ember.typeOf(handler) === 'function') {
210
- result = handler.call(gesture, eventObject, view, this);
211
- }
212
- }
213
-
214
- this._flushReDispatchQueue();
215
-
216
- return result;
217
- },
218
-
219
- /**
220
- Similar to _invokeEvent, but instead of invoking the event
221
- to the gesture recognizers, it re-dispatches the event to the
222
- view. This method is used by the gesture recognizers when they
223
- want to let the view respond to the original events.
224
- */
225
- redispatchEventToView: function(view, eventName, eventObject) {
226
- var queue = this._redispatchQueue;
227
-
228
- if (queue[eventName] === undefined) {
229
- queue[eventName] = [];
230
- }
231
- else {
232
- var views = queue[eventName];
233
-
234
- for (var i=0, l=views.length; i<l; i++) {
235
- if (view === views[i].view) {
236
- return;
237
- }
238
- }
239
- }
240
-
241
- var originalEvent = null;
242
- if (eventObject && eventObject.originalEvent) originalEvent = eventObject.originalEvent;
243
-
244
- queue[eventName].push({
245
- view: view,
246
- originalEvent: originalEvent
247
- });
248
- },
249
-
250
- /**
251
- This method is used internally by _invokeEvent. It re-dispatches
252
- events to the view if the gestures decided they want to.
253
- */
254
- _flushReDispatchQueue: function() {
255
- var queue = this._redispatchQueue;
256
-
257
- for (var eventName in queue) {
258
- var views = queue[eventName];
259
-
260
- for (var i=0, l=views.length; i<l; i++) {
261
- var view = views[i].view;
262
- var event = jQuery.Event(eventName);
263
-
264
- event.originalEvent = views[i].originalEvent;
265
-
266
- // Trigger event so it bubbles up the hierarchy
267
- view.$().trigger(event, this);
268
- }
269
- }
270
- }
271
-
272
- });
273
-
274
- })({});
275
-
276
-
277
- (function(exports) {
278
- // ==========================================================================
279
- // Project: SproutCore Touch
280
- // Copyright: ©2011 Strobe Inc. and contributors.
281
- // License: Licensed under MIT license (see license.js)
282
- // ==========================================================================
283
-
284
- var get = Ember.get;
285
- var set = Ember.set;
286
-
287
- /**
288
- @class
289
- @private
290
-
291
- Used to manage and maintain a list of active touches related to a gesture
292
- recognizer.
293
- */
294
- Ember.TouchList = Ember.Object.extend({
295
- touches: null,
296
-
297
- timestamp: null,
298
-
299
- init: function() {
300
- this._super();
301
-
302
- set(this, 'touches', []);
303
- },
304
-
305
- addTouch: function(touch) {
306
- var touches = get(this, 'touches');
307
- touches.push(touch);
308
- this.notifyPropertyChange('touches');
309
- },
310
-
311
- updateTouch: function(touch) {
312
- var touches = get(this, 'touches');
313
-
314
- for (var i=0, l=touches.length; i<l; i++) {
315
- var _t = touches[i];
316
-
317
- if (_t.identifier === touch.identifier) {
318
- touches[i] = touch;
319
- this.notifyPropertyChange('touches');
320
- break;
321
- }
322
- }
323
- },
324
-
325
- removeTouch: function(touch) {
326
- var touches = get(this, 'touches');
327
-
328
- for (var i=0, l=touches.length; i<l; i++) {
329
- var _t = touches[i];
330
-
331
- if (_t.identifier === touch.identifier) {
332
- touches.splice(i,1);
333
- this.notifyPropertyChange('touches');
334
- break;
335
- }
336
- }
337
- },
338
-
339
- removeAllTouches: function() {
340
- set(this, 'touches', []);
341
- },
342
-
343
- touchWithId: function(id) {
344
- var ret = null,
345
- touches = get(this, 'touches');
346
-
347
- for (var i=0, l=touches.length; i<l; i++) {
348
- var _t = touches[i];
349
-
350
- if (_t.identifier === id) {
351
- ret = _t;
352
- break;
353
- }
354
- }
355
-
356
- return ret;
357
- },
358
-
359
- length: function() {
360
- var touches = get(this, 'touches');
361
- return touches.length;
362
- }.property('touches').cacheable()
363
- });
364
-
365
- })({});
366
-
367
-
368
- (function(exports) {
369
- // ==========================================================================
370
- // Project: SproutCore Runtime
371
- // Copyright: ©2011 Strobe Inc. and contributors.
372
- // License: Licensed under MIT license (see license.js)
373
- // ==========================================================================
374
-
375
-
376
-
377
- var get = Ember.get;
378
- var set = Ember.set;
379
-
380
- var sigFigs = 100;
381
-
382
- /**
383
- @class
384
-
385
- Base class for all gesture recognizers. Handles low-level touch and state
386
- management, and provides some utility methods and some required methods all
387
- gesture recognizers are expected to implement.
388
-
389
- ## Overview
390
-
391
- Gestures coalesce multiple touch events to a single higher-level gesture
392
- event. For example, a tap gesture recognizer takes information about a
393
- touchstart event, a few touchmove events, and a touchend event and uses
394
- some heuristics to decide whether or not that sequence of events qualifies
395
- as a tap event. If it does, then it will notify the view of the higher-level
396
- tap events.
397
-
398
- Gesture events follow the format:
399
-
400
- * *[GESTURE_NAME]* Start - Sent when a gesture has gathered enough information
401
- to begin tracking the gesture
402
-
403
- * *[GESTURE_NAME]* Change - Sent when a gesture has already started and has
404
- received touchmove events that cause its state to change
405
-
406
- * *[GESTURE_NAME]* End - Sent when a touchend event is received and the gesture
407
- recognizer decides that the gesture is finished.
408
-
409
- * *[GESTURE_NAME]* Cancel - Sent when a touchcancel event is received.
410
-
411
- There are two types of gestures: Discrete and Continuous gestures. In contrast
412
- to continuous gestures, discrete gestures don't have any change events. Rather,
413
- the end event is the only one that gets sent to the view.
414
-
415
- ## Usage
416
-
417
- While you wouldn't use Ember.Gesture directly, all its subclasses implement the
418
- same API. For example, to implement pinch on a view, you implement one or more
419
- of the pinch events. For example:
420
-
421
- var myView = Ember.View.create({
422
- pinchStart: function(recognizer) {
423
- this.$().css('background','red');
424
- },
425
-
426
- pinchChange: function(recognizer) {
427
- var scale = recognizer.get('scale');
428
- this.$().css('scale',function(index, value) {
429
- return recognizer.get('scale') * value
430
- });
431
- },
432
-
433
- pinchEnd: function(recognizer) {
434
- this.$().css('background','blue');
435
- },
436
-
437
- pinchCancel: function(recognizer) {
438
- this.$().css('background','blue');
439
- }
440
- });
441
-
442
- pinchStart(), pinchEnd() and pinchCancel() will only get called once per
443
- gesture, but pinchChange() will get called repeatedly called every time
444
- one of the touches moves.
445
-
446
- ## Customizing Gesture Recognizers
447
-
448
- Some of the gesture recognizers include properties that can be customized by
449
- the user for a specific instance of a view. For example, a pan gesture defaults
450
- to being a one-finger gesture, but in some scenarios, it must be defined as a
451
- two-finger gesture. In that case, you can override defaults by specifying an
452
- Options hash.
453
-
454
- var myView = Ember.View.create({
455
- panOptions: {
456
- numberOfRequiredTouches: 2
457
- }
458
- });
459
-
460
- ## Creating Custom Gesture Recognizers
461
-
462
- Ember.Gesture also defines an API which its subclasses can implement to build
463
- custom gestures. The methods are:
464
-
465
- * **didBecomePossible** - Called when a gesture enters a possible state. This
466
- means the gesture recognizer has accepted enough touches to match
467
- the number of required touches. You would usually initialize your state
468
- in this callback.
469
-
470
- * **eventWasRejected** - Called if a view returns false from a gesture event.
471
- This callback allows you to reset internal state if the user rejects
472
- an event.
473
-
474
- * **shouldBegin** - Allows a gesture to block itself from entering a began state.
475
- This callback will continuously be called as touches move until it begins.
476
-
477
- * **shouldEnd** - Allows a gesture to block itself from entering an ended state.
478
- This callback gets called whenever a tracked touch gets a touchEnd event.
479
-
480
- * **didBegin** - Called when the gesture enters a began state. Called before the
481
- view receives the Start event.
482
-
483
- * **didChange** - Called when the gesture enters a began state, and when one of the
484
- touches moves. Called before the view receives the Change event.
485
-
486
- * **didEnd** - Called when the gesture enters an ended state. Called before the
487
- view receives the End event.
488
-
489
- * **didCancel** - Called when the gesture enters a cancelled state. Called before the
490
- view receives the Cancel event.
491
-
492
- In all the callbacks, you can use the `touches` protected property to access the
493
- touches hash. The touches hash is keyed on the identifiers of the touches, and the
494
- values are the jQuery.Event objects. You can also access the length property to inspect
495
- how many touches are active, this is mostly useful in shouldBegin since every other
496
- callback can assume that there are as many active touches as specified in the
497
- numberOfRequiredTouches property.
498
-
499
- ## Discrete vs Continuous Gestures
500
-
501
- There are two main classes of gesture recognizers: Discrete and Continuous
502
- gestures. Discrete gestures do not get Start, Change nor Cancel events sent,
503
- since they represent a single, instantaneous event, rather than a continuous
504
- motion. If you are implementing your own discrete gesture recognizer, you must
505
- set the isDiscreteGesture property to yes, and Ember.Gesture will adapt its behavior.
506
-
507
- Discrete gestures use the shouldEnd callback to either accept or decline the gesture
508
- event. If it is declined, then the gesture will enter a Cancelled state.
509
-
510
- @extends Ember.Object
511
- */
512
-
513
- Ember.Gesture = Ember.Object.extend(
514
- /** @scope Ember.Gesture.prototype */{
515
-
516
- /**
517
- The current state of the gesture recognizer. This value can be any one
518
- of the states defined at the end of this file.
519
-
520
- @type Number
521
- */
522
- state: null,
523
-
524
- /**
525
- A string of the gesture recognizer's name. This value is set automatically
526
- but Ember.Gestures when a gesture is registered.
527
-
528
- @type String
529
- */
530
- name: null,
531
-
532
- /**
533
- Specifies whether a gesture is discrete or continuous.
534
-
535
- @type Boolean
536
- @default false
537
- */
538
- gestureIsDiscrete: false,
539
-
540
- /**
541
- You can use the `touches` protected property to access the touches hash. The touches
542
- hash is keyed on the identifiers of the touches, and the values are the jQuery.Event
543
- objects.
544
-
545
- @private
546
- @type Hash
547
- */
548
- touches: null,
549
-
550
- /**
551
- You can also use the numberOfActiveTouches property to inspect how many touches
552
- are active, this is mostly useful in shouldBegin since every other callback can
553
- assume that there are as many active touches as specified in the
554
- numberOfRequiredTouches property.
555
-
556
- @private
557
- @type Number
558
- */
559
- numberOfActiveTouches: 0,
560
-
561
- /**
562
- Used to specify the number of touches required for the gesture to enter a possible
563
- state
564
-
565
- @private
566
- @type Number
567
- */
568
- numberOfRequiredTouches: 1,
569
-
570
- init: function() {
571
- this._super();
572
- this.touches = Ember.TouchList.create();
573
- },
574
-
575
- //..............................................
576
- // Gesture Callbacks
577
-
578
- /** @private */
579
- didBecomePossible: function() { },
580
-
581
- /** @private */
582
- shouldBegin: function() {
583
- return true;
584
- },
585
-
586
- /** @private */
587
- didBegin: function() { },
588
-
589
- /** @private */
590
- didChange: function() { },
591
-
592
- /** @private */
593
- eventWasRejected: function() { },
594
-
595
- /** @private */
596
- shouldEnd: function() {
597
- return true;
598
- },
599
-
600
- /** @private */
601
- didEnd: function() { },
602
-
603
- /** @private */
604
- didCancel: function() { },
605
-
606
- //..............................................
607
- // Utilities
608
-
609
- /** @private */
610
- attemptGestureEventDelivery: function(evt, view, eventName, stopPropagation) {
611
- if (stopPropagation === undefined) {
612
- stopPropagation = true;
613
- }
614
-
615
- if (this.notifyViewOfGestureEvent(view, eventName) === false) {
616
- this.eventWasRejected();
617
- } else if(stopPropagation) {
618
- evt.preventDefault();
619
- }
620
- },
621
-
622
- /**
623
- Given two Touch objects, this method returns the distance between them.
624
-
625
- @return Number
626
- */
627
- distance: function(touches) {
628
-
629
- if (touches.length < 2) {
630
- return 0;
631
- }
632
-
633
- var first = touches[0];
634
- var second = touches[1];
635
-
636
- var x = first.pageX;
637
- var y = first.pageY;
638
- var x0 = second.pageX;
639
- var y0 = second.pageY;
640
-
641
- return Math.sqrt((x -= x0) * x + (y -= y0) * y);
642
- },
643
-
644
- /**
645
- Given two Touch objects, this method returns the midpoint between them.
646
-
647
- @return Number
648
- */
649
- centerPointForTouches: function(touches) {
650
- var sumX = 0,
651
- sumY = 0;
652
-
653
- for (var i=0, l=touches.length; i<l; i++) {
654
- var touch = touches[i];
655
- sumX += touch.pageX;
656
- sumY += touch.pageY;
657
- }
658
-
659
- var location = {
660
- x: sumX / touches.length,
661
- y: sumY / touches.length
662
- };
663
-
664
- return location;
665
- },
666
-
667
- /** @private */
668
- _objectValues: function(object) {
669
- var ret = [];
670
-
671
- for (var item in object ) {
672
- if (object.hasOwnProperty(item)) {
673
- ret.push(object[item]);
674
- }
675
- }
676
-
677
- return ret;
678
- },
679
-
680
- /**
681
- Allows the gesture to notify the view it's associated with of a gesture
682
- event.
683
-
684
- @private
685
- */
686
- notifyViewOfGestureEvent: function(view, eventName, data) {
687
- var handler = view[eventName];
688
- var result = true;
689
-
690
- if (Ember.typeOf(handler) === 'function') {
691
- result = handler.call(view, this, data);
692
- }
693
-
694
- return result;
695
- },
696
-
697
- toString: function() {
698
- return Ember.Gesture+'<'+Ember.guidFor(this)+'>';
699
- },
700
-
701
- /** @private */
702
- _resetState: function() {
703
- this.touches.removeAllTouches();
704
- },
705
-
706
- //..............................................
707
- // Touch event handlers
708
-
709
- /** @private */
710
- touchStart: function(evt, view, manager) {
711
- var targetTouches = evt.originalEvent.targetTouches;
712
- var _touches = this.touches;
713
- var state = get(this, 'state');
714
-
715
- set(_touches, 'timestamp', Date.now());
716
-
717
- //Collect touches by their identifiers
718
- for (var i=0, l=targetTouches.length; i<l; i++) {
719
- var touch = targetTouches[i];
720
-
721
- if(_touches.touchWithId(touch.identifier) === null && _touches.get('length') < get(this, 'numberOfRequiredTouches')) {
722
- _touches.addTouch(touch);
723
- }
724
- }
725
-
726
- if (_touches.get('length') < get(this, 'numberOfRequiredTouches')) {
727
- set(this ,'state', Ember.Gesture.WAITING_FOR_TOUCHES);
728
-
729
- } else {
730
- // Discrete gestures may skip the possible step if they're ready to begin
731
- if (get(this, 'gestureIsDiscrete') && this.shouldBegin()) {
732
- set(this, 'state', Ember.Gesture.BEGAN);
733
- this.didBegin();
734
- } else {
735
- set(this, 'state', Ember.Gesture.POSSIBLE);
736
- this.didBecomePossible();
737
- }
738
- }
739
-
740
- manager.redispatchEventToView(view,'touchstart', evt);
741
- },
742
-
743
- /** @private */
744
- touchMove: function(evt, view, manager) {
745
- var state = get(this, 'state');
746
-
747
- if (state === Ember.Gesture.WAITING_FOR_TOUCHES || state === Ember.Gesture.ENDED || state === Ember.Gesture.CANCELLED) {
748
- // Nothing to do here
749
- manager.redispatchEventToView(view,'touchmove', evt);
750
- return;
751
- }
752
-
753
- var changedTouches = evt.originalEvent.changedTouches;
754
- var _touches = this.touches;
755
-
756
- set(_touches, 'timestamp', Date.now());
757
-
758
- // Update touches hash
759
- for (var i=0, l=changedTouches.length; i<l; i++) {
760
- var touch = changedTouches[i];
761
- _touches.updateTouch(touch);
762
- }
763
-
764
- if (state === Ember.Gesture.POSSIBLE) {
765
- if (this.shouldBegin()) {
766
- set(this, 'state', Ember.Gesture.BEGAN);
767
- this.didBegin();
768
-
769
- // Give the gesture a chance to update its state so the view can get
770
- // updated information in the Start event
771
- this.didChange();
772
-
773
- this.attemptGestureEventDelivery(evt, view, get(this, 'name')+'Start',(this.get('isDiscreteGesture'))? true: false);
774
- }
775
-
776
- // Discrete gestures don't fire changed events
777
- } else if ((state === Ember.Gesture.BEGAN || state === Ember.Gesture.CHANGED) && !get(this, 'gestureIsDiscrete')) {
778
- set(this, 'state', Ember.Gesture.CHANGED);
779
- this.didChange();
780
-
781
- this.attemptGestureEventDelivery(evt, view, get(this, 'name')+'Change');
782
-
783
- } else {
784
- manager.redispatchEventToView(view,'touchmove', evt);
785
- }
786
- },
787
-
788
- /** @private */
789
- touchEnd: function(evt, view, manager) {
790
- // Discrete gestures need to cancel if they shouldn't end successfully
791
- if (get(this, 'gestureIsDiscrete')) {
792
-
793
- // Discrete gestures use shouldEnd to either accept or decline the gesture.
794
- if (this.state === Ember.Gesture.BEGAN && this.shouldEnd()) {
795
- set(this, 'state', Ember.Gesture.ENDED);
796
- this.didEnd();
797
- this.attemptGestureEventDelivery(evt, view, get(this, 'name')+'End');
798
- } else {
799
- set(this, 'state', Ember.Gesture.CANCELLED);
800
- this.didCancel();
801
- this.attemptGestureEventDelivery(evt, view, get(this, 'name')+'Cancel');
802
- }
803
- }
804
- else {
805
- if ((this.state === Ember.Gesture.BEGAN || this.state === Ember.Gesture.CHANGED) && this.shouldEnd()) {
806
- set(this, 'state', Ember.Gesture.ENDED);
807
- this.didEnd();
808
-
809
- this.attemptGestureEventDelivery(evt, view, get(this, 'name')+'End');
810
- }
811
-
812
- manager.redispatchEventToView(view,'touchend', evt);
813
- }
814
-
815
- this._resetState();
816
- },
817
-
818
- /** @private */
819
- touchCancel: function(evt, view, manager) {
820
- if (this.state !== Ember.Gesture.CANCELLED) {
821
- this._resetState();
822
- set(this, 'state', Ember.Gesture.CANCELLED);
823
- this.notifyViewOfGestureEvent(view,get(this, 'name')+'Cancel');
824
- } else {
825
- manager.redispatchEventToView(view,'touchcancel', evt);
826
- }
827
- }
828
- });
829
-
830
- Ember.Gesture.WAITING_FOR_TOUCHES = 0;
831
- Ember.Gesture.POSSIBLE = 1;
832
- Ember.Gesture.BEGAN = 2;
833
- Ember.Gesture.CHANGED = 3;
834
- Ember.Gesture.ENDED = 4;
835
- Ember.Gesture.CANCELLED = 4;
836
-
837
- })({});
838
-
839
-
840
- (function(exports) {
841
- // ==========================================================================
842
- // Project: SproutCore Runtime
843
- // Copyright: ©2011 Strobe Inc. and contributors.
844
- // License: Licensed under MIT license (see license.js)
845
- // ==========================================================================
846
-
847
- var get = Ember.get;
848
- var set = Ember.set;
849
-
850
- var sigFigs = 100;
851
-
852
- /**
853
- @class
854
-
855
- Recognizes a multi-touch pinch gesture. Pinch gestures require a specified number
856
- of fingers to move and will record and update the scale.
857
-
858
- For pinchChange events, the pinch gesture recognizer includes a scale property
859
- which can be applied as a CSS transform directly.
860
-
861
- var myview = Ember.View.create({
862
- elementId: 'gestureTest',
863
-
864
- pinchChange: function(rec) {
865
- this.$().css('scale',function(index, value) {
866
- return rec.get('scale') * value
867
- });
868
- }
869
- })
870
-
871
- You can specify how many touches the gesture requires to start using the numberOfRequiredTouches
872
- property, which you can set in the pinchOptions hash:
873
-
874
- var myview = Ember.View.create({
875
- pinchOptions: {
876
- numberOfRequiredTouches: 3
877
- }
878
- ...
879
- })
880
-
881
-
882
- @extends Ember.Gesture
883
- */
884
- Ember.PinchGestureRecognizer = Ember.Gesture.extend({
885
-
886
- /**
887
- The scale value which represents the current amount of scaling that has been applied
888
- to the view. You would normally apply this value directly to your element as a 3D
889
- scale.
890
-
891
- @type Number
892
- */
893
- scale: 1,
894
-
895
- numberOfRequiredTouches: 2,
896
-
897
- //..................................................
898
- // Private Methods and Properties
899
-
900
- /**
901
- Track starting distance between touches per gesture.
902
-
903
- @private
904
- @type Number
905
- */
906
- _startingDistanceBetweenTouches: null,
907
-
908
- /**
909
- Used for measuring velocity
910
-
911
- @private
912
- @type Number
913
- */
914
- _previousTimestamp: null,
915
-
916
- /**
917
- Used for measuring velocity and scale
918
-
919
- @private
920
- @type Number
921
- */
922
- _previousDistance: 0,
923
-
924
- /**
925
- The pixel distance that the fingers need to get closer/farther away by before
926
- this gesture is recognized.
927
-
928
- @private
929
- @type Number
930
- */
931
- _deltaThreshold: 5,
932
-
933
- /**
934
- Used for rejected events
935
-
936
- @private
937
- @type Number
938
- */
939
- _previousScale: 1,
940
-
941
- /**
942
- @private
943
- */
944
- didBecomePossible: function() {
945
- this._startingDistanceBetweenTouches = this.distance(get(this.touches,'touches'));
946
- this._previousDistance = this._startingDistanceBetweenTouches;
947
- this._previousTimestamp = get(this.touches,'timestamp');
948
- },
949
-
950
- shouldBegin: function() {
951
- var currentDistanceBetweenTouches = this.distance(get(this.touches,'touches'));
952
-
953
- return Math.abs(currentDistanceBetweenTouches - this._startingDistanceBetweenTouches) >= this._deltaThreshold;
954
- },
955
-
956
- didChange: function() {
957
- var scale = this._previousScale = get(this, 'scale');
958
- var timeDifference = this.touches.timestamp - this._previousTimestamp;
959
- var currentDistanceBetweenTouches = this.distance(get(this.touches,'touches'));
960
- var distanceDifference = (currentDistanceBetweenTouches - this._previousDistance);
961
-
962
- set(this, 'velocity', distanceDifference / timeDifference);
963
- set(this, 'scale', currentDistanceBetweenTouches / this._previousDistance);
964
-
965
- this._previousTimestamp = get(this.touches,'timestamp');
966
- this._previousDistance = currentDistanceBetweenTouches;
967
- },
968
-
969
- eventWasRejected: function() {
970
- set(this, 'scale', this._previousScale);
971
- }
972
- });
973
-
974
- Ember.Gestures.register('pinch', Ember.PinchGestureRecognizer);
975
-
976
- })({});
977
-
978
-
979
- (function(exports) {
980
- // ==========================================================================
981
- // Project: SproutCore Runtime
982
- // Copyright: ©2011 Strobe Inc. and contributors.
983
- // License: Licensed under MIT license (see license.js)
984
- // ==========================================================================
985
-
986
- var get = Ember.get;
987
- var set = Ember.set;
988
- var x = 0;
989
-
990
- /**
991
- @class
992
-
993
- Recognizes a multi-touch pan gesture. Pan gestures require a specified number
994
- of fingers to move and will record and update the center point between the
995
- touches.
996
-
997
- For panChange events, the pan gesture recognizer includes a translation property
998
- which can be applied as a CSS transform directly. Translation values are hashes
999
- which contain an x and a y value.
1000
-
1001
- var myview = Ember.View.create({
1002
- elementId: 'gestureTest',
1003
-
1004
- panChange: function(rec) {
1005
- var val = rec.get('translation');
1006
- this.$().css({
1007
- translateX: '%@=%@'.fmt((val.x < 0)? '-' : '+',Math.abs(val.x)),
1008
- translateY: '%@=%@'.fmt((val.y < 0)? '-' : '+',Math.abs(val.y))
1009
- });
1010
- }
1011
- })
1012
-
1013
- You can specify how many touches the gesture requires to start using the numberOfRequiredTouches
1014
- property, which you can set in the panOptions hash:
1015
-
1016
- var myview = Ember.View.create({
1017
- panOptions: {
1018
- numberOfRequiredTouches: 3
1019
- }
1020
- ...
1021
- })
1022
-
1023
- @extends Ember.Gesture
1024
- */
1025
- Ember.PanGestureRecognizer = Ember.Gesture.extend({
1026
-
1027
- /**
1028
- The translation value which represents the current amount of movement that has been applied
1029
- to the view. You would normally apply this value directly to your element as a 3D
1030
- transform.
1031
-
1032
- @type Location
1033
- */
1034
- translation: null,
1035
-
1036
- //..................................................
1037
- // Private Methods and Properties
1038
-
1039
- /**
1040
- Used to measure offsets
1041
-
1042
- @private
1043
- @type Number
1044
- */
1045
- _previousLocation: null,
1046
-
1047
- /**
1048
- Used for rejected events
1049
-
1050
- @private
1051
- @type Hash
1052
- */
1053
- _previousTranslation: null,
1054
-
1055
- /**
1056
- The pixel distance that the fingers need to move before this gesture is recognized.
1057
-
1058
- @private
1059
- @type Number
1060
- */
1061
- _translationThreshold: 5,
1062
-
1063
- init: function() {
1064
- this._super();
1065
- set(this, 'translation', {x:0,y:0});
1066
- },
1067
-
1068
- didBecomePossible: function() {
1069
- this._previousLocation = this.centerPointForTouches(get(this.touches,'touches'));
1070
- },
1071
-
1072
- shouldBegin: function() {
1073
- var previousLocation = this._previousLocation;
1074
- var currentLocation = this.centerPointForTouches(get(this.touches,'touches'));
1075
-
1076
- var x = previousLocation.x;
1077
- var y = previousLocation.y;
1078
- var x0 = currentLocation.x;
1079
- var y0 = currentLocation.y;
1080
-
1081
- var distance = Math.sqrt((x -= x0) * x + (y -= y0) * y);
1082
- return distance >= this._translationThreshold;
1083
- },
1084
-
1085
- didChange: function() {
1086
- var previousLocation = this._previousLocation;
1087
- var currentLocation = this.centerPointForTouches(get(this.touches,'touches'));
1088
- var translation = {x:currentLocation.x, y:currentLocation.y};
1089
-
1090
- translation.x = currentLocation.x - previousLocation.x;
1091
- translation.y = currentLocation.y - previousLocation.y;
1092
-
1093
- this._previousTranslation = get(this, 'translation');
1094
- set(this, 'translation', translation);
1095
- this._previousLocation = currentLocation;
1096
- },
1097
-
1098
- eventWasRejected: function() {
1099
- set(this, 'translation', this._previousTranslation);
1100
- }
1101
- });
1102
-
1103
- Ember.Gestures.register('pan', Ember.PanGestureRecognizer);
1104
-
1105
- })({});
1106
-
1107
-
1108
- (function(exports) {
1109
- // ==========================================================================
1110
- // Project: SproutCore Runtime
1111
- // Copyright: ©2011 Strobe Inc. and contributors.
1112
- // License: Licensed under MIT license (see license.js)
1113
- // ==========================================================================
1114
-
1115
- var get = Ember.get;
1116
- var set = Ember.set;
1117
-
1118
- /**
1119
- @class
1120
-
1121
- Recognizes a multi-touch tap gesture. Tap gestures allow for a certain amount
1122
- of wiggle-room between a start and end of a touch. Taps are discrete gestures
1123
- so only tapEnd() will get fired on a view.
1124
-
1125
- var myview = Ember.View.create({
1126
- elementId: 'gestureTest',
1127
-
1128
- tapEnd: function(recognizer) {
1129
- $('#gestureTest').css('background','yellow');
1130
- }
1131
- })
1132
-
1133
- You can specify how many touches the gesture requires to start using the numberOfRequiredTouches
1134
- property, which you can set in the panOptions hash:
1135
-
1136
- var myview = Ember.View.create({
1137
- tapOptions: {
1138
- numberOfTaps: 3
1139
- }
1140
- ...
1141
- })
1142
-
1143
- And you can also specify the number of taps required for the gesture to fire using the numberOfTaps
1144
- property.
1145
-
1146
- @extends Ember.Gesture
1147
- */
1148
- Ember.TapGestureRecognizer = Ember.Gesture.extend({
1149
-
1150
- /**
1151
- The translation value which represents the current amount of movement that has been applied
1152
- to the view. You would normally apply this value directly to your element as a 3D
1153
- transform.
1154
-
1155
- @type Location
1156
- */
1157
- numberOfTaps: 1,
1158
-
1159
- //..................................................
1160
- // Private Methods and Properties
1161
-
1162
- /** @private */
1163
- MULTITAP_DELAY: 150,
1164
-
1165
- /** @private */
1166
- gestureIsDiscrete: true,
1167
-
1168
- /** @private */
1169
- _initialLocation: null,
1170
-
1171
- /** @private */
1172
- _waitingInterval: null,
1173
-
1174
- /** @private */
1175
- _waitingForMoreTouches: false,
1176
-
1177
- /** @private */
1178
- _moveThreshold: 10,
1179
-
1180
- shouldBegin: function() {
1181
- return get(this.touches,'length') === get(this, 'numberOfRequiredTouches');
1182
- },
1183
-
1184
- didBegin: function() {
1185
- this._initialLocation = this.centerPointForTouches(get(this.touches,'touches'));
1186
-
1187
- if (get(this.touches,'length') < get(this, 'numberOfTaps')) {
1188
- this._waitingForMoreTouches = true;
1189
- this._waitingInterval = window.setInterval(this._intervalFired,this.MULTITAP_DELAY);
1190
- }
1191
- },
1192
-
1193
- shouldEnd: function() {
1194
- var currentLocation = this.centerPointForTouches(get(this.touches,'touches'));
1195
-
1196
- var x = this._initialLocation.x;
1197
- var y = this._initialLocation.y;
1198
- var x0 = currentLocation.x;
1199
- var y0 = currentLocation.y;
1200
-
1201
- var distance = Math.sqrt((x -= x0) * x + (y -= y0) * y);
1202
-
1203
- return (Math.abs(distance) < this._moveThreshold) && !this._waitingForMoreTouches;
1204
- },
1205
-
1206
- didEnd: function() {
1207
- this._initialLocation = null;
1208
- },
1209
-
1210
- didCancel: function() {
1211
- this._initialLocation = null;
1212
- },
1213
-
1214
- _intervalFired: function() {
1215
- window.clearInterval(this._waitingInterval);
1216
- _waitingForMoreTouches = false;
1217
- }
1218
- });
1219
-
1220
- Ember.Gestures.register('tap', Ember.TapGestureRecognizer);
1221
-
1222
- })({});
1223
-
1224
-
1225
- (function(exports) {
1226
-
1227
-
1228
-
1229
- })({});
1230
-
1231
-
1232
- (function(exports) {
1233
- // ==========================================================================
1234
- // Project: SproutCore Runtime
1235
- // Copyright: ©2011 Strobe Inc. and contributors.
1236
- // License: Licensed under MIT license (see license.js)
1237
- // ==========================================================================
1238
-
1239
- var get = Ember.get;
1240
- var set = Ember.set;
1241
-
1242
- /**
1243
- @class
1244
-
1245
- Extends Ember.View by making the init method gesture-aware.
1246
-
1247
- @extends Ember.Object
1248
- */
1249
- Ember.View.reopen(
1250
- /** @scope Ember.View.prototype */{
1251
-
1252
- /**
1253
- The Ember.GestureManager instance which will manager the gestures of the view.
1254
- This object is automatically created and set at init-time.
1255
-
1256
- @default null
1257
- @type Array
1258
- */
1259
- eventManager: null,
1260
-
1261
- /**
1262
- Inspects the properties on the view instance and create gestures if they're
1263
- used.
1264
- */
1265
- init: function() {
1266
- this._super();
1267
-
1268
- var knownGestures = Ember.Gestures.knownGestures();
1269
- var eventManager = get(this, 'eventManager');
1270
-
1271
- if (knownGestures && !eventManager) {
1272
- var gestures = [];
1273
-
1274
- for (var gesture in knownGestures) {
1275
- if (this[gesture+'Start'] || this[gesture+'Change'] || this[gesture+'End']) {
1276
-
1277
- var optionsHash;
1278
- if (this[gesture+'Options'] !== undefined && typeof this[gesture+'Options'] === 'object') {
1279
- optionsHash = this[gesture+'Options'];
1280
- } else {
1281
- optionsHash = {};
1282
- }
1283
-
1284
- optionsHash.name = gesture;
1285
- optionsHash.view = this;
1286
-
1287
- gestures.push(knownGestures[gesture].create(optionsHash));
1288
- }
1289
- }
1290
-
1291
- var manager = Ember.GestureManager.create({
1292
- gestures: gestures
1293
- });
1294
-
1295
- set(this, 'eventManager', manager);
1296
-
1297
- }
1298
- }
1299
-
1300
- });
1301
-
1302
- })({});
1303
-