Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1 | /* |
| 2 | moo.fx, simple effects library built with prototype.js (http://prototype.conio.net). |
| 3 | by Valerio Proietti (http://mad4milk.net) MIT-style LICENSE. |
| 4 | for more info (http://moofx.mad4milk.net). |
| 5 | 10/24/2005 |
| 6 | v(1.0.2) |
| 7 | */ |
| 8 | |
| 9 | //base |
| 10 | var fx = new Object(); |
| 11 | fx.Base = function(){}; |
| 12 | fx.Base.prototype = { |
| 13 | setOptions: function(options) { |
| 14 | this.options = { |
| 15 | duration: 500, |
| 16 | onComplete: '' |
| 17 | } |
| 18 | Object.extend(this.options, options || {}); |
| 19 | }, |
| 20 | |
| 21 | go: function() { |
| 22 | this.duration = this.options.duration; |
| 23 | this.startTime = (new Date).getTime(); |
| 24 | this.timer = setInterval (this.step.bind(this), 13); |
| 25 | }, |
| 26 | |
| 27 | step: function() { |
| 28 | var time = (new Date).getTime(); |
| 29 | var Tpos = (time - this.startTime) / (this.duration); |
| 30 | if (time >= this.duration+this.startTime) { |
| 31 | this.now = this.to; |
| 32 | clearInterval (this.timer); |
| 33 | this.timer = null; |
| 34 | if (this.options.onComplete) setTimeout(this.options.onComplete.bind(this), 10); |
| 35 | } |
| 36 | else { |
| 37 | this.now = ((-Math.cos(Tpos*Math.PI)/2) + 0.5) * (this.to-this.from) + this.from; |
| 38 | //this time-position, sinoidal transition thing is from script.aculo.us |
| 39 | } |
| 40 | this.increase(); |
| 41 | }, |
| 42 | |
| 43 | custom: function(from, to) { |
| 44 | if (this.timer != null) return; |
| 45 | this.from = from; |
| 46 | this.to = to; |
| 47 | this.go(); |
| 48 | }, |
| 49 | |
| 50 | hide: function() { |
| 51 | this.now = 0; |
| 52 | this.increase(); |
| 53 | }, |
| 54 | |
| 55 | clearTimer: function() { |
| 56 | clearInterval(this.timer); |
| 57 | this.timer = null; |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | //stretchers |
| 62 | fx.Layout = Class.create(); |
| 63 | fx.Layout.prototype = Object.extend(new fx.Base(), { |
| 64 | initialize: function(el, options) { |
| 65 | this.el = $(el); |
| 66 | this.el.style.overflow = "hidden"; |
| 67 | this.el.iniWidth = this.el.offsetWidth; |
| 68 | this.el.iniHeight = this.el.offsetHeight; |
| 69 | this.setOptions(options); |
| 70 | } |
| 71 | }); |
| 72 | |
| 73 | fx.Height = Class.create(); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 74 | Object.extend(Object.extend(fx.Height.prototype, fx.Layout.prototype), { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 75 | increase: function() { |
| 76 | this.el.style.height = this.now + "px"; |
| 77 | }, |
| 78 | |
| 79 | toggle: function() { |
| 80 | if (this.el.offsetHeight > 0) this.custom(this.el.offsetHeight, 0); |
| 81 | else this.custom(0, this.el.scrollHeight); |
| 82 | } |
| 83 | }); |
| 84 | |
| 85 | fx.Width = Class.create(); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 86 | Object.extend(Object.extend(fx.Width.prototype, fx.Layout.prototype), { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 87 | increase: function() { |
| 88 | this.el.style.width = this.now + "px"; |
| 89 | }, |
| 90 | |
| 91 | toggle: function(){ |
| 92 | if (this.el.offsetWidth > 0) this.custom(this.el.offsetWidth, 0); |
| 93 | else this.custom(0, this.el.iniWidth); |
| 94 | } |
| 95 | }); |
| 96 | |
| 97 | //fader |
| 98 | fx.Opacity = Class.create(); |
| 99 | fx.Opacity.prototype = Object.extend(new fx.Base(), { |
| 100 | initialize: function(el, options) { |
| 101 | this.el = $(el); |
| 102 | this.now = 1; |
| 103 | this.increase(); |
| 104 | this.setOptions(options); |
| 105 | }, |
| 106 | |
| 107 | increase: function() { |
| 108 | if (this.now == 1) this.now = 0.9999; |
| 109 | if (this.now > 0 && this.el.style.visibility == "hidden") this.el.style.visibility = "visible"; |
| 110 | if (this.now == 0) this.el.style.visibility = "hidden"; |
| 111 | if (window.ActiveXObject) this.el.style.filter = "alpha(opacity=" + this.now*100 + ")"; |
| 112 | this.el.style.opacity = this.now; |
| 113 | }, |
| 114 | |
| 115 | toggle: function() { |
| 116 | if (this.now > 0) this.custom(1, 0); |
| 117 | else this.custom(0, 1); |
| 118 | } |
admin | 7ffa703 | 2006-09-27 21:06:30 +0000 | [diff] [blame] | 119 | }); |