sproutcore 1.11.0.rc3 → 1.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +6 -14
- data/CHANGELOG +5 -0
- data/VERSION.yml +1 -1
- data/lib/frameworks/sproutcore/Buildfile +3 -2
- data/lib/frameworks/sproutcore/CHANGELOG.md +59 -10
- data/lib/frameworks/sproutcore/apps/showcase/resources/main_page.js +1 -0
- data/lib/frameworks/sproutcore/apps/showcase/resources/stylesheet.css +9 -4
- data/lib/frameworks/sproutcore/frameworks/core_foundation/panes/manipulation.js +1 -1
- data/lib/frameworks/sproutcore/frameworks/core_foundation/system/event.js +0 -10
- data/lib/frameworks/sproutcore/frameworks/core_foundation/system/locale.js +1 -1
- data/lib/frameworks/sproutcore/frameworks/core_foundation/system/root_responder.js +10 -45
- data/lib/frameworks/sproutcore/frameworks/core_foundation/system/selection_set.js +3 -3
- data/lib/frameworks/sproutcore/frameworks/core_foundation/system/touch.js +76 -0
- data/lib/frameworks/sproutcore/frameworks/core_foundation/tests/system/{touch.js → touch_test.js} +64 -0
- data/lib/frameworks/sproutcore/frameworks/core_foundation/tests/views/pane/append_remove.js +1 -1
- data/lib/frameworks/sproutcore/frameworks/core_foundation/tests/views/pane/design_mode_test.js +61 -24
- data/lib/frameworks/sproutcore/frameworks/core_foundation/tests/views/view/createChildViews.js +1 -2
- data/lib/frameworks/sproutcore/frameworks/core_foundation/tests/views/view/destroy.js +0 -3
- data/lib/frameworks/sproutcore/frameworks/core_foundation/tests/views/view/{layoutStyle.js → layout_style_test.js} +4 -4
- data/lib/frameworks/sproutcore/frameworks/core_foundation/tests/views/view/layout_test.js +602 -0
- data/lib/frameworks/sproutcore/frameworks/core_foundation/tests/views/view/viewDidResize.js +0 -23
- data/lib/frameworks/sproutcore/frameworks/core_foundation/views/view.js +18 -17
- data/lib/frameworks/sproutcore/frameworks/core_foundation/views/view/animation.js +5 -5
- data/lib/frameworks/sproutcore/frameworks/core_foundation/views/view/design_mode.js +64 -24
- data/lib/frameworks/sproutcore/frameworks/core_foundation/views/view/layout.js +904 -871
- data/lib/frameworks/sproutcore/frameworks/core_foundation/views/view/layout_style.js +1 -3
- data/lib/frameworks/sproutcore/frameworks/core_foundation/views/view/statechart.js +40 -24
- data/lib/frameworks/sproutcore/frameworks/datastore/data_sources/fixtures.js +2 -2
- data/lib/frameworks/sproutcore/frameworks/datastore/models/record.js +5 -5
- data/lib/frameworks/sproutcore/frameworks/datastore/system/nested_store.js +14 -14
- data/lib/frameworks/sproutcore/frameworks/datastore/system/query.js +1 -1
- data/lib/frameworks/sproutcore/frameworks/datastore/system/record_array.js +2 -2
- data/lib/frameworks/sproutcore/frameworks/datastore/system/store.js +36 -33
- data/lib/frameworks/sproutcore/frameworks/datastore/tests/models/record/writeAttribute.js +1 -1
- data/lib/frameworks/sproutcore/frameworks/datastore/tests/system/nested_store/autonomous_dataSourceCallbacks.js +6 -6
- data/lib/frameworks/sproutcore/frameworks/datastore/tests/system/store/commitChangesFromNestedStore.js +1 -1
- data/lib/frameworks/sproutcore/frameworks/datastore/tests/system/store/commitRecord.js +1 -1
- data/lib/frameworks/sproutcore/frameworks/datastore/tests/system/store/dataSourceCallbacks.js +7 -7
- data/lib/frameworks/sproutcore/frameworks/datastore/tests/system/store/destroyRecord.js +2 -2
- data/lib/frameworks/sproutcore/frameworks/datastore/tests/system/store/recordDidChange.js +2 -2
- data/lib/frameworks/sproutcore/frameworks/datastore/tests/system/store/retrieveRecord.js +4 -4
- data/lib/frameworks/sproutcore/frameworks/datetime/frameworks/core/system/datetime.js +11 -11
- data/lib/frameworks/sproutcore/frameworks/designer/coders/object.js +1 -1
- data/lib/frameworks/sproutcore/frameworks/desktop/panes/menu.js +30 -1
- data/lib/frameworks/sproutcore/frameworks/desktop/panes/picker.js +12 -1
- data/lib/frameworks/sproutcore/frameworks/desktop/views/menu_scroll.js +5 -3
- data/lib/frameworks/sproutcore/frameworks/desktop/views/menu_scroller_view.js +0 -36
- data/lib/frameworks/sproutcore/frameworks/desktop/views/scroll_view.js +3 -3
- data/lib/frameworks/sproutcore/frameworks/desktop/views/segmented.js +1 -1
- data/lib/frameworks/sproutcore/frameworks/desktop/views/static_content.js +1 -1
- data/lib/frameworks/sproutcore/frameworks/foundation/gestures/pinch_gesture.js +286 -0
- data/lib/frameworks/sproutcore/frameworks/foundation/gestures/swipe_gesture.js +449 -0
- data/lib/frameworks/sproutcore/frameworks/foundation/gestures/tap_gesture.js +259 -0
- data/lib/frameworks/sproutcore/frameworks/foundation/mixins/gesturable.js +218 -30
- data/lib/frameworks/sproutcore/frameworks/foundation/system/gesture.js +259 -158
- data/lib/frameworks/sproutcore/frameworks/foundation/system/string.js +58 -50
- data/lib/frameworks/sproutcore/frameworks/foundation/system/utils/string_measurement.js +1 -1
- data/lib/frameworks/sproutcore/frameworks/foundation/tests/gestures/pinch_gesture_test.js +321 -0
- data/lib/frameworks/sproutcore/frameworks/foundation/tests/gestures/swipe_gesture_test.js +154 -0
- data/lib/frameworks/sproutcore/frameworks/foundation/tests/gestures/tap_gesture_test.js +55 -0
- data/lib/frameworks/sproutcore/frameworks/foundation/tests/mixins/gesturable_test.js +233 -0
- data/lib/frameworks/sproutcore/frameworks/foundation/tests/mixins/staticLayout.js +2 -2
- data/lib/frameworks/sproutcore/frameworks/foundation/tests/system/gesture_test.js +254 -0
- data/lib/frameworks/sproutcore/frameworks/foundation/views/container.js +1 -0
- data/lib/frameworks/sproutcore/frameworks/foundation/views/text_field.js +1 -1
- data/lib/frameworks/sproutcore/frameworks/legacy/object_keys_polyfill.js +51 -0
- data/lib/frameworks/sproutcore/frameworks/{core_foundation/system/req_anim_frame.js → legacy/request_animation_frame_polyfill.js} +10 -3
- data/lib/frameworks/sproutcore/frameworks/media/views/audio.js +19 -25
- data/lib/frameworks/sproutcore/frameworks/media/views/controls.js +7 -7
- data/lib/frameworks/sproutcore/frameworks/media/views/mini_controls.js +3 -3
- data/lib/frameworks/sproutcore/frameworks/media/views/simple_controls.js +9 -9
- data/lib/frameworks/sproutcore/frameworks/runtime/core.js +2 -2
- data/lib/frameworks/sproutcore/frameworks/runtime/debug/test_suites/array/insertAt.js +2 -2
- data/lib/frameworks/sproutcore/frameworks/runtime/debug/test_suites/array/removeAt.js +1 -1
- data/lib/frameworks/sproutcore/frameworks/runtime/ext/array.js +1 -1
- data/lib/frameworks/sproutcore/frameworks/runtime/mixins/array.js +2 -2
- data/lib/frameworks/sproutcore/frameworks/runtime/mixins/freezable.js +2 -2
- data/lib/frameworks/sproutcore/frameworks/runtime/mixins/observable.js +66 -5
- data/lib/frameworks/sproutcore/frameworks/runtime/mixins/tree.js +44 -0
- data/lib/frameworks/sproutcore/frameworks/runtime/private/observer_queue.js +4 -1
- data/lib/frameworks/sproutcore/frameworks/runtime/system/binding.js +0 -25
- data/lib/frameworks/sproutcore/frameworks/runtime/system/enumerator.js +1 -1
- data/lib/frameworks/sproutcore/frameworks/runtime/system/error.js +67 -15
- data/lib/frameworks/sproutcore/frameworks/runtime/system/index_set.js +6 -11
- data/lib/frameworks/sproutcore/frameworks/runtime/system/set.js +6 -6
- data/lib/frameworks/sproutcore/frameworks/runtime/system/string.js +1 -1
- data/lib/frameworks/sproutcore/frameworks/runtime/tests/mixins/observable/{observable.js → observable_test.js} +110 -16
- data/lib/frameworks/sproutcore/frameworks/runtime/tests/system/error.js +21 -0
- data/lib/frameworks/sproutcore/frameworks/statechart/system/statechart.js +2 -2
- data/lib/frameworks/sproutcore/frameworks/template_view/ext/handlebars.js +1 -1
- data/lib/frameworks/sproutcore/frameworks/testing/system/plan.js +1 -1
- data/lib/sproutcore/render_engines/haml.rb +1 -1
- metadata +610 -604
- data/lib/frameworks/sproutcore/frameworks/core_foundation/tests/views/view/layout.js +0 -210
- data/lib/frameworks/sproutcore/frameworks/core_foundation/tests/views/view/layoutDidChange.js +0 -275
- data/lib/frameworks/sproutcore/frameworks/foundation/gestures/pinch.js +0 -119
- data/lib/frameworks/sproutcore/frameworks/foundation/gestures/swipe.js +0 -234
- data/lib/frameworks/sproutcore/frameworks/foundation/gestures/tap.js +0 -157
@@ -1,119 +0,0 @@
|
|
1
|
-
// ==========================================================================
|
2
|
-
// Project: SproutCore - JavaScript Application Framework
|
3
|
-
// Copyright: ©2006-2011 Strobe Inc. and contributors.
|
4
|
-
// Portions ©2008-2011 Apple Inc. All rights reserved.
|
5
|
-
// License: Licensed under MIT license (see license.js)
|
6
|
-
// ==========================================================================
|
7
|
-
|
8
|
-
sc_require("system/gesture");
|
9
|
-
|
10
|
-
/*
|
11
|
-
TODO Document this class
|
12
|
-
*/
|
13
|
-
|
14
|
-
/**
|
15
|
-
@class
|
16
|
-
@extends SC.Gesture
|
17
|
-
*/
|
18
|
-
SC.PinchGesture = SC.Gesture.extend(
|
19
|
-
/** @scope SC.PinchGesture.prototype */{
|
20
|
-
|
21
|
-
/**
|
22
|
-
@type String
|
23
|
-
@default "pinch"
|
24
|
-
@readOnly
|
25
|
-
*/
|
26
|
-
name: "pinch",
|
27
|
-
|
28
|
-
/**
|
29
|
-
@type Boolean
|
30
|
-
@default YES
|
31
|
-
@readOnly
|
32
|
-
*/
|
33
|
-
acceptsMultitouch: YES,
|
34
|
-
|
35
|
-
/**
|
36
|
-
@type Number
|
37
|
-
@default 1
|
38
|
-
*/
|
39
|
-
scale: 1,
|
40
|
-
|
41
|
-
/**
|
42
|
-
The default for this method is to loop through each touch one by one to see if it qualifies.
|
43
|
-
Here, however, we want to take the touches when there are 2, and only 2 of them. As a result
|
44
|
-
we can do the work here, with no need to pass them on.
|
45
|
-
|
46
|
-
@param {Event} evt The touch event
|
47
|
-
@param {Array} touches All touches
|
48
|
-
*/
|
49
|
-
unassignedTouchesDidChange: function(evt, touches) {
|
50
|
-
if (touches.length == 2) {
|
51
|
-
this.take(touches[0]);
|
52
|
-
this.take(touches[1]);
|
53
|
-
}
|
54
|
-
},
|
55
|
-
|
56
|
-
/**
|
57
|
-
We could probably just return YES here, since unassignedTouchesDidChange shouldn't let more
|
58
|
-
than 2 touches through, however, we're double checking here to make sure that we haven't
|
59
|
-
already captured 2 touches.
|
60
|
-
|
61
|
-
@param {Touch} touch
|
62
|
-
@returns {Boolean} YES if there were none or one touches prior to this, NO otherwise
|
63
|
-
*/
|
64
|
-
touchStart: function(touch) {
|
65
|
-
var touches = touch.touchesForResponder(this);
|
66
|
-
if (!touches || touches.length === 0) {
|
67
|
-
return YES;
|
68
|
-
} else if (touches.length == 1) {
|
69
|
-
this.start([touches[0], touch]);
|
70
|
-
return YES;
|
71
|
-
} else {
|
72
|
-
return NO;
|
73
|
-
}
|
74
|
-
},
|
75
|
-
|
76
|
-
/**
|
77
|
-
Here we're getting the distance between the 2 touches and comparing it to their starting
|
78
|
-
distance. It's possible we'll want to implement a more complex algorithm to make things
|
79
|
-
a bit smoother. Once we have the relative change, we trigger the pinch action in the view.
|
80
|
-
|
81
|
-
@param {Event} evt
|
82
|
-
@param {Array} touches
|
83
|
-
*/
|
84
|
-
touchesDragged: function(evt, touches) {
|
85
|
-
var touch = touches.firstObject(),
|
86
|
-
avg = touch.averagedTouchesForView(this);
|
87
|
-
|
88
|
-
if (avg.touchCount == 2) {
|
89
|
-
if (!this._startDistance) {
|
90
|
-
this._startDistance = avg.d;
|
91
|
-
}
|
92
|
-
|
93
|
-
this.scale = avg.d / this._startDistance;
|
94
|
-
|
95
|
-
this.change(touches, this.scale);
|
96
|
-
}
|
97
|
-
},
|
98
|
-
|
99
|
-
/**
|
100
|
-
Once one touch has ended we don't need to watch the other so we release all touches.
|
101
|
-
|
102
|
-
@param {SC.Touch} touch
|
103
|
-
*/
|
104
|
-
touchEnd: function(touch) {
|
105
|
-
this._startDistance = null;
|
106
|
-
|
107
|
-
var touches = touch.touchesForResponder(this);
|
108
|
-
|
109
|
-
this.trigger(touches, this.scale);
|
110
|
-
this.end(touches, this.scale);
|
111
|
-
|
112
|
-
if (touches) {
|
113
|
-
touches.forEach(function(touch){
|
114
|
-
this.release(touch);
|
115
|
-
}, this);
|
116
|
-
}
|
117
|
-
}
|
118
|
-
|
119
|
-
});
|
@@ -1,234 +0,0 @@
|
|
1
|
-
// ==========================================================================
|
2
|
-
// Project: SproutCore - JavaScript Application Framework
|
3
|
-
// Copyright: ©2006-2011 Strobe Inc. and contributors.
|
4
|
-
// Portions ©2008-2011 Apple Inc. All rights reserved.
|
5
|
-
// License: Licensed under MIT license (see license.js)
|
6
|
-
// ==========================================================================
|
7
|
-
|
8
|
-
sc_require("system/gesture");
|
9
|
-
|
10
|
-
/*
|
11
|
-
TODO Document this class
|
12
|
-
*/
|
13
|
-
|
14
|
-
/**
|
15
|
-
@static
|
16
|
-
@type String
|
17
|
-
@constant
|
18
|
-
*/
|
19
|
-
SC.SWIPE_HORIZONTAL = "X";
|
20
|
-
|
21
|
-
/**
|
22
|
-
@static
|
23
|
-
@type String
|
24
|
-
@constant
|
25
|
-
*/
|
26
|
-
SC.SWIPE_VERTICAL = "Y";
|
27
|
-
|
28
|
-
/**
|
29
|
-
@static
|
30
|
-
@type String
|
31
|
-
@constant
|
32
|
-
*/
|
33
|
-
SC.SWIPE_ANY = "XY";
|
34
|
-
|
35
|
-
/**
|
36
|
-
@static
|
37
|
-
@type String
|
38
|
-
@constant
|
39
|
-
*/
|
40
|
-
SC.SWIPE_LEFT = "LEFT";
|
41
|
-
|
42
|
-
/**
|
43
|
-
@static
|
44
|
-
@type String
|
45
|
-
@constant
|
46
|
-
*/
|
47
|
-
SC.SWIPE_RIGHT = "RIGHT";
|
48
|
-
|
49
|
-
/**
|
50
|
-
@static
|
51
|
-
@type String
|
52
|
-
@constant
|
53
|
-
*/
|
54
|
-
SC.SWIPE_UP = "UP";
|
55
|
-
|
56
|
-
/**
|
57
|
-
@static
|
58
|
-
@type String
|
59
|
-
@constant
|
60
|
-
*/
|
61
|
-
SC.SWIPE_DOWN = "DOWN";
|
62
|
-
|
63
|
-
/**
|
64
|
-
@class
|
65
|
-
@extends SC.Gesture
|
66
|
-
*/
|
67
|
-
SC.SwipeGesture = SC.Gesture.extend(
|
68
|
-
/** @scope SC.SwipeGesture.prototype */ {
|
69
|
-
|
70
|
-
/**
|
71
|
-
@type String
|
72
|
-
@default "swipe"
|
73
|
-
@readOnly
|
74
|
-
*/
|
75
|
-
name: "swipe",
|
76
|
-
|
77
|
-
/**
|
78
|
-
@type Boolean
|
79
|
-
@default YES
|
80
|
-
@readOnly
|
81
|
-
*/
|
82
|
-
acceptsMultitouch: YES,
|
83
|
-
|
84
|
-
/**
|
85
|
-
@type String
|
86
|
-
@default SC.SWIPE_HORIZONTAL
|
87
|
-
*/
|
88
|
-
direction: SC.SWIPE_HORIZONTAL,
|
89
|
-
|
90
|
-
/**
|
91
|
-
Will be populated with the current direction of the swipe once
|
92
|
-
one has been determined.
|
93
|
-
|
94
|
-
@type String
|
95
|
-
@default null
|
96
|
-
*/
|
97
|
-
currentDirection: null,
|
98
|
-
|
99
|
-
/**
|
100
|
-
@type Number
|
101
|
-
@default 5
|
102
|
-
*/
|
103
|
-
startDistance: 5,
|
104
|
-
|
105
|
-
/**
|
106
|
-
@type Number
|
107
|
-
@default 40
|
108
|
-
*/
|
109
|
-
swipeDistance: 40,
|
110
|
-
|
111
|
-
/**
|
112
|
-
Amount of distance in the other direction to consider it a swipe
|
113
|
-
|
114
|
-
@type Number
|
115
|
-
@default 0.5
|
116
|
-
*/
|
117
|
-
tolerance: 0.5,
|
118
|
-
|
119
|
-
/** @private */
|
120
|
-
touchIsInGesture: function(touch, status) {
|
121
|
-
// if we have not "flunked" the touch before, and it has moved
|
122
|
-
if (!status.flunked) {
|
123
|
-
var d = this.get('direction'),
|
124
|
-
cd = this.get('currentDirection'),
|
125
|
-
startDistance = this.get('startDistance'),
|
126
|
-
deltaX = touch.pageX - touch.startX,
|
127
|
-
deltaY = touch.pageY - touch.startY,
|
128
|
-
absX = Math.abs(deltaX),
|
129
|
-
absY = Math.abs(deltaY);
|
130
|
-
|
131
|
-
if (Math.abs(deltaX) > startDistance || Math.abs(deltaY) > startDistance) {
|
132
|
-
|
133
|
-
if (!cd) {
|
134
|
-
if (d == SC.SWIPE_ANY) {
|
135
|
-
if (absX > absY) cd = SC.SWIPE_HORIZONTAL;
|
136
|
-
else if (absY > absX) cd = SC.SWIPE_VERTICAL;
|
137
|
-
else return NO; // We can't determine a direction yet
|
138
|
-
} else {
|
139
|
-
cd = d;
|
140
|
-
}
|
141
|
-
this.set('currentDirection', cd);
|
142
|
-
}
|
143
|
-
|
144
|
-
var delta = (cd == SC.SWIPE_HORIZONTAL) ? deltaX : deltaY,
|
145
|
-
oDelta = (cd == SC.SWIPE_HORIZONTAL) ? deltaY : deltaX;
|
146
|
-
|
147
|
-
if (Math.abs(delta) * this.get("tolerance") > Math.abs(oDelta)) {
|
148
|
-
return YES;
|
149
|
-
}
|
150
|
-
|
151
|
-
}
|
152
|
-
}
|
153
|
-
return NO;
|
154
|
-
},
|
155
|
-
|
156
|
-
/** @private */
|
157
|
-
touchStart: function(touch) {
|
158
|
-
var d = this.get("currentDirection"),
|
159
|
-
delta = touch["page" + d] - touch["start" + d],
|
160
|
-
swipeDirection;
|
161
|
-
|
162
|
-
if (delta < 0) swipeDirection = (d === SC.SWIPE_HORIZONTAL) ? SC.SWIPE_LEFT : SC.SWIPE_UP;
|
163
|
-
else swipeDirection = (d === SC.SWIPE_HORIZONTAL) ? SC.SWIPE_RIGHT : SC.SWIPE_DOWN;
|
164
|
-
|
165
|
-
this.start(touch, swipeDirection, delta);
|
166
|
-
return YES;
|
167
|
-
},
|
168
|
-
|
169
|
-
/** @private */
|
170
|
-
touchesDragged: function(evt, touches) {
|
171
|
-
var touch = touches.firstObject();
|
172
|
-
var d = this.get("currentDirection"),
|
173
|
-
o = (d === SC.SWIPE_HORIZONTAL ? "Y" : "X"),
|
174
|
-
delta = touch["page" + d] - touch["start" + d],
|
175
|
-
oDelta = touch["page" + o] - touch["start" + o],
|
176
|
-
swipeDirection;
|
177
|
-
|
178
|
-
if (delta < 0) swipeDirection = (d === SC.SWIPE_HORIZONTAL) ? SC.SWIPE_LEFT : SC.SWIPE_UP;
|
179
|
-
else swipeDirection = (d === SC.SWIPE_HORIZONTAL) ? SC.SWIPE_RIGHT : SC.SWIPE_DOWN;
|
180
|
-
|
181
|
-
if (
|
182
|
-
Math.abs(delta) < this.get("startDistance") ||
|
183
|
-
Math.abs(delta) * this.get("tolerance") < Math.abs(oDelta)
|
184
|
-
) {
|
185
|
-
// does not qualify anymore
|
186
|
-
this.release(touch);
|
187
|
-
|
188
|
-
var allTouches = touch.touchesForResponder(this);
|
189
|
-
if (!allTouches || allTouches.length === 0) this.cancel(touch, swipeDirection, delta);
|
190
|
-
} else {
|
191
|
-
this.change(touch, swipeDirection, delta);
|
192
|
-
}
|
193
|
-
},
|
194
|
-
|
195
|
-
/** @private */
|
196
|
-
touchEnd: function(touch) {
|
197
|
-
var d = this.get("currentDirection"),
|
198
|
-
o = (d === SC.SWIPE_HORIZONTAL ? "Y" : "X"),
|
199
|
-
delta = touch["page" + d] - touch["start" + d],
|
200
|
-
oDelta = touch["page" + o] - touch["start" + o],
|
201
|
-
swipeDirection;
|
202
|
-
|
203
|
-
// determine swipe direction
|
204
|
-
if (delta < 0) swipeDirection = (d === SC.SWIPE_HORIZONTAL) ? SC.SWIPE_LEFT : SC.SWIPE_UP;
|
205
|
-
else swipeDirection = (d === SC.SWIPE_HORIZONTAL) ? SC.SWIPE_RIGHT : SC.SWIPE_DOWN;
|
206
|
-
|
207
|
-
// trigger
|
208
|
-
if (
|
209
|
-
Math.abs(delta) > this.get("swipeDistance") ||
|
210
|
-
Math.abs(delta) * this.get("tolerance") < Math.abs(oDelta)
|
211
|
-
) {
|
212
|
-
this.trigger(touch, swipeDirection);
|
213
|
-
}
|
214
|
-
|
215
|
-
this.end(touch, swipeDirection, delta);
|
216
|
-
|
217
|
-
this.set('currentDirection', null);
|
218
|
-
|
219
|
-
// and release all others
|
220
|
-
var touches = touch.touchesForResponder(this);
|
221
|
-
if (touches) {
|
222
|
-
touches.forEach(function(touch){
|
223
|
-
this.release(touch);
|
224
|
-
}, this);
|
225
|
-
}
|
226
|
-
},
|
227
|
-
|
228
|
-
/** @private */
|
229
|
-
cancel: function(){
|
230
|
-
sc_super();
|
231
|
-
this.set('currentDirection', null);
|
232
|
-
}
|
233
|
-
|
234
|
-
});
|
@@ -1,157 +0,0 @@
|
|
1
|
-
// ==========================================================================
|
2
|
-
// Project: SproutCore - JavaScript Application Framework
|
3
|
-
// Copyright: ©2010 Strobe Inc. All rights reserved.
|
4
|
-
// Author: Peter Wagenet
|
5
|
-
// License: Licensed under MIT license (see license.js)
|
6
|
-
// ==========================================================================
|
7
|
-
|
8
|
-
sc_require("system/gesture");
|
9
|
-
|
10
|
-
/**
|
11
|
-
@class
|
12
|
-
@extends SC.Gesture
|
13
|
-
*/
|
14
|
-
SC.TapGesture = SC.Gesture.extend(
|
15
|
-
/** @scope SC.TapGesture.prototype */{
|
16
|
-
|
17
|
-
/**
|
18
|
-
@type String
|
19
|
-
@default "tap"
|
20
|
-
@readOnly
|
21
|
-
*/
|
22
|
-
name: "tap",
|
23
|
-
|
24
|
-
/**
|
25
|
-
@type Boolean
|
26
|
-
@default NO
|
27
|
-
@readOnly
|
28
|
-
*/
|
29
|
-
acceptsMultitouch: NO,
|
30
|
-
|
31
|
-
/** @private */
|
32
|
-
_tapCount: null,
|
33
|
-
|
34
|
-
/** @private */
|
35
|
-
_candidateTouch: null,
|
36
|
-
|
37
|
-
/** @private */
|
38
|
-
_eventTimer: null,
|
39
|
-
|
40
|
-
/**
|
41
|
-
@type Number
|
42
|
-
@default 20
|
43
|
-
*/
|
44
|
-
tapWiggle: 10,
|
45
|
-
|
46
|
-
/**
|
47
|
-
@type Number
|
48
|
-
@default 200
|
49
|
-
*/
|
50
|
-
tapDelay: 200,
|
51
|
-
|
52
|
-
/** @private */
|
53
|
-
touchIsInGesture: function(touch, status) {
|
54
|
-
return !touch.tapFlunked;
|
55
|
-
},
|
56
|
-
|
57
|
-
/** @private */
|
58
|
-
touchStart: function(touch) {
|
59
|
-
// We don't want events triggering during a touch, will be reset when touch is over if it's a candidate
|
60
|
-
if (this._eventTimer) this._eventTimer.invalidate();
|
61
|
-
|
62
|
-
// We have an activeTap but another touch has been started
|
63
|
-
if (this._candidateTouch && this._candidateTouch.touch.identifier !== touch.identifier) {
|
64
|
-
this._cancelTap(touch);
|
65
|
-
return NO;
|
66
|
-
}
|
67
|
-
|
68
|
-
// This touch is a candidate
|
69
|
-
this._candidateTouch = {
|
70
|
-
startTime: Date.now(),
|
71
|
-
touch: touch
|
72
|
-
};
|
73
|
-
|
74
|
-
this.start(touch);
|
75
|
-
|
76
|
-
return YES;
|
77
|
-
},
|
78
|
-
|
79
|
-
/** @private */
|
80
|
-
touchesDragged: function(evt, touches) {
|
81
|
-
var touch = touches[0];
|
82
|
-
|
83
|
-
// Somehow another touch got in
|
84
|
-
var tooManyTouches = (
|
85
|
-
touches.length > 1 ||
|
86
|
-
!this._candidateTouch ||
|
87
|
-
touch.identifier !== this._candidateTouch.touch.identifier
|
88
|
-
);
|
89
|
-
|
90
|
-
// Touch moved too much
|
91
|
-
var touchMoved = this._calculateDragDistance(touch) > this.get('tapWiggle');
|
92
|
-
|
93
|
-
if (tooManyTouches || touchMoved) this._cancelTap(touch);
|
94
|
-
},
|
95
|
-
|
96
|
-
/** @private */
|
97
|
-
touchEnd: function(touch){
|
98
|
-
if (this._calculateDragDistance(touch) > this.get('tapWiggle') || Date.now() - this._candidateTouch.startTime > this.get('tapDelay') ) {
|
99
|
-
// Touch moved too much or took too long
|
100
|
-
this._cancelTap(touch);
|
101
|
-
} else {
|
102
|
-
this._addTap(touch);
|
103
|
-
}
|
104
|
-
},
|
105
|
-
|
106
|
-
/** @private */
|
107
|
-
_addTap: function(touch){
|
108
|
-
var self = this;
|
109
|
-
|
110
|
-
if (this._eventTimer) this._eventTimer.invalidate();
|
111
|
-
|
112
|
-
this._tapCount = (this._tapCount || 0) + 1;
|
113
|
-
this._candidateTouch = null;
|
114
|
-
this._eventTimer = SC.Timer.schedule({
|
115
|
-
target: self,
|
116
|
-
action: function(){ this._triggerTap(touch); },
|
117
|
-
interval: this.get('tapDelay')
|
118
|
-
});
|
119
|
-
|
120
|
-
this.change(touch, this._tapCount);
|
121
|
-
this.trigger(touch, this._tapCount);
|
122
|
-
|
123
|
-
},
|
124
|
-
|
125
|
-
/** @private */
|
126
|
-
_cancelTap: function(touch){
|
127
|
-
// We don't set this on the touchStatus because the status is
|
128
|
-
// linked to an individual view/gesture and we want this to be
|
129
|
-
// global. If it's not a tap somewhere, it's not a tap anywhere.
|
130
|
-
touch.tapFlunked = YES;
|
131
|
-
|
132
|
-
this.release(touch);
|
133
|
-
this.cancel(touch, this._tapCount);
|
134
|
-
|
135
|
-
if (this._eventTimer) this._eventTimer.invalidate();
|
136
|
-
this._tapCount = null;
|
137
|
-
this._candidateTouch = null;
|
138
|
-
this._eventTimer = null;
|
139
|
-
|
140
|
-
},
|
141
|
-
|
142
|
-
/** @private */
|
143
|
-
_triggerTap: function(touch){
|
144
|
-
this.end(touch, this._tapCount);
|
145
|
-
|
146
|
-
this._tapCount = null;
|
147
|
-
this._candidateTouch = null;
|
148
|
-
this._eventTimer = null;
|
149
|
-
},
|
150
|
-
|
151
|
-
/** @private */
|
152
|
-
_calculateDragDistance: function(touch) {
|
153
|
-
return Math.sqrt(Math.pow(touch.pageX - touch.startX, 2) + Math.pow(touch.pageY - touch.startY, 2));
|
154
|
-
}
|
155
|
-
|
156
|
-
});
|
157
|
-
|