rasputin 0.9.1 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,4 @@
1
+ //=require sproutcore-utils
1
2
 
2
3
  (function(exports) {
3
4
  // ==========================================================================
@@ -1,328 +1,4 @@
1
-
2
- (function(exports) {
3
- // Vector and Matrix mathematics modules for JavaScript
4
- // Copyright (c) 2007 James Coglan
5
- //
6
- // Permission is hereby granted, free of charge, to any person obtaining
7
- // a copy of this software and associated documentation files (the "Software"),
8
- // to deal in the Software without restriction, including without limitation
9
- // the rights to use, copy, modify, merge, publish, distribute, sublicense,
10
- // and/or sell copies of the Software, and to permit persons to whom the
11
- // Software is furnished to do so, subject to the following conditions:
12
- //
13
- // The above copyright notice and this permission notice shall be included
14
- // in all copies or substantial portions of the Software.
15
- //
16
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17
- // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19
- // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
- // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22
- // DEALINGS IN THE SOFTWARE.
23
-
24
- var Sylvester = {
25
- version: '0.1.3',
26
- precision: 1e-6
27
- };
28
-
29
- function Matrix() {}
30
- Matrix.prototype = {
31
-
32
- // Returns element (i,j) of the matrix
33
- e: function(i,j) {
34
- if (i < 1 || i > this.elements.length || j < 1 || j > this.elements[0].length) { return null; }
35
- return this.elements[i-1][j-1];
36
- },
37
-
38
- // Maps the matrix to another matrix (of the same dimensions) according to the given function
39
- map: function(fn) {
40
- var els = [], ni = this.elements.length, ki = ni, i, nj, kj = this.elements[0].length, j;
41
- do { i = ki - ni;
42
- nj = kj;
43
- els[i] = [];
44
- do { j = kj - nj;
45
- els[i][j] = fn(this.elements[i][j], i + 1, j + 1);
46
- } while (--nj);
47
- } while (--ni);
48
- return Matrix.create(els);
49
- },
50
-
51
- // Returns the result of multiplying the matrix from the right by the argument.
52
- // If the argument is a scalar then just multiply all the elements. If the argument is
53
- // a vector, a vector is returned, which saves you having to remember calling
54
- // col(1) on the result.
55
- multiply: function(matrix) {
56
- if (!matrix.elements) {
57
- return this.map(function(x) { return x * matrix; });
58
- }
59
- var returnVector = matrix.modulus ? true : false;
60
- var M = matrix.elements || matrix;
61
- if (typeof(M[0][0]) == 'undefined') { M = Matrix.create(M).elements; }
62
- if (!this.canMultiplyFromLeft(M)) { return null; }
63
- var ni = this.elements.length, ki = ni, i, nj, kj = M[0].length, j;
64
- var cols = this.elements[0].length, elements = [], sum, nc, c;
65
- do { i = ki - ni;
66
- elements[i] = [];
67
- nj = kj;
68
- do { j = kj - nj;
69
- sum = 0;
70
- nc = cols;
71
- do { c = cols - nc;
72
- sum += this.elements[i][c] * M[c][j];
73
- } while (--nc);
74
- elements[i][j] = sum;
75
- } while (--nj);
76
- } while (--ni);
77
- var M = Matrix.create(elements);
78
- return returnVector ? M.col(1) : M;
79
- },
80
-
81
- x: function(matrix) { return this.multiply(matrix); },
82
-
83
- // Returns true iff the matrix can multiply the argument from the left
84
- canMultiplyFromLeft: function(matrix) {
85
- var M = matrix.elements || matrix;
86
- if (typeof(M[0][0]) == 'undefined') { M = Matrix.create(M).elements; }
87
- // this.columns should equal matrix.rows
88
- return (this.elements[0].length == M.length);
89
- },
90
-
91
- // Set the matrix's elements from an array. If the argument passed
92
- // is a vector, the resulting matrix will be a single column.
93
- setElements: function(els) {
94
- var i, elements = els.elements || els;
95
- if (typeof(elements[0][0]) != 'undefined') {
96
- var ni = elements.length, ki = ni, nj, kj, j;
97
- this.elements = [];
98
- do { i = ki - ni;
99
- nj = elements[i].length; kj = nj;
100
- this.elements[i] = [];
101
- do { j = kj - nj;
102
- this.elements[i][j] = elements[i][j];
103
- } while (--nj);
104
- } while(--ni);
105
- return this;
106
- }
107
- var n = elements.length, k = n;
108
- this.elements = [];
109
- do { i = k - n;
110
- this.elements.push([elements[i]]);
111
- } while (--n);
112
- return this;
113
- }
114
- };
115
-
116
- // Constructor function
117
- Matrix.create = function(elements) {
118
- var M = new Matrix();
119
- return M.setElements(elements);
120
- };
121
-
122
- // Utility functions
123
- $M = Matrix.create;
124
-
125
- })({});
126
-
127
-
128
- (function(exports) {
129
- // ==========================================================================
130
- // Project: AcceleratedEffects
131
- // Copyright: ©2011 Majd Taby
132
- // License: Licensed under MIT license (see license.js)
133
- // ==========================================================================
134
-
135
- (function($) {
136
- if ( !$.cssHooks ) {
137
- throw("jQuery 1.4.3+ is needed for this plugin to work");
138
- return;
139
- }
140
-
141
- function styleSupport( prop ) {
142
- var vendorProp, supportedProp,
143
-
144
- // capitalize first character of the prop to test vendor prefix
145
- capProp = prop.charAt(0).toUpperCase() + prop.slice(1),
146
- prefixes = [ "Moz", "Webkit", "O", "ms" ],
147
- div = document.createElement( "div" );
148
-
149
- if ( prop in div.style ) {
150
-
151
- // browser supports standard CSS property name
152
- supportedProp = prop;
153
- } else {
154
-
155
- // otherwise test support for vendor-prefixed property names
156
- for ( var i = 0; i < prefixes.length; i++ ) {
157
- vendorProp = prefixes[i] + capProp;
158
- if ( vendorProp in div.style ) {
159
- supportedProp = vendorProp;
160
- break;
161
- }
162
- }
163
- }
164
-
165
- // avoid memory leak in IE
166
- div = null;
167
-
168
- // add property to $.support so it can be accessed elsewhere
169
- $.support[ prop ] = supportedProp;
170
-
171
- return supportedProp;
172
- }
173
-
174
- var transformProperty = styleSupport('transform');
175
- console.log(transformProperty);
176
-
177
- var properties = {
178
- rotateX: {
179
- defaultValue: 0
180
- },
181
- rotateY: {
182
- defaultValue: 0
183
- },
184
- rotateZ: {
185
- defaultValue: 0
186
- },
187
- translateX: {
188
- defaultValue: 0
189
- },
190
- translateY: {
191
- defaultValue: 0
192
- },
193
- translateZ: {
194
- defaultValue: 0
195
- },
196
- scale: {
197
- defaultValue: 1
198
- }
199
- };
200
-
201
- var RotationXMatrix = function(a) {
202
- return $M([
203
- [1,0,0,0],
204
- [0,Math.cos(a), Math.sin(-a), 0],
205
- [0,Math.sin(a), Math.cos( a), 0],
206
- [0,0,0,1]
207
- ]);
208
- };
209
-
210
- var RotationYMatrix = function(b) {
211
- return $M([
212
- [Math.cos( b), 0, Math.sin(b),0],
213
- [0,1,0,0],
214
- [Math.sin(-b), 0, Math.cos(b), 0],
215
- [0,0,0,1]
216
- ]);
217
- };
218
-
219
- var RotationZMatrix = function(c) {
220
- return $M([
221
- [Math.cos(c), Math.sin(-c), 0, 0],
222
- [Math.sin(c), Math.cos( c), 0, 0],
223
- [0,0,1,0],
224
- [0,0,0,1]
225
- ]);
226
- };
227
-
228
- var TranslationMatrix = function(tx,ty,tz) {
229
- return $M([
230
- [1,0,0,0],
231
- [0,1,0,0],
232
- [0,0,1,0],
233
- [tx,ty,tz,1]
234
- ]);
235
- };
236
-
237
- var ScaleMatrix = function(s) {
238
- return $M([
239
- [s,0,0,0],
240
- [0,s,0,0],
241
- [0,0,s,0],
242
- [0,0,0,1]
243
- ]);
244
- };
245
-
246
- var applyMatrix = function(elem) {
247
- var transforms = $(elem).data('transforms');
248
-
249
- var rotX = transforms.rotateX || properties.rotateX.defaultValue,
250
- rotY = transforms.rotateY || properties.rotateY.defaultValue,
251
- rotZ = transforms.rotateZ || properties.rotateZ.defaultValue,
252
- scale = transforms.scale || properties.scale.defaultValue,
253
- translateX = transforms.translateX || properties.translateX.defaultValue,
254
- translateY = transforms.translateY || properties.translateY.defaultValue,
255
- translateZ = transforms.translateZ || properties.translateZ.defaultValue;
256
-
257
- var tM = RotationXMatrix(rotX)
258
- .x(RotationYMatrix(rotY))
259
- .x(RotationZMatrix(rotZ))
260
- .x(ScaleMatrix(scale))
261
- .x(TranslationMatrix(translateX,translateY,translateZ));
262
-
263
- s = "matrix3d(";
264
- s += tM.e(1,1).toFixed(10) + "," + tM.e(1,2).toFixed(10) + "," + tM.e(1,3).toFixed(10) + "," + tM.e(1,4).toFixed(10) + ",";
265
- s += tM.e(2,1).toFixed(10) + "," + tM.e(2,2).toFixed(10) + "," + tM.e(2,3).toFixed(10) + "," + tM.e(2,4).toFixed(10) + ",";
266
- s += tM.e(3,1).toFixed(10) + "," + tM.e(3,2).toFixed(10) + "," + tM.e(3,3).toFixed(10) + "," + tM.e(3,4).toFixed(10) + ",";
267
- s += tM.e(4,1).toFixed(10) + "," + tM.e(4,2).toFixed(10) + "," + tM.e(4,3).toFixed(10) + "," + tM.e(4,4).toFixed(10);
268
- s += ")";
269
-
270
- elem.style[transformProperty] = s;
271
- }
272
-
273
- var hookFor = function(name) {
274
-
275
- $.fx.step[name] = function(fx){
276
- $.cssHooks[name].set( fx.elem, fx.now + fx.unit );
277
- };
278
-
279
- return {
280
- get: function( elem, computed, extra ) {
281
- var transforms = $(elem).data('transforms');
282
- if (transforms === undefined) {
283
- transforms = {};
284
- $(elem).data('transforms',transforms);
285
- }
286
-
287
- return transforms[name] || properties[name].defaultValue;
288
- },
289
- set: function( elem, value) {
290
- var transforms = $(elem).data('transforms');
291
- if (transforms === undefined) transforms = {};
292
- var propInfo = properties[name];
293
-
294
- if (typeof propInfo.apply === 'function') {
295
- transforms[name] = propInfo.apply(transforms[name] || propInfo.defaultValue, value);
296
- } else {
297
- transforms[name] = value
298
- }
299
-
300
- $(elem).data('transforms',transforms);
301
- applyMatrix(elem);
302
- }
303
- }
304
- }
305
-
306
- if (transformProperty) {
307
- for (var name in properties) {
308
- $.cssHooks[name] = hookFor(name);
309
- $.cssNumber[name] = true;
310
- }
311
- }
312
-
313
- })(jQuery);
314
-
315
- })({});
316
-
317
-
318
- (function(exports) {
319
- // ==========================================================================
320
- // Project: AcceleratedEffects
321
- // Copyright: ©2011 Majd Taby
322
- // License: Licensed under MIT license (see license.js)
323
- // ==========================================================================
324
-
325
- })({});
1
+ //=require TransformJS
326
2
 
327
3
  (function(exports) {
328
4
  // ==========================================================================
@@ -712,8 +388,7 @@ var sigFigs = 100;
712
388
  management, and provides some utility methods and some required methods all
713
389
  gesture recognizers are expected to implement.
714
390
 
715
- Overview
716
- =========
391
+ ## Overview
717
392
 
718
393
  Gestures coalesce multiple touch events to a single higher-level gesture
719
394
  event. For example, a tap gesture recognizer takes information about a
@@ -724,27 +399,26 @@ var sigFigs = 100;
724
399
 
725
400
  Gesture events follow the format:
726
401
 
727
- * [GESTURE_NAME]Start - Sent when a gesture has gathered enough information
402
+ * *[GESTURE_NAME]* Start - Sent when a gesture has gathered enough information
728
403
  to begin tracking the gesture
729
404
 
730
- * [GESTURE_NAME]Change - Sent when a gesture has already started and has
405
+ * *[GESTURE_NAME]* Change - Sent when a gesture has already started and has
731
406
  received touchmove events that cause its state to change
732
407
 
733
- * [GESTURE_NAME]End - Sent when a touchend event is received and the gesture
408
+ * *[GESTURE_NAME]* End - Sent when a touchend event is received and the gesture
734
409
  recognizer decides that the gesture is finished.
735
410
 
736
- * [GESTURE_NAME]Cancel - Sent when a touchcancel event is received.
411
+ * *[GESTURE_NAME]* Cancel - Sent when a touchcancel event is received.
737
412
 
738
- There are two types of gesturess: Discrete and Continuous gestures. In contrast
413
+ There are two types of gestures: Discrete and Continuous gestures. In contrast
739
414
  to continuous gestures, discrete gestures don't have any change events. Rather,
740
- the start and end events are the only one that gets sent.
415
+ the end event is the only one that gets sent to the view.
741
416
 
742
- Usage
743
- =======
417
+ ## Usage
744
418
 
745
- While you wouldn't use SC.Gesture directly, all its subclasses have the same
746
- API. For example, to implement pinch on a view, you implement pinchChange and
747
- optionally pinchStart, pinchEnd and pinchCancel.
419
+ While you wouldn't use SC.Gesture directly, all its subclasses implement the
420
+ same API. For example, to implement pinch on a view, you implement one or more
421
+ of the pinch events. For example:
748
422
 
749
423
  var myView = SC.View.create({
750
424
  pinchStart: function(recognizer) {
@@ -753,7 +427,9 @@ var sigFigs = 100;
753
427
 
754
428
  pinchChange: function(recognizer) {
755
429
  var scale = recognizer.get('scale');
756
- this.$().css('-webkit-transform','scale3d('+scale+','+scale+',1)');
430
+ this.$().css('scale',function(index, value) {
431
+ return recognizer.get('scale') * value
432
+ });
757
433
  },
758
434
 
759
435
  pinchEnd: function(recognizer) {
@@ -769,8 +445,21 @@ var sigFigs = 100;
769
445
  gesture, but pinchChange() will get called repeatedly called every time
770
446
  one of the touches moves.
771
447
 
772
- Creating Custom Gesture Recognizers
773
- ======
448
+ ## Customizing Gesture Recognizers
449
+
450
+ Some of the gesture recognizers include properties that can be customized by
451
+ the user for a specific instance of a view. For example, a pan gesture defaults
452
+ to being a one-finger gesture, but in some scenarios, it must be defined as a
453
+ two-finger gesture. In that case, you can override defaults by specifying an
454
+ Options hash.
455
+
456
+ var myView = SC.View.create({
457
+ panOptions: {
458
+ numberOfRequiredTouches: 2
459
+ }
460
+ });
461
+
462
+ ## Creating Custom Gesture Recognizers
774
463
 
775
464
  SC.Gesture also defines an API which its subclasses can implement to build
776
465
  custom gestures. The methods are:
@@ -804,26 +493,22 @@ var sigFigs = 100;
804
493
 
805
494
  In all the callbacks, you can use the `touches` protected property to access the
806
495
  touches hash. The touches hash is keyed on the identifiers of the touches, and the
807
- values are the jQuery.Event objects.
808
-
809
- You can also use the numberOfActiveTouches property to inspect how many touches
810
- are active, this is mostly useful in shouldBegin since every other callback can
811
- assume that there are as many active touches as specified in the
496
+ values are the jQuery.Event objects. You can also access the length property to inspect
497
+ how many touches are active, this is mostly useful in shouldBegin since every other
498
+ callback can assume that there are as many active touches as specified in the
812
499
  numberOfRequiredTouches property.
813
500
 
814
- Discrete vs Continuous Gestures
815
- =======
501
+ ## Discrete vs Continuous Gestures
816
502
 
817
503
  There are two main classes of gesture recognizers: Discrete and Continuous
818
- gestures. Discrete gestures do not get Change events sent, since they represent
819
- a single, instantaneous event, rather than a continuous motion. If you are
820
- implementing your own discrete gesture recognizer, you must set the
821
- isDiscreteGesture property to yes, and SC.Gesture will adapt its behavior.
504
+ gestures. Discrete gestures do not get Start, Change nor Cancel events sent,
505
+ since they represent a single, instantaneous event, rather than a continuous
506
+ motion. If you are implementing your own discrete gesture recognizer, you must
507
+ set the isDiscreteGesture property to yes, and SC.Gesture will adapt its behavior.
822
508
 
823
509
  Discrete gestures use the shouldEnd callback to either accept or decline the gesture
824
- event. If it is delined, then the gesture will enter a Cancelled state and trigger
825
- the Cancel event on the view.
826
-
510
+ event. If it is declined, then the gesture will enter a Cancelled state.
511
+
827
512
  @extends SC.Object
828
513
  */
829
514
 
@@ -924,10 +609,14 @@ SC.Gesture = SC.Object.extend(
924
609
  // Utilities
925
610
 
926
611
  /** @private */
927
- attemptGestureEventDelivery: function(evt, view, eventName) {
612
+ attemptGestureEventDelivery: function(evt, view, eventName, stopPropagation) {
613
+ if (stopPropagation === undefined) {
614
+ var stopPropagation = true;
615
+ }
616
+
928
617
  if (this.notifyViewOfGestureEvent(view, eventName) === false) {
929
618
  this.eventWasRejected();
930
- } else {
619
+ } else if(stopPropagation) {
931
620
  evt.preventDefault();
932
621
  }
933
622
  },
@@ -1044,7 +733,6 @@ SC.Gesture = SC.Object.extend(
1044
733
  if (get(this, 'gestureIsDiscrete') && this.shouldBegin()) {
1045
734
  set(this, 'state', SC.Gesture.BEGAN);
1046
735
  this.didBegin();
1047
- this.attemptGestureEventDelivery(evt, view, get(this, 'name')+'Start');
1048
736
  } else {
1049
737
  set(this, 'state', SC.Gesture.POSSIBLE);
1050
738
  this.didBecomePossible();
@@ -1084,7 +772,7 @@ SC.Gesture = SC.Object.extend(
1084
772
  // updated information in the Start event
1085
773
  this.didChange();
1086
774
 
1087
- this.attemptGestureEventDelivery(evt, view, get(this, 'name')+'Start');
775
+ this.attemptGestureEventDelivery(evt, view, get(this, 'name')+'Start',(this.get('isDiscreteGesture'))? true: false);
1088
776
  }
1089
777
 
1090
778
  // Discrete gestures don't fire changed events
@@ -1116,7 +804,7 @@ SC.Gesture = SC.Object.extend(
1116
804
  }
1117
805
  }
1118
806
  else {
1119
- if (this.state !== SC.Gesture.ENDED && this.shouldEnd()) {
807
+ if ((this.state === SC.Gesture.BEGAN || this.state === SC.Gesture.CHANGED) && this.shouldEnd()) {
1120
808
  set(this, 'state', SC.Gesture.ENDED);
1121
809
  this.didEnd();
1122
810
 
@@ -1174,9 +862,11 @@ var sigFigs = 100;
1174
862
 
1175
863
  var myview = SC.View.create({
1176
864
  elementId: 'gestureTest',
1177
- pinchChange: function(recognizer) {
1178
- var scale = recognizer.get('scale');
1179
- this.$().css('-webkit-transform','scale3d('+scale+','+scale+',1)');
865
+
866
+ pinchChange: function(rec) {
867
+ this.$().css('scale',function(index, value) {
868
+ return rec.get('scale') * value
869
+ });
1180
870
  }
1181
871
  })
1182
872
 
@@ -1312,9 +1002,13 @@ var x = 0;
1312
1002
 
1313
1003
  var myview = SC.View.create({
1314
1004
  elementId: 'gestureTest',
1315
- panChange: function(recognizer) {
1316
- var translation = recognizer.get('translation');
1317
- this.$().css('-webkit-transform','translate3d('+translate.x+'px,'+translate.y+'px,0)');
1005
+
1006
+ panChange: function(rec) {
1007
+ var val = rec.get('translation');
1008
+ this.$().css({
1009
+ translateX: '%@=%@'.fmt((val.x < 0)? '-' : '+',Math.abs(val.x)),
1010
+ translateY: '%@=%@'.fmt((val.y < 0)? '-' : '+',Math.abs(val.y))
1011
+ });
1318
1012
  }
1319
1013
  })
1320
1014
 
@@ -1428,13 +1122,10 @@ var set = SC.set;
1428
1122
 
1429
1123
  Recognizes a multi-touch tap gesture. Tap gestures allow for a certain amount
1430
1124
  of wiggle-room between a start and end of a touch. Taps are discrete gestures
1431
- so only tapStart() and tapEnd() will get fired on a view.
1125
+ so only tapEnd() will get fired on a view.
1432
1126
 
1433
1127
  var myview = SC.View.create({
1434
1128
  elementId: 'gestureTest',
1435
- tapStart: function(recognizer) {
1436
- $('#gestureTest').css('background','green');
1437
- },
1438
1129
 
1439
1130
  tapEnd: function(recognizer) {
1440
1131
  $('#gestureTest').css('background','yellow');
@@ -1445,8 +1136,8 @@ var set = SC.set;
1445
1136
  property, which you can set in the panOptions hash:
1446
1137
 
1447
1138
  var myview = SC.View.create({
1448
- panOptions: {
1449
- numberOfRequiredTouches: 3
1139
+ tapOptions: {
1140
+ numberOfTaps: 3
1450
1141
  }
1451
1142
  ...
1452
1143
  })
@@ -1610,20 +1301,5 @@ SC.View.reopen(
1610
1301
 
1611
1302
  });
1612
1303
 
1613
-
1614
1304
  })({});
1615
1305
 
1616
-
1617
- (function(exports) {
1618
-
1619
-
1620
-
1621
-
1622
- })({});
1623
-
1624
-
1625
- (function(exports) {
1626
-
1627
-
1628
-
1629
- })({});