bio 0.7.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. data/bin/bioruby +71 -27
  2. data/bin/br_biofetch.rb +5 -17
  3. data/bin/br_bioflat.rb +14 -26
  4. data/bin/br_biogetseq.rb +6 -18
  5. data/bin/br_pmfetch.rb +6 -16
  6. data/doc/Changes-0.7.rd +35 -0
  7. data/doc/KEGG_API.rd +287 -172
  8. data/doc/KEGG_API.rd.ja +273 -160
  9. data/doc/Tutorial.rd +18 -9
  10. data/doc/Tutorial.rd.ja +656 -138
  11. data/lib/bio.rb +6 -24
  12. data/lib/bio/alignment.rb +5 -5
  13. data/lib/bio/appl/blast.rb +132 -98
  14. data/lib/bio/appl/blast/format0.rb +9 -19
  15. data/lib/bio/appl/blast/wublast.rb +5 -18
  16. data/lib/bio/appl/emboss.rb +40 -47
  17. data/lib/bio/appl/hmmer.rb +116 -82
  18. data/lib/bio/appl/hmmer/report.rb +509 -364
  19. data/lib/bio/appl/spidey/report.rb +7 -18
  20. data/lib/bio/data/na.rb +3 -21
  21. data/lib/bio/db.rb +3 -21
  22. data/lib/bio/db/aaindex.rb +147 -52
  23. data/lib/bio/db/embl/common.rb +27 -6
  24. data/lib/bio/db/embl/embl.rb +18 -10
  25. data/lib/bio/db/embl/sptr.rb +87 -67
  26. data/lib/bio/db/embl/swissprot.rb +32 -3
  27. data/lib/bio/db/embl/trembl.rb +32 -3
  28. data/lib/bio/db/embl/uniprot.rb +32 -3
  29. data/lib/bio/db/fasta.rb +327 -289
  30. data/lib/bio/db/medline.rb +25 -4
  31. data/lib/bio/db/nbrf.rb +12 -20
  32. data/lib/bio/db/pdb.rb +4 -1
  33. data/lib/bio/db/pdb/chemicalcomponent.rb +240 -0
  34. data/lib/bio/db/pdb/pdb.rb +13 -8
  35. data/lib/bio/db/rebase.rb +93 -97
  36. data/lib/bio/feature.rb +2 -31
  37. data/lib/bio/io/ddbjxml.rb +167 -139
  38. data/lib/bio/io/fastacmd.rb +89 -56
  39. data/lib/bio/io/flatfile.rb +994 -278
  40. data/lib/bio/io/flatfile/index.rb +257 -194
  41. data/lib/bio/io/flatfile/indexer.rb +37 -29
  42. data/lib/bio/reference.rb +147 -64
  43. data/lib/bio/sequence.rb +57 -417
  44. data/lib/bio/sequence/aa.rb +64 -0
  45. data/lib/bio/sequence/common.rb +175 -0
  46. data/lib/bio/sequence/compat.rb +68 -0
  47. data/lib/bio/sequence/format.rb +134 -0
  48. data/lib/bio/sequence/generic.rb +24 -0
  49. data/lib/bio/sequence/na.rb +189 -0
  50. data/lib/bio/shell.rb +9 -23
  51. data/lib/bio/shell/core.rb +130 -125
  52. data/lib/bio/shell/demo.rb +143 -0
  53. data/lib/bio/shell/{session.rb → interface.rb} +42 -40
  54. data/lib/bio/shell/object.rb +52 -0
  55. data/lib/bio/shell/plugin/codon.rb +4 -22
  56. data/lib/bio/shell/plugin/emboss.rb +23 -0
  57. data/lib/bio/shell/plugin/entry.rb +34 -25
  58. data/lib/bio/shell/plugin/flatfile.rb +5 -23
  59. data/lib/bio/shell/plugin/keggapi.rb +11 -24
  60. data/lib/bio/shell/plugin/midi.rb +5 -23
  61. data/lib/bio/shell/plugin/obda.rb +4 -22
  62. data/lib/bio/shell/plugin/seq.rb +6 -24
  63. data/lib/bio/shell/rails/Rakefile +10 -0
  64. data/lib/bio/shell/rails/app/controllers/application.rb +4 -0
  65. data/lib/bio/shell/rails/app/controllers/shell_controller.rb +94 -0
  66. data/lib/bio/shell/rails/app/helpers/application_helper.rb +3 -0
  67. data/lib/bio/shell/rails/app/models/shell_connection.rb +30 -0
  68. data/lib/bio/shell/rails/app/views/layouts/shell.rhtml +37 -0
  69. data/lib/bio/shell/rails/app/views/shell/history.rhtml +5 -0
  70. data/lib/bio/shell/rails/app/views/shell/index.rhtml +2 -0
  71. data/lib/bio/shell/rails/app/views/shell/show.rhtml +13 -0
  72. data/lib/bio/shell/rails/config/boot.rb +19 -0
  73. data/lib/bio/shell/rails/config/database.yml +85 -0
  74. data/lib/bio/shell/rails/config/environment.rb +53 -0
  75. data/lib/bio/shell/rails/config/environments/development.rb +19 -0
  76. data/lib/bio/shell/rails/config/environments/production.rb +19 -0
  77. data/lib/bio/shell/rails/config/environments/test.rb +19 -0
  78. data/lib/bio/shell/rails/config/routes.rb +19 -0
  79. data/lib/bio/shell/rails/doc/README_FOR_APP +2 -0
  80. data/lib/bio/shell/rails/public/404.html +8 -0
  81. data/lib/bio/shell/rails/public/500.html +8 -0
  82. data/lib/bio/shell/rails/public/dispatch.cgi +10 -0
  83. data/lib/bio/shell/rails/public/dispatch.fcgi +24 -0
  84. data/lib/bio/shell/rails/public/dispatch.rb +10 -0
  85. data/lib/bio/shell/rails/public/favicon.ico +0 -0
  86. data/lib/bio/shell/rails/public/images/icon.png +0 -0
  87. data/lib/bio/shell/rails/public/images/rails.png +0 -0
  88. data/lib/bio/shell/rails/public/index.html +277 -0
  89. data/lib/bio/shell/rails/public/javascripts/controls.js +750 -0
  90. data/lib/bio/shell/rails/public/javascripts/dragdrop.js +584 -0
  91. data/lib/bio/shell/rails/public/javascripts/effects.js +854 -0
  92. data/lib/bio/shell/rails/public/javascripts/prototype.js +1785 -0
  93. data/lib/bio/shell/rails/public/robots.txt +1 -0
  94. data/lib/bio/shell/rails/public/stylesheets/main.css +187 -0
  95. data/lib/bio/shell/rails/script/about +3 -0
  96. data/lib/bio/shell/rails/script/breakpointer +3 -0
  97. data/lib/bio/shell/rails/script/console +3 -0
  98. data/lib/bio/shell/rails/script/destroy +3 -0
  99. data/lib/bio/shell/rails/script/generate +3 -0
  100. data/lib/bio/shell/rails/script/performance/benchmarker +3 -0
  101. data/lib/bio/shell/rails/script/performance/profiler +3 -0
  102. data/lib/bio/shell/rails/script/plugin +3 -0
  103. data/lib/bio/shell/rails/script/process/reaper +3 -0
  104. data/lib/bio/shell/rails/script/process/spawner +3 -0
  105. data/lib/bio/shell/rails/script/process/spinner +3 -0
  106. data/lib/bio/shell/rails/script/runner +3 -0
  107. data/lib/bio/shell/rails/script/server +42 -0
  108. data/lib/bio/shell/rails/test/test_helper.rb +28 -0
  109. data/lib/bio/shell/web.rb +90 -0
  110. data/lib/bio/util/contingency_table.rb +231 -225
  111. data/sample/any2fasta.rb +59 -0
  112. data/test/data/HMMER/hmmpfam.out +64 -0
  113. data/test/data/HMMER/hmmsearch.out +88 -0
  114. data/test/data/aaindex/DAYM780301 +30 -0
  115. data/test/data/aaindex/PRAM900102 +20 -0
  116. data/test/data/bl2seq/cd8a_cd8b_blastp.bl2seq +53 -0
  117. data/test/data/bl2seq/cd8a_p53_e-5blastp.bl2seq +37 -0
  118. data/test/data/blast/{eco:b0002.faa → b0002.faa} +0 -0
  119. data/test/data/blast/{eco:b0002.faa.m0 → b0002.faa.m0} +2 -2
  120. data/test/data/blast/{eco:b0002.faa.m7 → b0002.faa.m7} +1 -1
  121. data/test/data/blast/{eco:b0002.faa.m8 → b0002.faa.m8} +0 -0
  122. data/test/unit/bio/appl/bl2seq/test_report.rb +134 -0
  123. data/test/unit/bio/appl/blast/test_report.rb +15 -12
  124. data/test/unit/bio/appl/blast/test_xmlparser.rb +4 -4
  125. data/test/unit/bio/appl/hmmer/test_report.rb +355 -0
  126. data/test/unit/bio/appl/test_blast.rb +5 -5
  127. data/test/unit/bio/data/test_na.rb +9 -18
  128. data/test/unit/bio/db/pdb/test_pdb.rb +169 -0
  129. data/test/unit/bio/db/test_aaindex.rb +197 -0
  130. data/test/unit/bio/io/test_fastacmd.rb +55 -0
  131. data/test/unit/bio/sequence/test_aa.rb +102 -0
  132. data/test/unit/bio/sequence/test_common.rb +178 -0
  133. data/test/unit/bio/sequence/test_compat.rb +82 -0
  134. data/test/unit/bio/sequence/test_na.rb +242 -0
  135. data/test/unit/bio/shell/plugin/test_seq.rb +29 -19
  136. data/test/unit/bio/test_alignment.rb +15 -7
  137. data/test/unit/bio/test_reference.rb +198 -0
  138. data/test/unit/bio/test_sequence.rb +4 -49
  139. data/test/unit/bio/test_shell.rb +2 -2
  140. metadata +118 -15
  141. data/lib/bio/io/brdb.rb +0 -103
  142. data/lib/bioruby.rb +0 -34
