win_gui 0.1.0

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