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
@@ -232,34 +232,38 @@ SC.mixin(SC.String, {
|
|
232
232
|
@returns {String} the plural form of the string
|
233
233
|
*/
|
234
234
|
pluralize: function(str) {
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
compare =
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
235
|
+
var inflectionConstants = SC.Locale.currentLocale.inflectionConstants;
|
236
|
+
|
237
|
+
// Fast path if there is no inflection constants for a locale
|
238
|
+
if (!inflectionConstants) return str.toString();
|
239
|
+
|
240
|
+
var idx, len,
|
241
|
+
compare = str.split(/\s/).pop(), //check only the last word of a string
|
242
|
+
restOfString = str.replace(compare,''),
|
243
|
+
isCapitalized = compare.charAt(0).match(/[A-Z]/) ? true : false;
|
244
|
+
|
245
|
+
compare = compare.toLowerCase();
|
246
|
+
for (idx=0, len=inflectionConstants.UNCOUNTABLE.length; idx < len; idx++) {
|
247
|
+
var uncountable = inflectionConstants.UNCOUNTABLE[idx];
|
248
|
+
if (compare == uncountable) {
|
249
|
+
return str.toString();
|
247
250
|
}
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
251
|
+
}
|
252
|
+
for (idx=0, len=inflectionConstants.IRREGULAR.length; idx < len; idx++) {
|
253
|
+
var singular = inflectionConstants.IRREGULAR[idx][0],
|
254
|
+
plural = inflectionConstants.IRREGULAR[idx][1];
|
255
|
+
if ((compare == singular) || (compare == plural)) {
|
256
|
+
if(isCapitalized) plural = plural.capitalize();
|
257
|
+
return restOfString + plural;
|
255
258
|
}
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
259
|
+
}
|
260
|
+
for (idx=0, len=inflectionConstants.PLURAL.length; idx < len; idx++) {
|
261
|
+
var regex = inflectionConstants.PLURAL[idx][0],
|
262
|
+
replace_string = inflectionConstants.PLURAL[idx][1];
|
263
|
+
if (regex.test(compare)) {
|
264
|
+
return str.replace(regex, replace_string);
|
262
265
|
}
|
266
|
+
}
|
263
267
|
},
|
264
268
|
|
265
269
|
/**
|
@@ -269,34 +273,38 @@ SC.mixin(SC.String, {
|
|
269
273
|
@returns {String} the singular form of the string
|
270
274
|
*/
|
271
275
|
singularize: function(str) {
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
compare =
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
276
|
+
var inflectionConstants = SC.Locale.currentLocale.inflectionConstants;
|
277
|
+
|
278
|
+
// Fast path if there is no inflection constants for a locale
|
279
|
+
if (!inflectionConstants) return str.toString();
|
280
|
+
|
281
|
+
var idx, len,
|
282
|
+
compare = str.split(/\s/).pop(), //check only the last word of a string
|
283
|
+
restOfString = str.replace(compare,''),
|
284
|
+
isCapitalized = compare.charAt(0).match(/[A-Z]/) ? true : false;
|
285
|
+
|
286
|
+
compare = compare.toLowerCase();
|
287
|
+
for (idx=0, len=inflectionConstants.UNCOUNTABLE.length; idx < len; idx++) {
|
288
|
+
var uncountable = inflectionConstants.UNCOUNTABLE[idx];
|
289
|
+
if (compare == uncountable) {
|
290
|
+
return str.toString();
|
284
291
|
}
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
+
}
|
293
|
+
for (idx=0, len=inflectionConstants.IRREGULAR.length; idx < len; idx++) {
|
294
|
+
var singular = inflectionConstants.IRREGULAR[idx][0],
|
295
|
+
plural = inflectionConstants.IRREGULAR[idx][1];
|
296
|
+
if ((compare == singular) || (compare == plural)) {
|
297
|
+
if(isCapitalized) singular = singular.capitalize();
|
298
|
+
return restOfString + singular;
|
292
299
|
}
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
300
|
+
}
|
301
|
+
for (idx=0, len=inflectionConstants.SINGULAR.length; idx < len; idx++) {
|
302
|
+
var regex = inflectionConstants.SINGULAR[idx][0],
|
303
|
+
replace_string = inflectionConstants.SINGULAR[idx][1];
|
304
|
+
if (regex.test(compare)) {
|
305
|
+
return str.replace(regex, replace_string);
|
299
306
|
}
|
307
|
+
}
|
300
308
|
}
|
301
309
|
|
302
310
|
});
|
@@ -114,7 +114,7 @@ SC.mixin( /** @scope SC */ {
|
|
114
114
|
@param classNames {String} (Optional) Class names to add to the test element.
|
115
115
|
*/
|
116
116
|
prepareStringMeasurement: function(exampleElement, classNames) {
|
117
|
-
var element = this._metricsCalculationElement, classes,
|
117
|
+
var element = this._metricsCalculationElement, classes, style,
|
118
118
|
cqElem;
|
119
119
|
|
120
120
|
// collect the class names
|
@@ -0,0 +1,321 @@
|
|
1
|
+
// ==========================================================================
|
2
|
+
// Project: SproutCore
|
3
|
+
// License: Licensed under MIT license
|
4
|
+
// ==========================================================================
|
5
|
+
/*globals CoreTest, module, test, ok, equals, same, expect, start, stop */
|
6
|
+
|
7
|
+
var gesture;
|
8
|
+
module("SC.PinchGesture", {
|
9
|
+
|
10
|
+
setup: function () {
|
11
|
+
gesture = SC.PinchGesture;
|
12
|
+
},
|
13
|
+
|
14
|
+
teardown: function () {
|
15
|
+
if (gesture.destroy) { gesture.destroy(); }
|
16
|
+
gesture = null;
|
17
|
+
}
|
18
|
+
});
|
19
|
+
|
20
|
+
/* Properties */
|
21
|
+
|
22
|
+
test("Default Properties:", function () {
|
23
|
+
gesture = gesture.create();
|
24
|
+
equals(gesture.name, 'pinch', "The default value of name is");
|
25
|
+
});
|
26
|
+
|
27
|
+
/* Methods */
|
28
|
+
|
29
|
+
// This method registers _sc_pinchAnchorScale to the value of the view's scale.
|
30
|
+
test("Method: touchSessionStarted", function () {
|
31
|
+
gesture = gesture.create({
|
32
|
+
view: SC.View.create({ layout: { scale: 1.5 } })
|
33
|
+
});
|
34
|
+
equals(gesture.touchSessionStarted(), undefined, "The method returns");
|
35
|
+
|
36
|
+
equals(gesture._sc_pinchAnchorScale, 1.5, "The value of _sc_pinchAnchorScale has been set to");
|
37
|
+
});
|
38
|
+
|
39
|
+
// This method registers _sc_pinchAnchorD as the average distance between all touches.
|
40
|
+
test("Method: touchAddedToSession", function () {
|
41
|
+
var view = SC.View.create({ });
|
42
|
+
|
43
|
+
gesture = gesture.create({
|
44
|
+
view: view
|
45
|
+
});
|
46
|
+
|
47
|
+
var testTouch1 = SC.Touch.create({
|
48
|
+
identifier: 'test-touch-1',
|
49
|
+
pageX: 0,
|
50
|
+
pageY: 0
|
51
|
+
}, SC.RootResponder.responder),
|
52
|
+
|
53
|
+
testTouch2 = SC.Touch.create({
|
54
|
+
identifier: 'test-touch-2',
|
55
|
+
pageX: 100,
|
56
|
+
pageY: 100
|
57
|
+
}, SC.RootResponder.responder),
|
58
|
+
|
59
|
+
testTouch3 = SC.Touch.create({
|
60
|
+
identifier: 'test-touch-3',
|
61
|
+
pageX: 200,
|
62
|
+
pageY: 200
|
63
|
+
}, SC.RootResponder.responder);
|
64
|
+
|
65
|
+
// Set up root responder nonsense.
|
66
|
+
SC.RootResponder.responder._touchedViews[SC.guidFor(view)] = {
|
67
|
+
touches: SC.CoreSet.create([testTouch1])
|
68
|
+
};
|
69
|
+
|
70
|
+
equals(gesture.touchAddedToSession(testTouch2, [testTouch1]), true, "The method returns");
|
71
|
+
equals(gesture._sc_pinchAnchorD.toFixed(1), '70.7', "The variable _sc_pinchAnchorD is");
|
72
|
+
|
73
|
+
gesture.touchAddedToSession(testTouch3, [testTouch2, testTouch1]);
|
74
|
+
equals(gesture._sc_pinchAnchorD.toFixed(1), '141.4', "The variable _sc_pinchAnchorD is now");
|
75
|
+
});
|
76
|
+
|
77
|
+
// This method updates the anchors to the new fewer number of touches. If only one touch remains it nulls out the anchors.
|
78
|
+
test("Method: touchCancelledInSession", function () {
|
79
|
+
var view = SC.View.create({});
|
80
|
+
|
81
|
+
gesture = gesture.create({
|
82
|
+
view: view
|
83
|
+
});
|
84
|
+
|
85
|
+
var testTouch1 = SC.Touch.create({
|
86
|
+
identifier: 'test-touch-1',
|
87
|
+
pageX: 0,
|
88
|
+
pageY: 0
|
89
|
+
}, SC.RootResponder.responder),
|
90
|
+
|
91
|
+
testTouch2 = SC.Touch.create({
|
92
|
+
identifier: 'test-touch-2',
|
93
|
+
pageX: 100,
|
94
|
+
pageY: 100
|
95
|
+
}, SC.RootResponder.responder),
|
96
|
+
|
97
|
+
testTouch3 = SC.Touch.create({
|
98
|
+
identifier: 'test-touch-3',
|
99
|
+
pageX: 200,
|
100
|
+
pageY: 200
|
101
|
+
}, SC.RootResponder.responder);
|
102
|
+
|
103
|
+
// Set up root responder nonsense.
|
104
|
+
SC.RootResponder.responder._touchedViews[SC.guidFor(view)] = {
|
105
|
+
touches: SC.CoreSet.create([testTouch1, testTouch2])
|
106
|
+
};
|
107
|
+
|
108
|
+
equals(gesture.touchCancelledInSession(testTouch3, [testTouch1, testTouch2]), true, "The method returns");
|
109
|
+
equals(gesture._sc_pinchAnchorD.toFixed(1), '70.7', "The variable _sc_pinchAnchorD is now");
|
110
|
+
|
111
|
+
// Also check that an active pinch is killed. Fake out an active pinch.
|
112
|
+
gesture._sc_isPinching = true;
|
113
|
+
gesture._sc_pinchingTimer = SC.Timer.schedule({
|
114
|
+
interval: 100
|
115
|
+
});
|
116
|
+
|
117
|
+
gesture.touchCancelledInSession(testTouch2, [testTouch1]);
|
118
|
+
equals(gesture._sc_pinchAnchorD, null, "The variable _sc_pinchAnchorD is finally");
|
119
|
+
equals(gesture._sc_isPinching, false, "The variable _sc_isPinching is now");
|
120
|
+
|
121
|
+
gesture.touchCancelledInSession(testTouch1, []);
|
122
|
+
equals(gesture._sc_pinchAnchorD, null, "The variable _sc_pinchAnchorD is still");
|
123
|
+
});
|
124
|
+
|
125
|
+
// This method updates the anchors to the new fewer number of touches. If only one touch remains it nulls out the anchors and cancels any active pinch.
|
126
|
+
test("Method: touchEndedInSession", function () {
|
127
|
+
var view = SC.View.create(SC.Gesturable, {
|
128
|
+
gestures: [SC.PinchGesture],
|
129
|
+
|
130
|
+
pinchEnd: function () {
|
131
|
+
ok(true, 'called', 'called', "The pinchEnd method was");
|
132
|
+
}
|
133
|
+
});
|
134
|
+
|
135
|
+
gesture = gesture.create({
|
136
|
+
view: view
|
137
|
+
});
|
138
|
+
|
139
|
+
var testTouch1 = SC.Touch.create({
|
140
|
+
identifier: 'test-touch-1',
|
141
|
+
pageX: 0,
|
142
|
+
pageY: 0
|
143
|
+
}, SC.RootResponder.responder),
|
144
|
+
|
145
|
+
testTouch2 = SC.Touch.create({
|
146
|
+
identifier: 'test-touch-2',
|
147
|
+
pageX: 100,
|
148
|
+
pageY: 100
|
149
|
+
}, SC.RootResponder.responder),
|
150
|
+
|
151
|
+
testTouch3 = SC.Touch.create({
|
152
|
+
identifier: 'test-touch-3',
|
153
|
+
pageX: 200,
|
154
|
+
pageY: 200
|
155
|
+
}, SC.RootResponder.responder);
|
156
|
+
|
157
|
+
// Set up root responder nonsense.
|
158
|
+
SC.RootResponder.responder._touchedViews[SC.guidFor(view)] = {
|
159
|
+
touches: SC.CoreSet.create([testTouch1, testTouch2])
|
160
|
+
};
|
161
|
+
|
162
|
+
equals(gesture.touchEndedInSession(testTouch3, [testTouch1, testTouch2]), true, "The method returns");
|
163
|
+
equals(gesture._sc_pinchAnchorD.toFixed(1), '70.7', "The variable _sc_pinchAnchorD is now");
|
164
|
+
|
165
|
+
// Also check that an active pinch is killed. Fake out an active pinch.
|
166
|
+
gesture._sc_isPinching = true;
|
167
|
+
gesture._sc_pinchingTimer = SC.Timer.schedule({
|
168
|
+
interval: 100
|
169
|
+
});
|
170
|
+
|
171
|
+
gesture.touchEndedInSession(testTouch2, [testTouch1]);
|
172
|
+
equals(gesture._sc_pinchAnchorD, null, "The variable _sc_pinchAnchorD is finally");
|
173
|
+
equals(gesture._sc_isPinching, false, "The variable _sc_isPinching is now");
|
174
|
+
|
175
|
+
gesture.touchCancelledInSession(testTouch1, []);
|
176
|
+
equals(gesture._sc_pinchAnchorD, null, "The variable _sc_pinchAnchorD is still");
|
177
|
+
});
|
178
|
+
|
179
|
+
// This method calls `pinchStart` once as long as still moving. It also calls `pinch` with the scale each time the average touch distance changes. Once enough time has passed, calls `pinchEnd` (via timer).
|
180
|
+
test("Method: touchesMovedInSession", function () {
|
181
|
+
var lastScale = 1,
|
182
|
+
view = SC.View.create(SC.Gesturable, {
|
183
|
+
gestures: [SC.PinchGesture],
|
184
|
+
|
185
|
+
pinchStart: function () {
|
186
|
+
ok(true, 'called', 'called', "The pinchStart method was");
|
187
|
+
},
|
188
|
+
|
189
|
+
pinch: function (scale) {
|
190
|
+
ok(true, 'called', 'called', "The pinch method was");
|
191
|
+
ok(scale < lastScale, 'changed', 'changed', "The scale (%@) has".fmt(scale));
|
192
|
+
lastScale = scale;
|
193
|
+
},
|
194
|
+
|
195
|
+
pinchEnd: function () {
|
196
|
+
ok(true, 'called', 'called', "The pinchEnd method was");
|
197
|
+
}
|
198
|
+
});
|
199
|
+
|
200
|
+
gesture = gesture.create({
|
201
|
+
view: view
|
202
|
+
});
|
203
|
+
|
204
|
+
var testTouch1 = SC.Touch.create({
|
205
|
+
identifier: 'test-touch-1',
|
206
|
+
pageX: 0,
|
207
|
+
pageY: 0
|
208
|
+
}, SC.RootResponder.responder),
|
209
|
+
|
210
|
+
testTouch2 = SC.Touch.create({
|
211
|
+
identifier: 'test-touch-2',
|
212
|
+
pageX: 100,
|
213
|
+
pageY: 100
|
214
|
+
}, SC.RootResponder.responder);
|
215
|
+
|
216
|
+
// Set up root responder nonsense.
|
217
|
+
SC.RootResponder.responder._touchedViews[SC.guidFor(view)] = {
|
218
|
+
touches: SC.CoreSet.create([testTouch1, testTouch2])
|
219
|
+
};
|
220
|
+
|
221
|
+
// Set up the initial touch distance and view scale.
|
222
|
+
gesture._sc_pinchAnchorD = 70.7;
|
223
|
+
gesture._sc_pinchAnchorScale = 1;
|
224
|
+
|
225
|
+
// Move a touch.
|
226
|
+
testTouch2.pageX = 99;
|
227
|
+
testTouch2.pageY = 99;
|
228
|
+
|
229
|
+
equals(gesture.touchesMovedInSession([testTouch1, testTouch2]), true, "The method returns");
|
230
|
+
|
231
|
+
// Should include the pinchStart ok().
|
232
|
+
expect(4);
|
233
|
+
|
234
|
+
// Move a touch.
|
235
|
+
testTouch2.pageX = 98;
|
236
|
+
testTouch2.pageY = 98;
|
237
|
+
gesture.touchesMovedInSession([testTouch1, testTouch2]);
|
238
|
+
|
239
|
+
// Should only include the pinch ok's.
|
240
|
+
expect(6);
|
241
|
+
|
242
|
+
setTimeout(function () {
|
243
|
+
expect(7);
|
244
|
+
start();
|
245
|
+
}, gesture.get('pinchDelay') + 200);
|
246
|
+
|
247
|
+
// Don't continue to the next test.
|
248
|
+
stop();
|
249
|
+
});
|
250
|
+
|
251
|
+
// This method clears out all variables and cancels an active pinch.
|
252
|
+
test("Method: touchSessionCancelled", function () {
|
253
|
+
var view = SC.View.create({});
|
254
|
+
|
255
|
+
gesture = gesture.create({
|
256
|
+
view: view
|
257
|
+
});
|
258
|
+
|
259
|
+
var testTouch1 = SC.Touch.create({
|
260
|
+
identifier: 'test-touch-1',
|
261
|
+
pageX: 0,
|
262
|
+
pageY: 0
|
263
|
+
}, SC.RootResponder.responder),
|
264
|
+
|
265
|
+
testTouch2 = SC.Touch.create({
|
266
|
+
identifier: 'test-touch-2',
|
267
|
+
pageX: 100,
|
268
|
+
pageY: 100
|
269
|
+
}, SC.RootResponder.responder);
|
270
|
+
|
271
|
+
// Set up root responder nonsense.
|
272
|
+
SC.RootResponder.responder._touchedViews[SC.guidFor(view)] = {
|
273
|
+
touches: SC.CoreSet.create([testTouch1, testTouch2])
|
274
|
+
};
|
275
|
+
|
276
|
+
// Also check that an active pinch is killed. Fake out an active pinch.
|
277
|
+
gesture._sc_isPinching = true;
|
278
|
+
gesture._sc_pinchingTimer = SC.Timer.schedule({
|
279
|
+
interval: 100
|
280
|
+
});
|
281
|
+
|
282
|
+
equals(gesture.touchSessionCancelled(), undefined, "The method returns");
|
283
|
+
equals(gesture._sc_pinchAnchorD, null, "The variable _sc_pinchAnchorD is now");
|
284
|
+
equals(gesture._sc_isPinching, false, "The variable _sc_isPinching is now");
|
285
|
+
});
|
286
|
+
|
287
|
+
// This method clears out all variables and cancels an active pinch.
|
288
|
+
test("Method: touchSessionEnded", function () {
|
289
|
+
var view = SC.View.create({});
|
290
|
+
|
291
|
+
gesture = gesture.create({
|
292
|
+
view: view
|
293
|
+
});
|
294
|
+
|
295
|
+
var testTouch1 = SC.Touch.create({
|
296
|
+
identifier: 'test-touch-1',
|
297
|
+
pageX: 0,
|
298
|
+
pageY: 0
|
299
|
+
}, SC.RootResponder.responder),
|
300
|
+
|
301
|
+
testTouch2 = SC.Touch.create({
|
302
|
+
identifier: 'test-touch-2',
|
303
|
+
pageX: 100,
|
304
|
+
pageY: 100
|
305
|
+
}, SC.RootResponder.responder);
|
306
|
+
|
307
|
+
// Set up root responder nonsense.
|
308
|
+
SC.RootResponder.responder._touchedViews[SC.guidFor(view)] = {
|
309
|
+
touches: SC.CoreSet.create([testTouch1, testTouch2])
|
310
|
+
};
|
311
|
+
|
312
|
+
// Also check that an active pinch is killed. Fake out an active pinch.
|
313
|
+
gesture._sc_isPinching = true;
|
314
|
+
gesture._sc_pinchingTimer = SC.Timer.schedule({
|
315
|
+
interval: 100
|
316
|
+
});
|
317
|
+
|
318
|
+
equals(gesture.touchSessionCancelled(), undefined, "The method returns");
|
319
|
+
equals(gesture._sc_pinchAnchorD, null, "The variable _sc_pinchAnchorD is now");
|
320
|
+
equals(gesture._sc_isPinching, false, "The variable _sc_isPinching is now");
|
321
|
+
});
|