@@ -0,0 +1,854 @@
1
+ // Copyright (c) 2005 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
+ // See scriptaculous.js for full license.
8
+
9
+ /* ------------- element ext -------------- */
10
+
11
+ // converts rgb() and #xxx to #xxxxxx format,
12
+ // returns self (or first argument) if not convertable
13
+ String.prototype.parseColor = function() {
14
+ var color = '#';
15
+ if(this.slice(0,4) == 'rgb(') {
16
+ var cols = this.slice(4,this.length-1).split(',');
17
+ var i=0; do { color += parseInt(cols[i]).toColorPart() } while (++i<3);
18
+ } else {
19
+ if(this.slice(0,1) == '#') {
20
+ if(this.length==4) for(var i=1;i<4;i++) color += (this.charAt(i) + this.charAt(i)).toLowerCase();
21
+ if(this.length==7) color = this.toLowerCase();
22
+ }
23
+ }
24
+ return(color.length==7 ? color : (arguments[0] || this));
25
+ }
26
+
27
+ Element.collectTextNodesIgnoreClass = function(element, ignoreclass) {
28
+ var children = $(element).childNodes;
29
+ var text = '';
30
+ var classtest = new RegExp('^([^ ]+ )*' + ignoreclass+ '( [^ ]+)*$','i');
31
+
32
+ for (var i = 0; i < children.length; i++) {
33
+ if(children[i].nodeType==3) {
34
+ text+=children[i].nodeValue;
35
+ } else {
36
+ if((!children[i].className.match(classtest)) && children[i].hasChildNodes())
37
+ text += Element.collectTextNodesIgnoreClass(children[i], ignoreclass);
38
+ }
39
+ }
40
+
41
+ return text;
42
+ }
43
+
44
+ Element.setStyle = function(element, style) {
45
+ element = $(element);
46
+ for(k in style) element.style[k.camelize()] = style[k];
47
+ }
48
+
49
+ Element.setContentZoom = function(element, percent) {
50
+ Element.setStyle(element, {fontSize: (percent/100) + 'em'});
51
+ if(navigator.appVersion.indexOf('AppleWebKit')>0) window.scrollBy(0,0);
52
+ }
53
+
54
+ Element.getOpacity = function(element){
55
+ var opacity;
56
+ if (opacity = Element.getStyle(element, 'opacity'))
57
+ return parseFloat(opacity);
58
+ if (opacity = (Element.getStyle(element, 'filter') || '').match(/alpha\(opacity=(.*)\)/))
59
+ if(opacity[1]) return parseFloat(opacity[1]) / 100;
60
+ return 1.0;
61
+ }
62
+
63
+ Element.setOpacity = function(element, value){
64
+ element= $(element);
65
+ if (value == 1){
66
+ Element.setStyle(element, { opacity:
67
+ (/Gecko/.test(navigator.userAgent) && !/Konqueror|Safari|KHTML/.test(navigator.userAgent)) ?
68
+ 0.999999 : null });
69
+ if(/MSIE/.test(navigator.userAgent))
70
+ Element.setStyle(element, {filter: Element.getStyle(element,'filter').replace(/alpha\([^\)]*\)/gi,'')});
71
+ } else {
72
+ if(value < 0.00001) value = 0;
73
+ Element.setStyle(element, {opacity: value});
74
+ if(/MSIE/.test(navigator.userAgent))
75
+ Element.setStyle(element,
76
+ { filter: Element.getStyle(element,'filter').replace(/alpha\([^\)]*\)/gi,'') +
77
+ 'alpha(opacity='+value*100+')' });
78
+ }
79
+ }
80
+
81
+ Element.getInlineOpacity = function(element){
82
+ return $(element).style.opacity || '';
83
+ }
84
+
85
+ Element.childrenWithClassName = function(element, className) {
86
+ return $A($(element).getElementsByTagName('*')).select(
87
+ function(c) { return Element.hasClassName(c, className) });
88
+ }
89
+
90
+ Array.prototype.call = function() {
91
+ var args = arguments;
92
+ this.each(function(f){ f.apply(this, args) });
93
+ }
94
+
95
+ /*--------------------------------------------------------------------------*/
96
+
97
+ var Effect = {
98
+ tagifyText: function(element) {
99
+ var tagifyStyle = 'position:relative';
100
+ if(/MSIE/.test(navigator.userAgent)) tagifyStyle += ';zoom:1';
101
+ element = $(element);
102
+ $A(element.childNodes).each( function(child) {
103
+ if(child.nodeType==3) {
104
+ child.nodeValue.toArray().each( function(character) {
105
+ element.insertBefore(
106
+ Builder.node('span',{style: tagifyStyle},
107
+ character == ' ' ? String.fromCharCode(160) : character),
108
+ child);
109
+ });
110
+ Element.remove(child);
111
+ }
112
+ });
113
+ },
114
+ multiple: function(element, effect) {
115
+ var elements;
116
+ if(((typeof element == 'object') ||
117
+ (typeof element == 'function')) &&
118
+ (element.length))
119
+ elements = element;
120
+ else
121
+ elements = $(element).childNodes;
122
+
123
+ var options = Object.extend({
124
+ speed: 0.1,
125
+ delay: 0.0
126
+ }, arguments[2] || {});
127
+ var masterDelay = options.delay;
128
+
129
+ $A(elements).each( function(element, index) {
130
+ new effect(element, Object.extend(options, { delay: index * options.speed + masterDelay }));
131
+ });
132
+ }
133
+ };
134
+
135
+ var Effect2 = Effect; // deprecated
136
+
137
+ /* ------------- transitions ------------- */
138
+
139
+ Effect.Transitions = {}
140
+
141
+ Effect.Transitions.linear = function(pos) {
142
+ return pos;
143
+ }
144
+ Effect.Transitions.sinoidal = function(pos) {
145
+ return (-Math.cos(pos*Math.PI)/2) + 0.5;
146
+ }
147
+ Effect.Transitions.reverse = function(pos) {
148
+ return 1-pos;
149
+ }
150
+ Effect.Transitions.flicker = function(pos) {
151
+ return ((-Math.cos(pos*Math.PI)/4) + 0.75) + Math.random()/4;
152
+ }
153
+ Effect.Transitions.wobble = function(pos) {
154
+ return (-Math.cos(pos*Math.PI*(9*pos))/2) + 0.5;
155
+ }
156
+ Effect.Transitions.pulse = function(pos) {
157
+ return (Math.floor(pos*10) % 2 == 0 ?
158
+ (pos*10-Math.floor(pos*10)) : 1-(pos*10-Math.floor(pos*10)));
159
+ }
160
+ Effect.Transitions.none = function(pos) {
161
+ return 0;
162
+ }
163
+ Effect.Transitions.full = function(pos) {
164
+ return 1;
165
+ }
166
+
167
+ /* ------------- core effects ------------- */
168
+
169
+ Effect.Queue = {
170
+ effects: [],
171
+ _each: function(iterator) {
172
+ this.effects._each(iterator);
173
+ },
174
+ interval: null,
175
+ add: function(effect) {
176
+ var timestamp = new Date().getTime();
177
+
178
+ switch(effect.options.queue) {
179
+ case 'front':
180
+ // move unstarted effects after this effect
181
+ this.effects.findAll(function(e){ return e.state=='idle' }).each( function(e) {
182
+ e.startOn += effect.finishOn;
183
+ e.finishOn += effect.finishOn;
184
+ });
185
+ break;
186
+ case 'end':
187
+ // start effect after last queued effect has finished
188
+ timestamp = this.effects.pluck('finishOn').max() || timestamp;
189
+ break;
190
+ }
191
+
192
+ effect.startOn += timestamp;
193
+ effect.finishOn += timestamp;
194
+ this.effects.push(effect);
195
+ if(!this.interval)
196
+ this.interval = setInterval(this.loop.bind(this), 40);
197
+ },
198
+ remove: function(effect) {
199
+ this.effects = this.effects.reject(function(e) { return e==effect });
200
+ if(this.effects.length == 0) {
201
+ clearInterval(this.interval);
202
+ this.interval = null;
203
+ }
204
+ },
205
+ loop: function() {
206
+ var timePos = new Date().getTime();
207
+ this.effects.invoke('loop', timePos);
208
+ }
209
+ }
210
+ Object.extend(Effect.Queue, Enumerable);
211
+
212
+ Effect.Base = function() {};
213
+ Effect.Base.prototype = {
214
+ position: null,
215
+ setOptions: function(options) {
216
+ this.options = Object.extend({
217
+ transition: Effect.Transitions.sinoidal,
218
+ duration: 1.0, // seconds
219
+ fps: 25.0, // max. 25fps due to Effect.Queue implementation
220
+ sync: false, // true for combining
221
+ from: 0.0,
222
+ to: 1.0,
223
+ delay: 0.0,
224
+ queue: 'parallel'
225
+ }, options || {});
226
+ },
227
+ start: function(options) {
228
+ this.setOptions(options || {});
229
+ this.currentFrame = 0;
230
+ this.state = 'idle';
231
+ this.startOn = this.options.delay*1000;
232
+ this.finishOn = this.startOn + (this.options.duration*1000);
233
+ this.event('beforeStart');
234
+ if(!this.options.sync) Effect.Queue.add(this);
235
+ },
236
+ loop: function(timePos) {
237
+ if(timePos >= this.startOn) {
238
+ if(timePos >= this.finishOn) {
239
+ this.render(1.0);
240
+ this.cancel();
241
+ this.event('beforeFinish');
242
+ if(this.finish) this.finish();
243
+ this.event('afterFinish');
244
+ return;
245
+ }
246
+ var pos = (timePos - this.startOn) / (this.finishOn - this.startOn);
247
+ var frame = Math.round(pos * this.options.fps * this.options.duration);
248
+ if(frame > this.currentFrame) {
249
+ this.render(pos);
250
+ this.currentFrame = frame;
251
+ }
252
+ }
253
+ },
254
+ render: function(pos) {
255
+ if(this.state == 'idle') {
256
+ this.state = 'running';
257
+ this.event('beforeSetup');
258
+ if(this.setup) this.setup();
259
+ this.event('afterSetup');
260
+ }
261
+ if(this.state == 'running') {
262
+ if(this.options.transition) pos = this.options.transition(pos);
263
+ pos *= (this.options.to-this.options.from);
264
+ pos += this.options.from;
265
+ this.position = pos;
266
+ this.event('beforeUpdate');
267
+ if(this.update) this.update(pos);
268
+ this.event('afterUpdate');
269
+ }
270
+ },
271
+ cancel: function() {
272
+ if(!this.options.sync) Effect.Queue.remove(this);
273
+ this.state = 'finished';
274
+ },
275
+ event: function(eventName) {
276
+ if(this.options[eventName + 'Internal']) this.options[eventName + 'Internal'](this);
277
+ if(this.options[eventName]) this.options[eventName](this);
278
+ },
279
+ inspect: function() {
280
+ return '#<Effect:' + $H(this).inspect() + ',options:' + $H(this.options).inspect() + '>';
281
+ }
282
+ }
283
+
284
+ Effect.Parallel = Class.create();
285
+ Object.extend(Object.extend(Effect.Parallel.prototype, Effect.Base.prototype), {
286
+ initialize: function(effects) {
287
+ this.effects = effects || [];
288
+ this.start(arguments[1]);
289
+ },
290
+ update: function(position) {
291
+ this.effects.invoke('render', position);
292
+ },
293
+ finish: function(position) {
294
+ this.effects.each( function(effect) {
295
+ effect.render(1.0);
296
+ effect.cancel();
297
+ effect.event('beforeFinish');
298
+ if(effect.finish) effect.finish(position);
299
+ effect.event('afterFinish');
300
+ });
301
+ }
302
+ });
303
+
304
+ Effect.Opacity = Class.create();
305
+ Object.extend(Object.extend(Effect.Opacity.prototype, Effect.Base.prototype), {
306
+ initialize: function(element) {
307
+ this.element = $(element);
308
+ // make this work on IE on elements without 'layout'
309
+ if(/MSIE/.test(navigator.userAgent) && (!this.element.hasLayout))
310
+ Element.setStyle(this.element, {zoom: 1});
311
+ var options = Object.extend({
312
+ from: Element.getOpacity(this.element) || 0.0,
313
+ to: 1.0
314
+ }, arguments[1] || {});
315
+ this.start(options);
316
+ },
317
+ update: function(position) {
318
+ Element.setOpacity(this.element, position);
319
+ }
320
+ });
321
+
322
+ Effect.MoveBy = Class.create();
323
+ Object.extend(Object.extend(Effect.MoveBy.prototype, Effect.Base.prototype), {
324
+ initialize: function(element, toTop, toLeft) {
325
+ this.element = $(element);
326
+ this.toTop = toTop;
327
+ this.toLeft = toLeft;
328
+ this.start(arguments[3]);
329
+ },
330
+ setup: function() {
331
+ // Bug in Opera: Opera returns the "real" position of a static element or
332
+ // relative element that does not have top/left explicitly set.
333
+ // ==> Always set top and left for position relative elements in your stylesheets
334
+ // (to 0 if you do not need them)
335
+ Element.makePositioned(this.element);
336
+ this.originalTop = parseFloat(Element.getStyle(this.element,'top') || '0');
337
+ this.originalLeft = parseFloat(Element.getStyle(this.element,'left') || '0');
338
+ },
339
+ update: function(position) {
340
+ Element.setStyle(this.element, {
341
+ top: this.toTop * position + this.originalTop + 'px',
342
+ left: this.toLeft * position + this.originalLeft + 'px'
343
+ });
344
+ }
345
+ });
346
+
347
+ Effect.Scale = Class.create();
348
+ Object.extend(Object.extend(Effect.Scale.prototype, Effect.Base.prototype), {
349
+ initialize: function(element, percent) {
350
+ this.element = $(element)
351
+ var options = Object.extend({
352
+ scaleX: true,
353
+ scaleY: true,
354
+ scaleContent: true,
355
+ scaleFromCenter: false,
356
+ scaleMode: 'box', // 'box' or 'contents' or {} with provided values
357
+ scaleFrom: 100.0,
358
+ scaleTo: percent
359
+ }, arguments[2] || {});
360
+ this.start(options);
361
+ },
362
+ setup: function() {
363
+ this.restoreAfterFinish = this.options.restoreAfterFinish || false;
364
+ this.elementPositioning = Element.getStyle(this.element,'position');
365
+
366
+ this.originalStyle = {};
367
+ ['top','left','width','height','fontSize'].each( function(k) {
368
+ this.originalStyle[k] = this.element.style[k];
369
+ }.bind(this));
370
+
371
+ this.originalTop = this.element.offsetTop;
372
+ this.originalLeft = this.element.offsetLeft;
373
+
374
+ var fontSize = Element.getStyle(this.element,'font-size') || '100%';
375
+ ['em','px','%'].each( function(fontSizeType) {
376
+ if(fontSize.indexOf(fontSizeType)>0) {
377
+ this.fontSize = parseFloat(fontSize);
378
+ this.fontSizeType = fontSizeType;
379
+ }
380
+ }.bind(this));
381
+
382
+ this.factor = (this.options.scaleTo - this.options.scaleFrom)/100;
383
+
384
+ this.dims = null;
385
+ if(this.options.scaleMode=='box')
386
+ this.dims = [this.element.offsetHeight, this.element.offsetWidth];
387
+ if(/^content/.test(this.options.scaleMode))
388
+ this.dims = [this.element.scrollHeight, this.element.scrollWidth];
389
+ if(!this.dims)
390
+ this.dims = [this.options.scaleMode.originalHeight,
391
+ this.options.scaleMode.originalWidth];
392
+ },
393
+ update: function(position) {
394
+ var currentScale = (this.options.scaleFrom/100.0) + (this.factor * position);
395
+ if(this.options.scaleContent && this.fontSize)
396
+ Element.setStyle(this.element, {fontSize: this.fontSize * currentScale + this.fontSizeType });
397
+ this.setDimensions(this.dims[0] * currentScale, this.dims[1] * currentScale);
398
+ },
399
+ finish: function(position) {
400
+ if (this.restoreAfterFinish) Element.setStyle(this.element, this.originalStyle);
401
+ },
402
+ setDimensions: function(height, width) {
403
+ var d = {};
404
+ if(this.options.scaleX) d.width = width + 'px';
405
+ if(this.options.scaleY) d.height = height + 'px';
406
+ if(this.options.scaleFromCenter) {
407
+ var topd = (height - this.dims[0])/2;
408
+ var leftd = (width - this.dims[1])/2;
409
+ if(this.elementPositioning == 'absolute') {
410
+ if(this.options.scaleY) d.top = this.originalTop-topd + 'px';
411
+ if(this.options.scaleX) d.left = this.originalLeft-leftd + 'px';
412
+ } else {
413
+ if(this.options.scaleY) d.top = -topd + 'px';
414
+ if(this.options.scaleX) d.left = -leftd + 'px';
415
+ }
416
+ }
417
+ Element.setStyle(this.element, d);
418
+ }
419
+ });
420
+
421
+ Effect.Highlight = Class.create();
422
+ Object.extend(Object.extend(Effect.Highlight.prototype, Effect.Base.prototype), {
423
+ initialize: function(element) {
424
+ this.element = $(element);
425
+ var options = Object.extend({ startcolor: '#ffff99' }, arguments[1] || {});
426
+ this.start(options);
427
+ },
428
+ setup: function() {
429
+ // Prevent executing on elements not in the layout flow
430
+ if(Element.getStyle(this.element, 'display')=='none') { this.cancel(); return; }
431
+ // Disable background image during the effect
432
+ this.oldStyle = {
433
+ backgroundImage: Element.getStyle(this.element, 'background-image') };
434
+ Element.setStyle(this.element, {backgroundImage: 'none'});
435
+ if(!this.options.endcolor)
436
+ this.options.endcolor = Element.getStyle(this.element, 'background-color').parseColor('#ffffff');
437
+ if(!this.options.restorecolor)
438
+ this.options.restorecolor = Element.getStyle(this.element, 'background-color');
439
+ // init color calculations
440
+ this._base = $R(0,2).map(function(i){ return parseInt(this.options.startcolor.slice(i*2+1,i*2+3),16) }.bind(this));
441
+ 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));
442
+ },
443
+ update: function(position) {
444
+ Element.setStyle(this.element,{backgroundColor: $R(0,2).inject('#',function(m,v,i){
445
+ return m+(Math.round(this._base[i]+(this._delta[i]*position)).toColorPart()); }.bind(this)) });
446
+ },
447
+ finish: function() {
448
+ Element.setStyle(this.element, Object.extend(this.oldStyle, {
449
+ backgroundColor: this.options.restorecolor
450
+ }));
451
+ }
452
+ });
453
+
454
+ Effect.ScrollTo = Class.create();
455
+ Object.extend(Object.extend(Effect.ScrollTo.prototype, Effect.Base.prototype), {
456
+ initialize: function(element) {
457
+ this.element = $(element);
458
+ this.start(arguments[1] || {});
459
+ },
460
+ setup: function() {
461
+ Position.prepare();
462
+ var offsets = Position.cumulativeOffset(this.element);
463
+ if(this.options.offset) offsets[1] += this.options.offset;
464
+ var max = window.innerHeight ?
465
+ window.height - window.innerHeight :
466
+ document.body.scrollHeight -
467
+ (document.documentElement.clientHeight ?
468
+ document.documentElement.clientHeight : document.body.clientHeight);
469
+ this.scrollStart = Position.deltaY;
470
+ this.delta = (offsets[1] > max ? max : offsets[1]) - this.scrollStart;
471
+ },
472
+ update: function(position) {
473
+ Position.prepare();
474
+ window.scrollTo(Position.deltaX,
475
+ this.scrollStart + (position*this.delta));
476
+ }
477
+ });
478
+
479
+ /* ------------- combination effects ------------- */
480
+
481
+ Effect.Fade = function(element) {
482
+ var oldOpacity = Element.getInlineOpacity(element);
483
+ var options = Object.extend({
484
+ from: Element.getOpacity(element) || 1.0,
485
+ to: 0.0,
486
+ afterFinishInternal: function(effect) { with(Element) {
487
+ if(effect.options.to!=0) return;
488
+ hide(effect.element);
489
+ setStyle(effect.element, {opacity: oldOpacity}); }}
490
+ }, arguments[1] || {});
491
+ return new Effect.Opacity(element,options);
492
+ }
493
+
494
+ Effect.Appear = function(element) {
495
+ var options = Object.extend({
496
+ from: (Element.getStyle(element, 'display') == 'none' ? 0.0 : Element.getOpacity(element) || 0.0),
497
+ to: 1.0,
498
+ beforeSetup: function(effect) { with(Element) {
499
+ setOpacity(effect.element, effect.options.from);
500
+ show(effect.element); }}
501
+ }, arguments[1] || {});
502
+ return new Effect.Opacity(element,options);
503
+ }
504
+
505
+ Effect.Puff = function(element) {
506
+ element = $(element);
507
+ var oldStyle = { opacity: Element.getInlineOpacity(element), position: Element.getStyle(element, 'position') };
508
+ return new Effect.Parallel(
509
+ [ new Effect.Scale(element, 200,
510
+ { sync: true, scaleFromCenter: true, scaleContent: true, restoreAfterFinish: true }),
511
+ new Effect.Opacity(element, { sync: true, to: 0.0 } ) ],
512
+ Object.extend({ duration: 1.0,
513
+ beforeSetupInternal: function(effect) { with(Element) {
514
+ setStyle(effect.effects[0].element, {position: 'absolute'}); }},
515
+ afterFinishInternal: function(effect) { with(Element) {
516
+ hide(effect.effects[0].element);
517
+ setStyle(effect.effects[0].element, oldStyle); }}
518
+ }, arguments[1] || {})
519
+ );
520
+ }
521
+
522
+ Effect.BlindUp = function(element) {
523
+ element = $(element);
524
+ Element.makeClipping(element);
525
+ return new Effect.Scale(element, 0,
526
+ Object.extend({ scaleContent: false,
527
+ scaleX: false,
528
+ restoreAfterFinish: true,
529
+ afterFinishInternal: function(effect) { with(Element) {
530
+ [hide, undoClipping].call(effect.element); }}
531
+ }, arguments[1] || {})
532
+ );
533
+ }
534
+
535
+ Effect.BlindDown = function(element) {
536
+ element = $(element);
537
+ var oldHeight = Element.getStyle(element, 'height');
538
+ var elementDimensions = Element.getDimensions(element);
539
+ return new Effect.Scale(element, 100,
540
+ Object.extend({ scaleContent: false,
541
+ scaleX: false,
542
+ scaleFrom: 0,
543
+ scaleMode: {originalHeight: elementDimensions.height, originalWidth: elementDimensions.width},
544
+ restoreAfterFinish: true,
545
+ afterSetup: function(effect) { with(Element) {
546
+ makeClipping(effect.element);
547
+ setStyle(effect.element, {height: '0px'});
548
+ show(effect.element);
549
+ }},
550
+ afterFinishInternal: function(effect) { with(Element) {
551
+ undoClipping(effect.element);
552
+ setStyle(effect.element, {height: oldHeight});
553
+ }}
554
+ }, arguments[1] || {})
555
+ );
556
+ }
557
+
558
+ Effect.SwitchOff = function(element) {
559
+ element = $(element);
560
+ var oldOpacity = Element.getInlineOpacity(element);
561
+ return new Effect.Appear(element, {
562
+ duration: 0.4,
563
+ from: 0,
564
+ transition: Effect.Transitions.flicker,
565
+ afterFinishInternal: function(effect) {
566
+ new Effect.Scale(effect.element, 1, {
567
+ duration: 0.3, scaleFromCenter: true,
568
+ scaleX: false, scaleContent: false, restoreAfterFinish: true,
569
+ beforeSetup: function(effect) { with(Element) {
570
+ [makePositioned,makeClipping].call(effect.element);
571
+ }},
572
+ afterFinishInternal: function(effect) { with(Element) {
573
+ [hide,undoClipping,undoPositioned].call(effect.element);
574
+ setStyle(effect.element, {opacity: oldOpacity});
575
+ }}
576
+ })
577
+ }
578
+ });
579
+ }
580
+
581
+ Effect.DropOut = function(element) {
582
+ element = $(element);
583
+ var oldStyle = {
584
+ top: Element.getStyle(element, 'top'),
585
+ left: Element.getStyle(element, 'left'),
586
+ opacity: Element.getInlineOpacity(element) };
587
+ return new Effect.Parallel(
588
+ [ new Effect.MoveBy(element, 100, 0, { sync: true }),
589
+ new Effect.Opacity(element, { sync: true, to: 0.0 }) ],
590
+ Object.extend(
591
+ { duration: 0.5,
592
+ beforeSetup: function(effect) { with(Element) {
593
+ makePositioned(effect.effects[0].element); }},
594
+ afterFinishInternal: function(effect) { with(Element) {
595
+ [hide, undoPositioned].call(effect.effects[0].element);
596
+ setStyle(effect.effects[0].element, oldStyle); }}
597
+ }, arguments[1] || {}));
598
+ }
599
+
600
+ Effect.Shake = function(element) {
601
+ element = $(element);
602
+ var oldStyle = {
603
+ top: Element.getStyle(element, 'top'),
604
+ left: Element.getStyle(element, 'left') };
605
+ return new Effect.MoveBy(element, 0, 20,
606
+ { duration: 0.05, afterFinishInternal: function(effect) {
607
+ new Effect.MoveBy(effect.element, 0, -40,
608
+ { duration: 0.1, afterFinishInternal: function(effect) {
609
+ new Effect.MoveBy(effect.element, 0, 40,
610
+ { duration: 0.1, afterFinishInternal: function(effect) {
611
+ new Effect.MoveBy(effect.element, 0, -40,
612
+ { duration: 0.1, afterFinishInternal: function(effect) {
613
+ new Effect.MoveBy(effect.element, 0, 40,
614
+ { duration: 0.1, afterFinishInternal: function(effect) {
615
+ new Effect.MoveBy(effect.element, 0, -20,
616
+ { duration: 0.05, afterFinishInternal: function(effect) { with(Element) {
617
+ undoPositioned(effect.element);
618
+ setStyle(effect.element, oldStyle);
619
+ }}}) }}) }}) }}) }}) }});
620
+ }
621
+
622
+ Effect.SlideDown = function(element) {
623
+ element = $(element);
624
+ Element.cleanWhitespace(element);
625
+ // SlideDown need to have the content of the element wrapped in a container element with fixed height!
626
+ var oldInnerBottom = Element.getStyle(element.firstChild, 'bottom');
627
+ var elementDimensions = Element.getDimensions(element);
628
+ return new Effect.Scale(element, 100, Object.extend({
629
+ scaleContent: false,
630
+ scaleX: false,
631
+ scaleFrom: 0,
632
+ scaleMode: {originalHeight: elementDimensions.height, originalWidth: elementDimensions.width},
633
+ restoreAfterFinish: true,
634
+ afterSetup: function(effect) { with(Element) {
635
+ makePositioned(effect.element);
636
+ makePositioned(effect.element.firstChild);
637
+ if(window.opera) setStyle(effect.element, {top: ''});
638
+ makeClipping(effect.element);
639
+ setStyle(effect.element, {height: '0px'});
640
+ show(element); }},
641
+ afterUpdateInternal: function(effect) { with(Element) {
642
+ setStyle(effect.element.firstChild, {bottom:
643
+ (effect.dims[0] - effect.element.clientHeight) + 'px' }); }},
644
+ afterFinishInternal: function(effect) { with(Element) {
645
+ undoClipping(effect.element);
646
+ undoPositioned(effect.element.firstChild);
647
+ undoPositioned(effect.element);
648
+ setStyle(effect.element.firstChild, {bottom: oldInnerBottom}); }}
649
+ }, arguments[1] || {})
650
+ );
651
+ }
652
+
653
+ Effect.SlideUp = function(element) {
654
+ element = $(element);
655
+ Element.cleanWhitespace(element);
656
+ var oldInnerBottom = Element.getStyle(element.firstChild, 'bottom');
657
+ return new Effect.Scale(element, 0,
658
+ Object.extend({ scaleContent: false,
659
+ scaleX: false,
660
+ scaleMode: 'box',
661
+ scaleFrom: 100,
662
+ restoreAfterFinish: true,
663
+ beforeStartInternal: function(effect) { with(Element) {
664
+ makePositioned(effect.element);
665
+ makePositioned(effect.element.firstChild);
666
+ if(window.opera) setStyle(effect.element, {top: ''});
667
+ makeClipping(effect.element);
668
+ show(element); }},
669
+ afterUpdateInternal: function(effect) { with(Element) {
670
+ setStyle(effect.element.firstChild, {bottom:
671
+ (effect.dims[0] - effect.element.clientHeight) + 'px' }); }},
672
+ afterFinishInternal: function(effect) { with(Element) {
673
+ [hide, undoClipping].call(effect.element);
674
+ undoPositioned(effect.element.firstChild);
675
+ undoPositioned(effect.element);
676
+ setStyle(effect.element.firstChild, {bottom: oldInnerBottom}); }}
677
+ }, arguments[1] || {})
678
+ );
679
+ }
680
+
681
+ // Bug in opera makes the TD containing this element expand for a instance after finish
682
+ Effect.Squish = function(element) {
683
+ return new Effect.Scale(element, window.opera ? 1 : 0,
684
+ { restoreAfterFinish: true,
685
+ beforeSetup: function(effect) { with(Element) {
686
+ makeClipping(effect.element); }},
687
+ afterFinishInternal: function(effect) { with(Element) {
688
+ hide(effect.element);
689
+ undoClipping(effect.element); }}
690
+ });
691
+ }
692
+
693
+ Effect.Grow = function(element) {
694
+ element = $(element);
695
+ var options = Object.extend({
696
+ direction: 'center',
697
+ moveTransistion: Effect.Transitions.sinoidal,
698
+ scaleTransition: Effect.Transitions.sinoidal,
699
+ opacityTransition: Effect.Transitions.full
700
+ }, arguments[1] || {});
701
+ var oldStyle = {
702
+ top: element.style.top,
703
+ left: element.style.left,
704
+ height: element.style.height,
705
+ width: element.style.width,
706
+ opacity: Element.getInlineOpacity(element) };
707
+
708
+ var dims = Element.getDimensions(element);
709
+ var initialMoveX, initialMoveY;
710
+ var moveX, moveY;
711
+
712
+ switch (options.direction) {
713
+ case 'top-left':
714
+ initialMoveX = initialMoveY = moveX = moveY = 0;
715
+ break;
716
+ case 'top-right':
717
+ initialMoveX = dims.width;
718
+ initialMoveY = moveY = 0;
719
+ moveX = -dims.width;
720
+ break;
721
+ case 'bottom-left':
722
+ initialMoveX = moveX = 0;
723
+ initialMoveY = dims.height;
724
+ moveY = -dims.height;
725
+ break;
726
+ case 'bottom-right':
727
+ initialMoveX = dims.width;
728
+ initialMoveY = dims.height;
729
+ moveX = -dims.width;
730
+ moveY = -dims.height;
731
+ break;
732
+ case 'center':
733
+ initialMoveX = dims.width / 2;
734
+ initialMoveY = dims.height / 2;
735
+ moveX = -dims.width / 2;
736
+ moveY = -dims.height / 2;
737
+ break;
738
+ }
739
+
740
+ return new Effect.MoveBy(element, initialMoveY, initialMoveX, {
741
+ duration: 0.01,
742
+ beforeSetup: function(effect) { with(Element) {
743
+ hide(effect.element);
744
+ makeClipping(effect.element);
745
+ makePositioned(effect.element);
746
+ }},
747
+ afterFinishInternal: function(effect) {
748
+ new Effect.Parallel(
749
+ [ new Effect.Opacity(effect.element, { sync: true, to: 1.0, from: 0.0, transition: options.opacityTransition }),
750
+ new Effect.MoveBy(effect.element, moveY, moveX, { sync: true, transition: options.moveTransition }),
751
+ new Effect.Scale(effect.element, 100, {
752
+ scaleMode: { originalHeight: dims.height, originalWidth: dims.width },
753
+ sync: true, scaleFrom: window.opera ? 1 : 0, transition: options.scaleTransition, restoreAfterFinish: true})
754
+ ], Object.extend({
755
+ beforeSetup: function(effect) { with(Element) {
756
+ setStyle(effect.effects[0].element, {height: '0px'});
757
+ show(effect.effects[0].element); }},
758
+ afterFinishInternal: function(effect) { with(Element) {
759
+ [undoClipping, undoPositioned].call(effect.effects[0].element);
760
+ setStyle(effect.effects[0].element, oldStyle); }}
761
+ }, options)
762
+ )
763
+ }
764
+ });
765
+ }
766
+
767
+ Effect.Shrink = function(element) {
768
+ element = $(element);
769
+ var options = Object.extend({
770
+ direction: 'center',
771
+ moveTransistion: Effect.Transitions.sinoidal,
772
+ scaleTransition: Effect.Transitions.sinoidal,
773
+ opacityTransition: Effect.Transitions.none
774
+ }, arguments[1] || {});
775
+ var oldStyle = {
776
+ top: element.style.top,
777
+ left: element.style.left,
778
+ height: element.style.height,
779
+ width: element.style.width,
780
+ opacity: Element.getInlineOpacity(element) };
781
+
782
+ var dims = Element.getDimensions(element);
783
+ var moveX, moveY;
784
+
785
+ switch (options.direction) {
786
+ case 'top-left':
787
+ moveX = moveY = 0;
788
+ break;
789
+ case 'top-right':
790
+ moveX = dims.width;
791
+ moveY = 0;
792
+ break;
793
+ case 'bottom-left':
794
+ moveX = 0;
795
+ moveY = dims.height;
796
+ break;
797
+ case 'bottom-right':
798
+ moveX = dims.width;
799
+ moveY = dims.height;
800
+ break;
801
+ case 'center':
802
+ moveX = dims.width / 2;
803
+ moveY = dims.height / 2;
804
+ break;
805
+ }
806
+
807
+ return new Effect.Parallel(
808
+ [ new Effect.Opacity(element, { sync: true, to: 0.0, from: 1.0, transition: options.opacityTransition }),
809
+ new Effect.Scale(element, window.opera ? 1 : 0, { sync: true, transition: options.scaleTransition, restoreAfterFinish: true}),
810
+ new Effect.MoveBy(element, moveY, moveX, { sync: true, transition: options.moveTransition })
811
+ ], Object.extend({
812
+ beforeStartInternal: function(effect) { with(Element) {
813
+ [makePositioned, makeClipping].call(effect.effects[0].element) }},
814
+ afterFinishInternal: function(effect) { with(Element) {
815
+ [hide, undoClipping, undoPositioned].call(effect.effects[0].element);
816
+ setStyle(effect.effects[0].element, oldStyle); }}
817
+ }, options)
818
+ );
819
+ }
820
+
821
+ Effect.Pulsate = function(element) {
822
+ element = $(element);
823
+ var options = arguments[1] || {};
824
+ var oldOpacity = Element.getInlineOpacity(element);
825
+ var transition = options.transition || Effect.Transitions.sinoidal;
826
+ var reverser = function(pos){ return transition(1-Effect.Transitions.pulse(pos)) };
827
+ reverser.bind(transition);
828
+ return new Effect.Opacity(element,
829
+ Object.extend(Object.extend({ duration: 3.0, from: 0,
830
+ afterFinishInternal: function(effect) { Element.setStyle(effect.element, {opacity: oldOpacity}); }
831
+ }, options), {transition: reverser}));
832
+ }
833
+
834
+ Effect.Fold = function(element) {
835
+ element = $(element);
836
+ var oldStyle = {
837
+ top: element.style.top,
838
+ left: element.style.left,
839
+ width: element.style.width,
840
+ height: element.style.height };
841
+ Element.makeClipping(element);
842
+ return new Effect.Scale(element, 5, Object.extend({
843
+ scaleContent: false,
844
+ scaleX: false,
845
+ afterFinishInternal: function(effect) {
846
+ new Effect.Scale(element, 1, {
847
+ scaleContent: false,
848
+ scaleY: false,
849
+ afterFinishInternal: function(effect) { with(Element) {
850
+ [hide, undoClipping].call(effect.element);
851
+ setStyle(effect.element, oldStyle);
852
+ }} });
853
+ }}, arguments[1] || {}));
854
+ }