headless-squirrel 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. data/README.rdoc +55 -0
  2. data/Rakefile +27 -0
  3. data/bin/jstest +10 -0
  4. data/lib/headless_squirrel.rb +2 -0
  5. data/lib/headless_squirrel/console.rb +24 -0
  6. data/lib/headless_squirrel/runner.rb +70 -0
  7. data/lib/headless_squirrel/test.rb +17 -0
  8. data/lib/headless_squirrel/test_case.rb +158 -0
  9. data/test/fixtures/a_unit_test.html +27 -0
  10. data/test/fixtures/a_unit_test.js +22 -0
  11. data/test/fixtures/syntax_error.html +27 -0
  12. data/test/fixtures/syntax_error.js +5 -0
  13. data/test/fixtures/type_error.html +27 -0
  14. data/test/fixtures/type_error.js +1 -0
  15. data/test/regression/prototype/unit/ajax_test.html +29 -0
  16. data/test/regression/prototype/unit/array_test.html +28 -0
  17. data/test/regression/prototype/unit/assets/prototype.js +4900 -0
  18. data/test/regression/prototype/unit/assets/unittest.css +50 -0
  19. data/test/regression/prototype/unit/assets/unittest.js +615 -0
  20. data/test/regression/prototype/unit/assets/unittest_transport.js +1 -0
  21. data/test/regression/prototype/unit/base_test.html +27 -0
  22. data/test/regression/prototype/unit/class_test.html +27 -0
  23. data/test/regression/prototype/unit/date_test.html +27 -0
  24. data/test/regression/prototype/unit/dom_test.html +304 -0
  25. data/test/regression/prototype/unit/element_mixins_test.html +30 -0
  26. data/test/regression/prototype/unit/enumerable_test.html +35 -0
  27. data/test/regression/prototype/unit/event_test.html +31 -0
  28. data/test/regression/prototype/unit/fixtures/ajax.html +2 -0
  29. data/test/regression/prototype/unit/fixtures/ajax.js +42 -0
  30. data/test/regression/prototype/unit/fixtures/array.html +1 -0
  31. data/test/regression/prototype/unit/fixtures/class.js +83 -0
  32. data/test/regression/prototype/unit/fixtures/content.html +1 -0
  33. data/test/regression/prototype/unit/fixtures/data.json +1 -0
  34. data/test/regression/prototype/unit/fixtures/dom.css +84 -0
  35. data/test/regression/prototype/unit/fixtures/dom.html +278 -0
  36. data/test/regression/prototype/unit/fixtures/dom.js +17 -0
  37. data/test/regression/prototype/unit/fixtures/element_mixins.html +4 -0
  38. data/test/regression/prototype/unit/fixtures/element_mixins.js +2 -0
  39. data/test/regression/prototype/unit/fixtures/empty.html +0 -0
  40. data/test/regression/prototype/unit/fixtures/empty.js +1 -0
  41. data/test/regression/prototype/unit/fixtures/enumerable.html +8 -0
  42. data/test/regression/prototype/unit/fixtures/enumerable.js +23 -0
  43. data/test/regression/prototype/unit/fixtures/event.html +4 -0
  44. data/test/regression/prototype/unit/fixtures/form.html +108 -0
  45. data/test/regression/prototype/unit/fixtures/function.js +13 -0
  46. data/test/regression/prototype/unit/fixtures/hash.js +25 -0
  47. data/test/regression/prototype/unit/fixtures/hello.js +1 -0
  48. data/test/regression/prototype/unit/fixtures/logo.gif +0 -0
  49. data/test/regression/prototype/unit/fixtures/object.html +6 -0
  50. data/test/regression/prototype/unit/fixtures/object.js +7 -0
  51. data/test/regression/prototype/unit/fixtures/position.html +9 -0
  52. data/test/regression/prototype/unit/fixtures/selector.html +71 -0
  53. data/test/regression/prototype/unit/fixtures/string.js +8 -0
  54. data/test/regression/prototype/unit/fixtures/unittest.html +18 -0
  55. data/test/regression/prototype/unit/form_test.html +135 -0
  56. data/test/regression/prototype/unit/function_test.html +27 -0
  57. data/test/regression/prototype/unit/hash_test.html +27 -0
  58. data/test/regression/prototype/unit/number_test.html +27 -0
  59. data/test/regression/prototype/unit/object_test.html +32 -0
  60. data/test/regression/prototype/unit/periodical_executer_test.html +27 -0
  61. data/test/regression/prototype/unit/position_test.html +36 -0
  62. data/test/regression/prototype/unit/prototype_test.html +27 -0
  63. data/test/regression/prototype/unit/range_test.html +27 -0
  64. data/test/regression/prototype/unit/regexp_test.html +27 -0
  65. data/test/regression/prototype/unit/selector_test.html +98 -0
  66. data/test/regression/prototype/unit/string_test.html +27 -0
  67. data/test/regression/prototype/unit/tests/ajax_test.js +379 -0
  68. data/test/regression/prototype/unit/tests/array_test.js +186 -0
  69. data/test/regression/prototype/unit/tests/base_test.js +43 -0
  70. data/test/regression/prototype/unit/tests/class_test.js +136 -0
  71. data/test/regression/prototype/unit/tests/date_test.js +5 -0
  72. data/test/regression/prototype/unit/tests/dom_test.js +1493 -0
  73. data/test/regression/prototype/unit/tests/element_mixins_test.js +32 -0
  74. data/test/regression/prototype/unit/tests/enumerable_test.js +271 -0
  75. data/test/regression/prototype/unit/tests/event_test.js +235 -0
  76. data/test/regression/prototype/unit/tests/form_test.js +382 -0
  77. data/test/regression/prototype/unit/tests/function_test.js +133 -0
  78. data/test/regression/prototype/unit/tests/hash_test.js +178 -0
  79. data/test/regression/prototype/unit/tests/number_test.js +44 -0
  80. data/test/regression/prototype/unit/tests/object_test.js +180 -0
  81. data/test/regression/prototype/unit/tests/periodical_executer_test.js +15 -0
  82. data/test/regression/prototype/unit/tests/position_test.js +44 -0
  83. data/test/regression/prototype/unit/tests/prototype_test.js +43 -0
  84. data/test/regression/prototype/unit/tests/range_test.js +58 -0
  85. data/test/regression/prototype/unit/tests/regexp_test.js +42 -0
  86. data/test/regression/prototype/unit/tests/selector_test.js +408 -0
  87. data/test/regression/prototype/unit/tests/string_test.js +548 -0
  88. data/test/regression/prototype/unit/tests/unittest_test.js +148 -0
  89. data/test/regression/prototype/unit/unittest_test.html +45 -0
  90. data/test/regression/prototype/upstream +1 -0
  91. data/test/regression/scriptaculous/unit/_ajax_inplaceeditor_ipce_alt_text.html +1 -0
  92. data/test/regression/scriptaculous/unit/_ajax_inplaceeditor_ipce_collection.js +1 -0
  93. data/test/regression/scriptaculous/unit/_ajax_inplaceeditor_result.html +1 -0
  94. data/test/regression/scriptaculous/unit/_ajax_inplaceeditor_result2.html +1 -0
  95. data/test/regression/scriptaculous/unit/_ajax_inplaceeditor_tagged.html +1 -0
  96. data/test/regression/scriptaculous/unit/_ajax_inplaceeditor_text.html +1 -0
  97. data/test/regression/scriptaculous/unit/_ajax_updater_result.html +20 -0
  98. data/test/regression/scriptaculous/unit/_autocomplete_result.html +11 -0
  99. data/test/regression/scriptaculous/unit/_autocomplete_result_nobr.html +1 -0
  100. data/test/regression/scriptaculous/unit/ajax_autocompleter_test.html +243 -0
  101. data/test/regression/scriptaculous/unit/ajax_inplaceeditor_test.html +895 -0
  102. data/test/regression/scriptaculous/unit/assets/builder.js +134 -0
  103. data/test/regression/scriptaculous/unit/assets/controls.js +963 -0
  104. data/test/regression/scriptaculous/unit/assets/dragdrop.js +973 -0
  105. data/test/regression/scriptaculous/unit/assets/effects.js +1122 -0
  106. data/test/regression/scriptaculous/unit/assets/javascripttest.rb +203 -0
  107. data/test/regression/scriptaculous/unit/assets/prototype.js +4320 -0
  108. data/test/regression/scriptaculous/unit/assets/scriptaculous.js +66 -0
  109. data/test/regression/scriptaculous/unit/assets/slider.js +273 -0
  110. data/test/regression/scriptaculous/unit/assets/sound.js +57 -0
  111. data/test/regression/scriptaculous/unit/assets/unittest.js +566 -0
  112. data/test/regression/scriptaculous/unit/bdd_test.html +150 -0
  113. data/test/regression/scriptaculous/unit/builder_test.html +262 -0
  114. data/test/regression/scriptaculous/unit/dragdrop_test.html +131 -0
  115. data/test/regression/scriptaculous/unit/effects_test.html +547 -0
  116. data/test/regression/scriptaculous/unit/element_test.html +116 -0
  117. data/test/regression/scriptaculous/unit/icon.png +0 -0
  118. data/test/regression/scriptaculous/unit/index.html +70 -0
  119. data/test/regression/scriptaculous/unit/loading_test.html +41 -0
  120. data/test/regression/scriptaculous/unit/position_clone_test.html +312 -0
  121. data/test/regression/scriptaculous/unit/slider_test.html +437 -0
  122. data/test/regression/scriptaculous/unit/sortable_test.html +205 -0
  123. data/test/regression/scriptaculous/unit/string_test.html +71 -0
  124. data/test/regression/scriptaculous/unit/unittest_test.html +154 -0
  125. data/test/regression/scriptaculous/upstream +1 -0
  126. data/test/test_helper.rb +20 -0
  127. data/test/unit/runner_test.rb +165 -0
  128. data/test/unit/test_case_test.rb +207 -0
  129. data/test/unit/test_test.rb +24 -0
  130. metadata +209 -0
@@ -0,0 +1,1122 @@
1
+ // Copyright (c) 2005-2008 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
2
+ // Contributors:
3
+ // Justin Palmer (http://encytemedia.com/)
4
+ // Mark Pilgrim (http://diveintomark.org/)
5
+ // Martin Bialasinki
6
+ //
7
+ // script.aculo.us is freely distributable under the terms of an MIT-style license.
8
+ // For details, see the script.aculo.us web site: http://script.aculo.us/
9
+
10
+ // converts rgb() and #xxx to #xxxxxx format,
11
+ // returns self (or first argument) if not convertable
12
+ String.prototype.parseColor = function() {
13
+ var color = '#';
14
+ if (this.slice(0,4) == 'rgb(') {
15
+ var cols = this.slice(4,this.length-1).split(',');
16
+ var i=0; do { color += parseInt(cols[i]).toColorPart() } while (++i<3);
17
+ } else {
18
+ if (this.slice(0,1) == '#') {
19
+ if (this.length==4) for(var i=1;i<4;i++) color += (this.charAt(i) + this.charAt(i)).toLowerCase();
20
+ if (this.length==7) color = this.toLowerCase();
21
+ }
22
+ }
23
+ return (color.length==7 ? color : (arguments[0] || this));
24
+ };
25
+
26
+ /*--------------------------------------------------------------------------*/
27
+
28
+ Element.collectTextNodes = function(element) {
29
+ return $A($(element).childNodes).collect( function(node) {
30
+ return (node.nodeType==3 ? node.nodeValue :
31
+ (node.hasChildNodes() ? Element.collectTextNodes(node) : ''));
32
+ }).flatten().join('');
33
+ };
34
+
35
+ Element.collectTextNodesIgnoreClass = function(element, className) {
36
+ return $A($(element).childNodes).collect( function(node) {
37
+ return (node.nodeType==3 ? node.nodeValue :
38
+ ((node.hasChildNodes() && !Element.hasClassName(node,className)) ?
39
+ Element.collectTextNodesIgnoreClass(node, className) : ''));
40
+ }).flatten().join('');
41
+ };
42
+
43
+ Element.setContentZoom = function(element, percent) {
44
+ element = $(element);
45
+ element.setStyle({fontSize: (percent/100) + 'em'});
46
+ if (Prototype.Browser.WebKit) window.scrollBy(0,0);
47
+ return element;
48
+ };
49
+
50
+ Element.getInlineOpacity = function(element){
51
+ return $(element).style.opacity || '';
52
+ };
53
+
54
+ Element.forceRerendering = function(element) {
55
+ try {
56
+ element = $(element);
57
+ var n = document.createTextNode(' ');
58
+ element.appendChild(n);
59
+ element.removeChild(n);
60
+ } catch(e) { }
61
+ };
62
+
63
+ /*--------------------------------------------------------------------------*/
64
+
65
+ var Effect = {
66
+ _elementDoesNotExistError: {
67
+ name: 'ElementDoesNotExistError',
68
+ message: 'The specified DOM element does not exist, but is required for this effect to operate'
69
+ },
70
+ Transitions: {
71
+ linear: Prototype.K,
72
+ sinoidal: function(pos) {
73
+ return (-Math.cos(pos*Math.PI)/2) + .5;
74
+ },
75
+ reverse: function(pos) {
76
+ return 1-pos;
77
+ },
78
+ flicker: function(pos) {
79
+ var pos = ((-Math.cos(pos*Math.PI)/4) + .75) + Math.random()/4;
80
+ return pos > 1 ? 1 : pos;
81
+ },
82
+ wobble: function(pos) {
83
+ return (-Math.cos(pos*Math.PI*(9*pos))/2) + .5;
84
+ },
85
+ pulse: function(pos, pulses) {
86
+ return (-Math.cos((pos*((pulses||5)-.5)*2)*Math.PI)/2) + .5;
87
+ },
88
+ spring: function(pos) {
89
+ return 1 - (Math.cos(pos * 4.5 * Math.PI) * Math.exp(-pos * 6));
90
+ },
91
+ none: function(pos) {
92
+ return 0;
93
+ },
94
+ full: function(pos) {
95
+ return 1;
96
+ }
97
+ },
98
+ DefaultOptions: {
99
+ duration: 1.0, // seconds
100
+ fps: 100, // 100= assume 66fps max.
101
+ sync: false, // true for combining
102
+ from: 0.0,
103
+ to: 1.0,
104
+ delay: 0.0,
105
+ queue: 'parallel'
106
+ },
107
+ tagifyText: function(element) {
108
+ var tagifyStyle = 'position:relative';
109
+ if (Prototype.Browser.IE) tagifyStyle += ';zoom:1';
110
+
111
+ element = $(element);
112
+ $A(element.childNodes).each( function(child) {
113
+ if (child.nodeType==3) {
114
+ child.nodeValue.toArray().each( function(character) {
115
+ element.insertBefore(
116
+ new Element('span', {style: tagifyStyle}).update(
117
+ character == ' ' ? String.fromCharCode(160) : character),
118
+ child);
119
+ });
120
+ Element.remove(child);
121
+ }
122
+ });
123
+ },
124
+ multiple: function(element, effect) {
125
+ var elements;
126
+ if (((typeof element == 'object') ||
127
+ Object.isFunction(element)) &&
128
+ (element.length))
129
+ elements = element;
130
+ else
131
+ elements = $(element).childNodes;
132
+
133
+ var options = Object.extend({
134
+ speed: 0.1,
135
+ delay: 0.0
136
+ }, arguments[2] || { });
137
+ var masterDelay = options.delay;
138
+
139
+ $A(elements).each( function(element, index) {
140
+ new effect(element, Object.extend(options, { delay: index * options.speed + masterDelay }));
141
+ });
142
+ },
143
+ PAIRS: {
144
+ 'slide': ['SlideDown','SlideUp'],
145
+ 'blind': ['BlindDown','BlindUp'],
146
+ 'appear': ['Appear','Fade']
147
+ },
148
+ toggle: function(element, effect) {
149
+ element = $(element);
150
+ effect = (effect || 'appear').toLowerCase();
151
+ var options = Object.extend({
152
+ queue: { position:'end', scope:(element.id || 'global'), limit: 1 }
153
+ }, arguments[2] || { });
154
+ Effect[element.visible() ?
155
+ Effect.PAIRS[effect][1] : Effect.PAIRS[effect][0]](element, options);
156
+ }
157
+ };
158
+
159
+ Effect.DefaultOptions.transition = Effect.Transitions.sinoidal;
160
+
161
+ /* ------------- core effects ------------- */
162
+
163
+ Effect.ScopedQueue = Class.create(Enumerable, {
164
+ initialize: function() {
165
+ this.effects = [];
166
+ this.interval = null;
167
+ },
168
+ _each: function(iterator) {
169
+ this.effects._each(iterator);
170
+ },
171
+ add: function(effect) {
172
+ var timestamp = new Date().getTime();
173
+
174
+ var position = Object.isString(effect.options.queue) ?
175
+ effect.options.queue : effect.options.queue.position;
176
+
177
+ switch(position) {
178
+ case 'front':
179
+ // move unstarted effects after this effect
180
+ this.effects.findAll(function(e){ return e.state=='idle' }).each( function(e) {
181
+ e.startOn += effect.finishOn;
182
+ e.finishOn += effect.finishOn;
183
+ });
184
+ break;
185
+ case 'with-last':
186
+ timestamp = this.effects.pluck('startOn').max() || timestamp;
187
+ break;
188
+ case 'end':
189
+ // start effect after last queued effect has finished
190
+ timestamp = this.effects.pluck('finishOn').max() || timestamp;
191
+ break;
192
+ }
193
+
194
+ effect.startOn += timestamp;
195
+ effect.finishOn += timestamp;
196
+
197
+ if (!effect.options.queue.limit || (this.effects.length < effect.options.queue.limit))
198
+ this.effects.push(effect);
199
+
200
+ if (!this.interval)
201
+ this.interval = setInterval(this.loop.bind(this), 15);
202
+ },
203
+ remove: function(effect) {
204
+ this.effects = this.effects.reject(function(e) { return e==effect });
205
+ if (this.effects.length == 0) {
206
+ clearInterval(this.interval);
207
+ this.interval = null;
208
+ }
209
+ },
210
+ loop: function() {
211
+ var timePos = new Date().getTime();
212
+ for(var i=0, len=this.effects.length;i<len;i++)
213
+ this.effects[i] && this.effects[i].loop(timePos);
214
+ }
215
+ });
216
+
217
+ Effect.Queues = {
218
+ instances: $H(),
219
+ get: function(queueName) {
220
+ if (!Object.isString(queueName)) return queueName;
221
+
222
+ return this.instances.get(queueName) ||
223
+ this.instances.set(queueName, new Effect.ScopedQueue());
224
+ }
225
+ };
226
+ Effect.Queue = Effect.Queues.get('global');
227
+
228
+ Effect.Base = Class.create({
229
+ position: null,
230
+ start: function(options) {
231
+ if (options && options.transition === false) options.transition = Effect.Transitions.linear;
232
+ this.options = Object.extend(Object.extend({ },Effect.DefaultOptions), options || { });
233
+ this.currentFrame = 0;
234
+ this.state = 'idle';
235
+ this.startOn = this.options.delay*1000;
236
+ this.finishOn = this.startOn+(this.options.duration*1000);
237
+ this.fromToDelta = this.options.to-this.options.from;
238
+ this.totalTime = this.finishOn-this.startOn;
239
+ this.totalFrames = this.options.fps*this.options.duration;
240
+
241
+ this.render = (function() {
242
+ function dispatch(effect, eventName) {
243
+ if (effect.options[eventName + 'Internal'])
244
+ effect.options[eventName + 'Internal'](effect);
245
+ if (effect.options[eventName])
246
+ effect.options[eventName](effect);
247
+ }
248
+
249
+ return function(pos) {
250
+ if (this.state === "idle") {
251
+ this.state = "running";
252
+ dispatch(this, 'beforeSetup');
253
+ if (this.setup) this.setup();
254
+ dispatch(this, 'afterSetup');
255
+ }
256
+ if (this.state === "running") {
257
+ pos = (this.options.transition(pos) * this.fromToDelta) + this.options.from;
258
+ this.position = pos;
259
+ dispatch(this, 'beforeUpdate');
260
+ if (this.update) this.update(pos);
261
+ dispatch(this, 'afterUpdate');
262
+ }
263
+ };
264
+ })();
265
+
266
+ this.event('beforeStart');
267
+ if (!this.options.sync)
268
+ Effect.Queues.get(Object.isString(this.options.queue) ?
269
+ 'global' : this.options.queue.scope).add(this);
270
+ },
271
+ loop: function(timePos) {
272
+ if (timePos >= this.startOn) {
273
+ if (timePos >= this.finishOn) {
274
+ this.render(1.0);
275
+ this.cancel();
276
+ this.event('beforeFinish');
277
+ if (this.finish) this.finish();
278
+ this.event('afterFinish');
279
+ return;
280
+ }
281
+ var pos = (timePos - this.startOn) / this.totalTime,
282
+ frame = (pos * this.totalFrames).round();
283
+ if (frame > this.currentFrame) {
284
+ this.render(pos);
285
+ this.currentFrame = frame;
286
+ }
287
+ }
288
+ },
289
+ cancel: function() {
290
+ if (!this.options.sync)
291
+ Effect.Queues.get(Object.isString(this.options.queue) ?
292
+ 'global' : this.options.queue.scope).remove(this);
293
+ this.state = 'finished';
294
+ },
295
+ event: function(eventName) {
296
+ if (this.options[eventName + 'Internal']) this.options[eventName + 'Internal'](this);
297
+ if (this.options[eventName]) this.options[eventName](this);
298
+ },
299
+ inspect: function() {
300
+ var data = $H();
301
+ for(property in this)
302
+ if (!Object.isFunction(this[property])) data.set(property, this[property]);
303
+ return '#<Effect:' + data.inspect() + ',options:' + $H(this.options).inspect() + '>';
304
+ }
305
+ });
306
+
307
+ Effect.Parallel = Class.create(Effect.Base, {
308
+ initialize: function(effects) {
309
+ this.effects = effects || [];
310
+ this.start(arguments[1]);
311
+ },
312
+ update: function(position) {
313
+ this.effects.invoke('render', position);
314
+ },
315
+ finish: function(position) {
316
+ this.effects.each( function(effect) {
317
+ effect.render(1.0);
318
+ effect.cancel();
319
+ effect.event('beforeFinish');
320
+ if (effect.finish) effect.finish(position);
321
+ effect.event('afterFinish');
322
+ });
323
+ }
324
+ });
325
+
326
+ Effect.Tween = Class.create(Effect.Base, {
327
+ initialize: function(object, from, to) {
328
+ object = Object.isString(object) ? $(object) : object;
329
+ var args = $A(arguments), method = args.last(),
330
+ options = args.length == 5 ? args[3] : null;
331
+ this.method = Object.isFunction(method) ? method.bind(object) :
332
+ Object.isFunction(object[method]) ? object[method].bind(object) :
333
+ function(value) { object[method] = value };
334
+ this.start(Object.extend({ from: from, to: to }, options || { }));
335
+ },
336
+ update: function(position) {
337
+ this.method(position);
338
+ }
339
+ });
340
+
341
+ Effect.Event = Class.create(Effect.Base, {
342
+ initialize: function() {
343
+ this.start(Object.extend({ duration: 0 }, arguments[0] || { }));
344
+ },
345
+ update: Prototype.emptyFunction
346
+ });
347
+
348
+ Effect.Opacity = Class.create(Effect.Base, {
349
+ initialize: function(element) {
350
+ this.element = $(element);
351
+ if (!this.element) throw(Effect._elementDoesNotExistError);
352
+ // make this work on IE on elements without 'layout'
353
+ if (Prototype.Browser.IE && (!this.element.currentStyle.hasLayout))
354
+ this.element.setStyle({zoom: 1});
355
+ var options = Object.extend({
356
+ from: this.element.getOpacity() || 0.0,
357
+ to: 1.0
358
+ }, arguments[1] || { });
359
+ this.start(options);
360
+ },
361
+ update: function(position) {
362
+ this.element.setOpacity(position);
363
+ }
364
+ });
365
+
366
+ Effect.Move = Class.create(Effect.Base, {
367
+ initialize: function(element) {
368
+ this.element = $(element);
369
+ if (!this.element) throw(Effect._elementDoesNotExistError);
370
+ var options = Object.extend({
371
+ x: 0,
372
+ y: 0,
373
+ mode: 'relative'
374
+ }, arguments[1] || { });
375
+ this.start(options);
376
+ },
377
+ setup: function() {
378
+ this.element.makePositioned();
379
+ this.originalLeft = parseFloat(this.element.getStyle('left') || '0');
380
+ this.originalTop = parseFloat(this.element.getStyle('top') || '0');
381
+ if (this.options.mode == 'absolute') {
382
+ this.options.x = this.options.x - this.originalLeft;
383
+ this.options.y = this.options.y - this.originalTop;
384
+ }
385
+ },
386
+ update: function(position) {
387
+ this.element.setStyle({
388
+ left: (this.options.x * position + this.originalLeft).round() + 'px',
389
+ top: (this.options.y * position + this.originalTop).round() + 'px'
390
+ });
391
+ }
392
+ });
393
+
394
+ // for backwards compatibility
395
+ Effect.MoveBy = function(element, toTop, toLeft) {
396
+ return new Effect.Move(element,
397
+ Object.extend({ x: toLeft, y: toTop }, arguments[3] || { }));
398
+ };
399
+
400
+ Effect.Scale = Class.create(Effect.Base, {
401
+ initialize: function(element, percent) {
402
+ this.element = $(element);
403
+ if (!this.element) throw(Effect._elementDoesNotExistError);
404
+ var options = Object.extend({
405
+ scaleX: true,
406
+ scaleY: true,
407
+ scaleContent: true,
408
+ scaleFromCenter: false,
409
+ scaleMode: 'box', // 'box' or 'contents' or { } with provided values
410
+ scaleFrom: 100.0,
411
+ scaleTo: percent
412
+ }, arguments[2] || { });
413
+ this.start(options);
414
+ },
415
+ setup: function() {
416
+ this.restoreAfterFinish = this.options.restoreAfterFinish || false;
417
+ this.elementPositioning = this.element.getStyle('position');
418
+
419
+ this.originalStyle = { };
420
+ ['top','left','width','height','fontSize'].each( function(k) {
421
+ this.originalStyle[k] = this.element.style[k];
422
+ }.bind(this));
423
+
424
+ this.originalTop = this.element.offsetTop;
425
+ this.originalLeft = this.element.offsetLeft;
426
+
427
+ var fontSize = this.element.getStyle('font-size') || '100%';
428
+ ['em','px','%','pt'].each( function(fontSizeType) {
429
+ if (fontSize.indexOf(fontSizeType)>0) {
430
+ this.fontSize = parseFloat(fontSize);
431
+ this.fontSizeType = fontSizeType;
432
+ }
433
+ }.bind(this));
434
+
435
+ this.factor = (this.options.scaleTo - this.options.scaleFrom)/100;
436
+
437
+ this.dims = null;
438
+ if (this.options.scaleMode=='box')
439
+ this.dims = [this.element.offsetHeight, this.element.offsetWidth];
440
+ if (/^content/.test(this.options.scaleMode))
441
+ this.dims = [this.element.scrollHeight, this.element.scrollWidth];
442
+ if (!this.dims)
443
+ this.dims = [this.options.scaleMode.originalHeight,
444
+ this.options.scaleMode.originalWidth];
445
+ },
446
+ update: function(position) {
447
+ var currentScale = (this.options.scaleFrom/100.0) + (this.factor * position);
448
+ if (this.options.scaleContent && this.fontSize)
449
+ this.element.setStyle({fontSize: this.fontSize * currentScale + this.fontSizeType });
450
+ this.setDimensions(this.dims[0] * currentScale, this.dims[1] * currentScale);
451
+ },
452
+ finish: function(position) {
453
+ if (this.restoreAfterFinish) this.element.setStyle(this.originalStyle);
454
+ },
455
+ setDimensions: function(height, width) {
456
+ var d = { };
457
+ if (this.options.scaleX) d.width = width.round() + 'px';
458
+ if (this.options.scaleY) d.height = height.round() + 'px';
459
+ if (this.options.scaleFromCenter) {
460
+ var topd = (height - this.dims[0])/2;
461
+ var leftd = (width - this.dims[1])/2;
462
+ if (this.elementPositioning == 'absolute') {
463
+ if (this.options.scaleY) d.top = this.originalTop-topd + 'px';
464
+ if (this.options.scaleX) d.left = this.originalLeft-leftd + 'px';
465
+ } else {
466
+ if (this.options.scaleY) d.top = -topd + 'px';
467
+ if (this.options.scaleX) d.left = -leftd + 'px';
468
+ }
469
+ }
470
+ this.element.setStyle(d);
471
+ }
472
+ });
473
+
474
+ Effect.Highlight = Class.create(Effect.Base, {
475
+ initialize: function(element) {
476
+ this.element = $(element);
477
+ if (!this.element) throw(Effect._elementDoesNotExistError);
478
+ var options = Object.extend({ startcolor: '#ffff99' }, arguments[1] || { });
479
+ this.start(options);
480
+ },
481
+ setup: function() {
482
+ // Prevent executing on elements not in the layout flow
483
+ if (this.element.getStyle('display')=='none') { this.cancel(); return; }
484
+ // Disable background image during the effect
485
+ this.oldStyle = { };
486
+ if (!this.options.keepBackgroundImage) {
487
+ this.oldStyle.backgroundImage = this.element.getStyle('background-image');
488
+ this.element.setStyle({backgroundImage: 'none'});
489
+ }
490
+ if (!this.options.endcolor)
491
+ this.options.endcolor = this.element.getStyle('background-color').parseColor('#ffffff');
492
+ if (!this.options.restorecolor)
493
+ this.options.restorecolor = this.element.getStyle('background-color');
494
+ // init color calculations
495
+ this._base = $R(0,2).map(function(i){ return parseInt(this.options.startcolor.slice(i*2+1,i*2+3),16) }.bind(this));
496
+ this._delta = $R(0,2).map(function(i){ return parseInt(this.options.endcolor.slice(i*2+1,i*2+3),16)-this._base[i] }.bind(this));
497
+ },
498
+ update: function(position) {
499
+ this.element.setStyle({backgroundColor: $R(0,2).inject('#',function(m,v,i){
500
+ return m+((this._base[i]+(this._delta[i]*position)).round().toColorPart()); }.bind(this)) });
501
+ },
502
+ finish: function() {
503
+ this.element.setStyle(Object.extend(this.oldStyle, {
504
+ backgroundColor: this.options.restorecolor
505
+ }));
506
+ }
507
+ });
508
+
509
+ Effect.ScrollTo = function(element) {
510
+ var options = arguments[1] || { },
511
+ scrollOffsets = document.viewport.getScrollOffsets(),
512
+ elementOffsets = $(element).cumulativeOffset();
513
+
514
+ if (options.offset) elementOffsets[1] += options.offset;
515
+
516
+ return new Effect.Tween(null,
517
+ scrollOffsets.top,
518
+ elementOffsets[1],
519
+ options,
520
+ function(p){ scrollTo(scrollOffsets.left, p.round()); }
521
+ );
522
+ };
523
+
524
+ /* ------------- combination effects ------------- */
525
+
526
+ Effect.Fade = function(element) {
527
+ element = $(element);
528
+ var oldOpacity = element.getInlineOpacity();
529
+ var options = Object.extend({
530
+ from: element.getOpacity() || 1.0,
531
+ to: 0.0,
532
+ afterFinishInternal: function(effect) {
533
+ if (effect.options.to!=0) return;
534
+ effect.element.hide().setStyle({opacity: oldOpacity});
535
+ }
536
+ }, arguments[1] || { });
537
+ return new Effect.Opacity(element,options);
538
+ };
539
+
540
+ Effect.Appear = function(element) {
541
+ element = $(element);
542
+ var options = Object.extend({
543
+ from: (element.getStyle('display') == 'none' ? 0.0 : element.getOpacity() || 0.0),
544
+ to: 1.0,
545
+ // force Safari to render floated elements properly
546
+ afterFinishInternal: function(effect) {
547
+ effect.element.forceRerendering();
548
+ },
549
+ beforeSetup: function(effect) {
550
+ effect.element.setOpacity(effect.options.from).show();
551
+ }}, arguments[1] || { });
552
+ return new Effect.Opacity(element,options);
553
+ };
554
+
555
+ Effect.Puff = function(element) {
556
+ element = $(element);
557
+ var oldStyle = {
558
+ opacity: element.getInlineOpacity(),
559
+ position: element.getStyle('position'),
560
+ top: element.style.top,
561
+ left: element.style.left,
562
+ width: element.style.width,
563
+ height: element.style.height
564
+ };
565
+ return new Effect.Parallel(
566
+ [ new Effect.Scale(element, 200,
567
+ { sync: true, scaleFromCenter: true, scaleContent: true, restoreAfterFinish: true }),
568
+ new Effect.Opacity(element, { sync: true, to: 0.0 } ) ],
569
+ Object.extend({ duration: 1.0,
570
+ beforeSetupInternal: function(effect) {
571
+ Position.absolutize(effect.effects[0].element);
572
+ },
573
+ afterFinishInternal: function(effect) {
574
+ effect.effects[0].element.hide().setStyle(oldStyle); }
575
+ }, arguments[1] || { })
576
+ );
577
+ };
578
+
579
+ Effect.BlindUp = function(element) {
580
+ element = $(element);
581
+ element.makeClipping();
582
+ return new Effect.Scale(element, 0,
583
+ Object.extend({ scaleContent: false,
584
+ scaleX: false,
585
+ restoreAfterFinish: true,
586
+ afterFinishInternal: function(effect) {
587
+ effect.element.hide().undoClipping();
588
+ }
589
+ }, arguments[1] || { })
590
+ );
591
+ };
592
+
593
+ Effect.BlindDown = function(element) {
594
+ element = $(element);
595
+ var elementDimensions = element.getDimensions();
596
+ return new Effect.Scale(element, 100, Object.extend({
597
+ scaleContent: false,
598
+ scaleX: false,
599
+ scaleFrom: 0,
600
+ scaleMode: {originalHeight: elementDimensions.height, originalWidth: elementDimensions.width},
601
+ restoreAfterFinish: true,
602
+ afterSetup: function(effect) {
603
+ effect.element.makeClipping().setStyle({height: '0px'}).show();
604
+ },
605
+ afterFinishInternal: function(effect) {
606
+ effect.element.undoClipping();
607
+ }
608
+ }, arguments[1] || { }));
609
+ };
610
+
611
+ Effect.SwitchOff = function(element) {
612
+ element = $(element);
613
+ var oldOpacity = element.getInlineOpacity();
614
+ return new Effect.Appear(element, Object.extend({
615
+ duration: 0.4,
616
+ from: 0,
617
+ transition: Effect.Transitions.flicker,
618
+ afterFinishInternal: function(effect) {
619
+ new Effect.Scale(effect.element, 1, {
620
+ duration: 0.3, scaleFromCenter: true,
621
+ scaleX: false, scaleContent: false, restoreAfterFinish: true,
622
+ beforeSetup: function(effect) {
623
+ effect.element.makePositioned().makeClipping();
624
+ },
625
+ afterFinishInternal: function(effect) {
626
+ effect.element.hide().undoClipping().undoPositioned().setStyle({opacity: oldOpacity});
627
+ }
628
+ });
629
+ }
630
+ }, arguments[1] || { }));
631
+ };
632
+
633
+ Effect.DropOut = function(element) {
634
+ element = $(element);
635
+ var oldStyle = {
636
+ top: element.getStyle('top'),
637
+ left: element.getStyle('left'),
638
+ opacity: element.getInlineOpacity() };
639
+ return new Effect.Parallel(
640
+ [ new Effect.Move(element, {x: 0, y: 100, sync: true }),
641
+ new Effect.Opacity(element, { sync: true, to: 0.0 }) ],
642
+ Object.extend(
643
+ { duration: 0.5,
644
+ beforeSetup: function(effect) {
645
+ effect.effects[0].element.makePositioned();
646
+ },
647
+ afterFinishInternal: function(effect) {
648
+ effect.effects[0].element.hide().undoPositioned().setStyle(oldStyle);
649
+ }
650
+ }, arguments[1] || { }));
651
+ };
652
+
653
+ Effect.Shake = function(element) {
654
+ element = $(element);
655
+ var options = Object.extend({
656
+ distance: 20,
657
+ duration: 0.5
658
+ }, arguments[1] || {});
659
+ var distance = parseFloat(options.distance);
660
+ var split = parseFloat(options.duration) / 10.0;
661
+ var oldStyle = {
662
+ top: element.getStyle('top'),
663
+ left: element.getStyle('left') };
664
+ return new Effect.Move(element,
665
+ { x: distance, y: 0, duration: split, afterFinishInternal: function(effect) {
666
+ new Effect.Move(effect.element,
667
+ { x: -distance*2, y: 0, duration: split*2, afterFinishInternal: function(effect) {
668
+ new Effect.Move(effect.element,
669
+ { x: distance*2, y: 0, duration: split*2, afterFinishInternal: function(effect) {
670
+ new Effect.Move(effect.element,
671
+ { x: -distance*2, y: 0, duration: split*2, afterFinishInternal: function(effect) {
672
+ new Effect.Move(effect.element,
673
+ { x: distance*2, y: 0, duration: split*2, afterFinishInternal: function(effect) {
674
+ new Effect.Move(effect.element,
675
+ { x: -distance, y: 0, duration: split, afterFinishInternal: function(effect) {
676
+ effect.element.undoPositioned().setStyle(oldStyle);
677
+ }}); }}); }}); }}); }}); }});
678
+ };
679
+
680
+ Effect.SlideDown = function(element) {
681
+ element = $(element).cleanWhitespace();
682
+ // SlideDown need to have the content of the element wrapped in a container element with fixed height!
683
+ var oldInnerBottom = element.down().getStyle('bottom');
684
+ var elementDimensions = element.getDimensions();
685
+ return new Effect.Scale(element, 100, Object.extend({
686
+ scaleContent: false,
687
+ scaleX: false,
688
+ scaleFrom: window.opera ? 0 : 1,
689
+ scaleMode: {originalHeight: elementDimensions.height, originalWidth: elementDimensions.width},
690
+ restoreAfterFinish: true,
691
+ afterSetup: function(effect) {
692
+ effect.element.makePositioned();
693
+ effect.element.down().makePositioned();
694
+ if (window.opera) effect.element.setStyle({top: ''});
695
+ effect.element.makeClipping().setStyle({height: '0px'}).show();
696
+ },
697
+ afterUpdateInternal: function(effect) {
698
+ effect.element.down().setStyle({bottom:
699
+ (effect.dims[0] - effect.element.clientHeight) + 'px' });
700
+ },
701
+ afterFinishInternal: function(effect) {
702
+ effect.element.undoClipping().undoPositioned();
703
+ effect.element.down().undoPositioned().setStyle({bottom: oldInnerBottom}); }
704
+ }, arguments[1] || { })
705
+ );
706
+ };
707
+
708
+ Effect.SlideUp = function(element) {
709
+ element = $(element).cleanWhitespace();
710
+ var oldInnerBottom = element.down().getStyle('bottom');
711
+ var elementDimensions = element.getDimensions();
712
+ return new Effect.Scale(element, window.opera ? 0 : 1,
713
+ Object.extend({ scaleContent: false,
714
+ scaleX: false,
715
+ scaleMode: 'box',
716
+ scaleFrom: 100,
717
+ scaleMode: {originalHeight: elementDimensions.height, originalWidth: elementDimensions.width},
718
+ restoreAfterFinish: true,
719
+ afterSetup: function(effect) {
720
+ effect.element.makePositioned();
721
+ effect.element.down().makePositioned();
722
+ if (window.opera) effect.element.setStyle({top: ''});
723
+ effect.element.makeClipping().show();
724
+ },
725
+ afterUpdateInternal: function(effect) {
726
+ effect.element.down().setStyle({bottom:
727
+ (effect.dims[0] - effect.element.clientHeight) + 'px' });
728
+ },
729
+ afterFinishInternal: function(effect) {
730
+ effect.element.hide().undoClipping().undoPositioned();
731
+ effect.element.down().undoPositioned().setStyle({bottom: oldInnerBottom});
732
+ }
733
+ }, arguments[1] || { })
734
+ );
735
+ };
736
+
737
+ // Bug in opera makes the TD containing this element expand for a instance after finish
738
+ Effect.Squish = function(element) {
739
+ return new Effect.Scale(element, window.opera ? 1 : 0, {
740
+ restoreAfterFinish: true,
741
+ beforeSetup: function(effect) {
742
+ effect.element.makeClipping();
743
+ },
744
+ afterFinishInternal: function(effect) {
745
+ effect.element.hide().undoClipping();
746
+ }
747
+ });
748
+ };
749
+
750
+ Effect.Grow = function(element) {
751
+ element = $(element);
752
+ var options = Object.extend({
753
+ direction: 'center',
754
+ moveTransition: Effect.Transitions.sinoidal,
755
+ scaleTransition: Effect.Transitions.sinoidal,
756
+ opacityTransition: Effect.Transitions.full
757
+ }, arguments[1] || { });
758
+ var oldStyle = {
759
+ top: element.style.top,
760
+ left: element.style.left,
761
+ height: element.style.height,
762
+ width: element.style.width,
763
+ opacity: element.getInlineOpacity() };
764
+
765
+ var dims = element.getDimensions();
766
+ var initialMoveX, initialMoveY;
767
+ var moveX, moveY;
768
+
769
+ switch (options.direction) {
770
+ case 'top-left':
771
+ initialMoveX = initialMoveY = moveX = moveY = 0;
772
+ break;
773
+ case 'top-right':
774
+ initialMoveX = dims.width;
775
+ initialMoveY = moveY = 0;
776
+ moveX = -dims.width;
777
+ break;
778
+ case 'bottom-left':
779
+ initialMoveX = moveX = 0;
780
+ initialMoveY = dims.height;
781
+ moveY = -dims.height;
782
+ break;
783
+ case 'bottom-right':
784
+ initialMoveX = dims.width;
785
+ initialMoveY = dims.height;
786
+ moveX = -dims.width;
787
+ moveY = -dims.height;
788
+ break;
789
+ case 'center':
790
+ initialMoveX = dims.width / 2;
791
+ initialMoveY = dims.height / 2;
792
+ moveX = -dims.width / 2;
793
+ moveY = -dims.height / 2;
794
+ break;
795
+ }
796
+
797
+ return new Effect.Move(element, {
798
+ x: initialMoveX,
799
+ y: initialMoveY,
800
+ duration: 0.01,
801
+ beforeSetup: function(effect) {
802
+ effect.element.hide().makeClipping().makePositioned();
803
+ },
804
+ afterFinishInternal: function(effect) {
805
+ new Effect.Parallel(
806
+ [ new Effect.Opacity(effect.element, { sync: true, to: 1.0, from: 0.0, transition: options.opacityTransition }),
807
+ new Effect.Move(effect.element, { x: moveX, y: moveY, sync: true, transition: options.moveTransition }),
808
+ new Effect.Scale(effect.element, 100, {
809
+ scaleMode: { originalHeight: dims.height, originalWidth: dims.width },
810
+ sync: true, scaleFrom: window.opera ? 1 : 0, transition: options.scaleTransition, restoreAfterFinish: true})
811
+ ], Object.extend({
812
+ beforeSetup: function(effect) {
813
+ effect.effects[0].element.setStyle({height: '0px'}).show();
814
+ },
815
+ afterFinishInternal: function(effect) {
816
+ effect.effects[0].element.undoClipping().undoPositioned().setStyle(oldStyle);
817
+ }
818
+ }, options)
819
+ );
820
+ }
821
+ });
822
+ };
823
+
824
+ Effect.Shrink = function(element) {
825
+ element = $(element);
826
+ var options = Object.extend({
827
+ direction: 'center',
828
+ moveTransition: Effect.Transitions.sinoidal,
829
+ scaleTransition: Effect.Transitions.sinoidal,
830
+ opacityTransition: Effect.Transitions.none
831
+ }, arguments[1] || { });
832
+ var oldStyle = {
833
+ top: element.style.top,
834
+ left: element.style.left,
835
+ height: element.style.height,
836
+ width: element.style.width,
837
+ opacity: element.getInlineOpacity() };
838
+
839
+ var dims = element.getDimensions();
840
+ var moveX, moveY;
841
+
842
+ switch (options.direction) {
843
+ case 'top-left':
844
+ moveX = moveY = 0;
845
+ break;
846
+ case 'top-right':
847
+ moveX = dims.width;
848
+ moveY = 0;
849
+ break;
850
+ case 'bottom-left':
851
+ moveX = 0;
852
+ moveY = dims.height;
853
+ break;
854
+ case 'bottom-right':
855
+ moveX = dims.width;
856
+ moveY = dims.height;
857
+ break;
858
+ case 'center':
859
+ moveX = dims.width / 2;
860
+ moveY = dims.height / 2;
861
+ break;
862
+ }
863
+
864
+ return new Effect.Parallel(
865
+ [ new Effect.Opacity(element, { sync: true, to: 0.0, from: 1.0, transition: options.opacityTransition }),
866
+ new Effect.Scale(element, window.opera ? 1 : 0, { sync: true, transition: options.scaleTransition, restoreAfterFinish: true}),
867
+ new Effect.Move(element, { x: moveX, y: moveY, sync: true, transition: options.moveTransition })
868
+ ], Object.extend({
869
+ beforeStartInternal: function(effect) {
870
+ effect.effects[0].element.makePositioned().makeClipping();
871
+ },
872
+ afterFinishInternal: function(effect) {
873
+ effect.effects[0].element.hide().undoClipping().undoPositioned().setStyle(oldStyle); }
874
+ }, options)
875
+ );
876
+ };
877
+
878
+ Effect.Pulsate = function(element) {
879
+ element = $(element);
880
+ var options = arguments[1] || { },
881
+ oldOpacity = element.getInlineOpacity(),
882
+ transition = options.transition || Effect.Transitions.linear,
883
+ reverser = function(pos){
884
+ return 1 - transition((-Math.cos((pos*(options.pulses||5)*2)*Math.PI)/2) + .5);
885
+ };
886
+
887
+ return new Effect.Opacity(element,
888
+ Object.extend(Object.extend({ duration: 2.0, from: 0,
889
+ afterFinishInternal: function(effect) { effect.element.setStyle({opacity: oldOpacity}); }
890
+ }, options), {transition: reverser}));
891
+ };
892
+
893
+ Effect.Fold = function(element) {
894
+ element = $(element);
895
+ var oldStyle = {
896
+ top: element.style.top,
897
+ left: element.style.left,
898
+ width: element.style.width,
899
+ height: element.style.height };
900
+ element.makeClipping();
901
+ return new Effect.Scale(element, 5, Object.extend({
902
+ scaleContent: false,
903
+ scaleX: false,
904
+ afterFinishInternal: function(effect) {
905
+ new Effect.Scale(element, 1, {
906
+ scaleContent: false,
907
+ scaleY: false,
908
+ afterFinishInternal: function(effect) {
909
+ effect.element.hide().undoClipping().setStyle(oldStyle);
910
+ } });
911
+ }}, arguments[1] || { }));
912
+ };
913
+
914
+ Effect.Morph = Class.create(Effect.Base, {
915
+ initialize: function(element) {
916
+ this.element = $(element);
917
+ if (!this.element) throw(Effect._elementDoesNotExistError);
918
+ var options = Object.extend({
919
+ style: { }
920
+ }, arguments[1] || { });
921
+
922
+ if (!Object.isString(options.style)) this.style = $H(options.style);
923
+ else {
924
+ if (options.style.include(':'))
925
+ this.style = options.style.parseStyle();
926
+ else {
927
+ this.element.addClassName(options.style);
928
+ this.style = $H(this.element.getStyles());
929
+ this.element.removeClassName(options.style);
930
+ var css = this.element.getStyles();
931
+ this.style = this.style.reject(function(style) {
932
+ return style.value == css[style.key];
933
+ });
934
+ options.afterFinishInternal = function(effect) {
935
+ effect.element.addClassName(effect.options.style);
936
+ effect.transforms.each(function(transform) {
937
+ effect.element.style[transform.style] = '';
938
+ });
939
+ };
940
+ }
941
+ }
942
+ this.start(options);
943
+ },
944
+
945
+ setup: function(){
946
+ function parseColor(color){
947
+ if (!color || ['rgba(0, 0, 0, 0)','transparent'].include(color)) color = '#ffffff';
948
+ color = color.parseColor();
949
+ return $R(0,2).map(function(i){
950
+ return parseInt( color.slice(i*2+1,i*2+3), 16 );
951
+ });
952
+ }
953
+ this.transforms = this.style.map(function(pair){
954
+ var property = pair[0], value = pair[1], unit = null;
955
+
956
+ if (value.parseColor('#zzzzzz') != '#zzzzzz') {
957
+ value = value.parseColor();
958
+ unit = 'color';
959
+ } else if (property == 'opacity') {
960
+ value = parseFloat(value);
961
+ if (Prototype.Browser.IE && (!this.element.currentStyle.hasLayout))
962
+ this.element.setStyle({zoom: 1});
963
+ } else if (Element.CSS_LENGTH.test(value)) {
964
+ var components = value.match(/^([\+\-]?[0-9\.]+)(.*)$/);
965
+ value = parseFloat(components[1]);
966
+ unit = (components.length == 3) ? components[2] : null;
967
+ }
968
+
969
+ var originalValue = this.element.getStyle(property);
970
+ return {
971
+ style: property.camelize(),
972
+ originalValue: unit=='color' ? parseColor(originalValue) : parseFloat(originalValue || 0),
973
+ targetValue: unit=='color' ? parseColor(value) : value,
974
+ unit: unit
975
+ };
976
+ }.bind(this)).reject(function(transform){
977
+ return (
978
+ (transform.originalValue == transform.targetValue) ||
979
+ (
980
+ transform.unit != 'color' &&
981
+ (isNaN(transform.originalValue) || isNaN(transform.targetValue))
982
+ )
983
+ );
984
+ });
985
+ },
986
+ update: function(position) {
987
+ var style = { }, transform, i = this.transforms.length;
988
+ while(i--)
989
+ style[(transform = this.transforms[i]).style] =
990
+ transform.unit=='color' ? '#'+
991
+ (Math.round(transform.originalValue[0]+
992
+ (transform.targetValue[0]-transform.originalValue[0])*position)).toColorPart() +
993
+ (Math.round(transform.originalValue[1]+
994
+ (transform.targetValue[1]-transform.originalValue[1])*position)).toColorPart() +
995
+ (Math.round(transform.originalValue[2]+
996
+ (transform.targetValue[2]-transform.originalValue[2])*position)).toColorPart() :
997
+ (transform.originalValue +
998
+ (transform.targetValue - transform.originalValue) * position).toFixed(3) +
999
+ (transform.unit === null ? '' : transform.unit);
1000
+ this.element.setStyle(style, true);
1001
+ }
1002
+ });
1003
+
1004
+ Effect.Transform = Class.create({
1005
+ initialize: function(tracks){
1006
+ this.tracks = [];
1007
+ this.options = arguments[1] || { };
1008
+ this.addTracks(tracks);
1009
+ },
1010
+ addTracks: function(tracks){
1011
+ tracks.each(function(track){
1012
+ track = $H(track);
1013
+ var data = track.values().first();
1014
+ this.tracks.push($H({
1015
+ ids: track.keys().first(),
1016
+ effect: Effect.Morph,
1017
+ options: { style: data }
1018
+ }));
1019
+ }.bind(this));
1020
+ return this;
1021
+ },
1022
+ play: function(){
1023
+ return new Effect.Parallel(
1024
+ this.tracks.map(function(track){
1025
+ var ids = track.get('ids'), effect = track.get('effect'), options = track.get('options');
1026
+ var elements = [$(ids) || $$(ids)].flatten();
1027
+ return elements.map(function(e){ return new effect(e, Object.extend({ sync:true }, options)) });
1028
+ }).flatten(),
1029
+ this.options
1030
+ );
1031
+ }
1032
+ });
1033
+
1034
+ Element.CSS_PROPERTIES = $w(
1035
+ 'backgroundColor backgroundPosition borderBottomColor borderBottomStyle ' +
1036
+ 'borderBottomWidth borderLeftColor borderLeftStyle borderLeftWidth ' +
1037
+ 'borderRightColor borderRightStyle borderRightWidth borderSpacing ' +
1038
+ 'borderTopColor borderTopStyle borderTopWidth bottom clip color ' +
1039
+ 'fontSize fontWeight height left letterSpacing lineHeight ' +
1040
+ 'marginBottom marginLeft marginRight marginTop markerOffset maxHeight '+
1041
+ 'maxWidth minHeight minWidth opacity outlineColor outlineOffset ' +
1042
+ 'outlineWidth paddingBottom paddingLeft paddingRight paddingTop ' +
1043
+ 'right textIndent top width wordSpacing zIndex');
1044
+
1045
+ Element.CSS_LENGTH = /^(([\+\-]?[0-9\.]+)(em|ex|px|in|cm|mm|pt|pc|\%))|0$/;
1046
+
1047
+ String.__parseStyleElement = document.createElement('div');
1048
+ String.prototype.parseStyle = function(){
1049
+ var style, styleRules = $H();
1050
+ if (Prototype.Browser.WebKit)
1051
+ style = new Element('div',{style:this}).style;
1052
+ else {
1053
+ String.__parseStyleElement.innerHTML = '<div style="' + this + '"></div>';
1054
+ style = String.__parseStyleElement.childNodes[0].style;
1055
+ }
1056
+
1057
+ Element.CSS_PROPERTIES.each(function(property){
1058
+ if (style[property]) styleRules.set(property, style[property]);
1059
+ });
1060
+
1061
+ if (Prototype.Browser.IE && this.include('opacity'))
1062
+ styleRules.set('opacity', this.match(/opacity:\s*((?:0|1)?(?:\.\d*)?)/)[1]);
1063
+
1064
+ return styleRules;
1065
+ };
1066
+
1067
+ if (document.defaultView && document.defaultView.getComputedStyle) {
1068
+ Element.getStyles = function(element) {
1069
+ var css = document.defaultView.getComputedStyle($(element), null);
1070
+ return Element.CSS_PROPERTIES.inject({ }, function(styles, property) {
1071
+ styles[property] = css[property];
1072
+ return styles;
1073
+ });
1074
+ };
1075
+ } else {
1076
+ Element.getStyles = function(element) {
1077
+ element = $(element);
1078
+ var css = element.currentStyle, styles;
1079
+ styles = Element.CSS_PROPERTIES.inject({ }, function(results, property) {
1080
+ results[property] = css[property];
1081
+ return results;
1082
+ });
1083
+ if (!styles.opacity) styles.opacity = element.getOpacity();
1084
+ return styles;
1085
+ };
1086
+ }
1087
+
1088
+ Effect.Methods = {
1089
+ morph: function(element, style) {
1090
+ element = $(element);
1091
+ new Effect.Morph(element, Object.extend({ style: style }, arguments[2] || { }));
1092
+ return element;
1093
+ },
1094
+ visualEffect: function(element, effect, options) {
1095
+ element = $(element);
1096
+ var s = effect.dasherize().camelize(), klass = s.charAt(0).toUpperCase() + s.substring(1);
1097
+ new Effect[klass](element, options);
1098
+ return element;
1099
+ },
1100
+ highlight: function(element, options) {
1101
+ element = $(element);
1102
+ new Effect.Highlight(element, options);
1103
+ return element;
1104
+ }
1105
+ };
1106
+
1107
+ $w('fade appear grow shrink fold blindUp blindDown slideUp slideDown '+
1108
+ 'pulsate shake puff squish switchOff dropOut').each(
1109
+ function(effect) {
1110
+ Effect.Methods[effect] = function(element, options){
1111
+ element = $(element);
1112
+ Effect[effect.charAt(0).toUpperCase() + effect.substring(1)](element, options);
1113
+ return element;
1114
+ };
1115
+ }
1116
+ );
1117
+
1118
+ $w('getInlineOpacity forceRerendering setContentZoom collectTextNodes collectTextNodesIgnoreClass getStyles').each(
1119
+ function(f) { Effect.Methods[f] = Element[f]; }
1120
+ );
1121
+
1122
+ Element.addMethods(Effect.Methods);