/** * Copyright (c) 2006, Opera Software ASA * All rights reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of Opera Software ASA nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY OPERA SOFTWARE ASA AND CONTRIBUTORS ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL OPERA SOFTWARE ASA AND CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* Version: 0.18.1 */ /* Modified to work under IE6+ op@, dorogush@, mvel@ */ var o_animationTimer=new function() { var time=15; var store=[]; var run=false; var interval=0; var realClock=[]; var realClockReady=false; var self=this; var onFrame=null; var getRealFrame=function() { var sum=0, i=1, length=0; if(realClock.length>30) realClock.shift(); realClock[(length=realClock.length)]=new Date(); onFrame(Math.round(1000/((realClock[length]-realClock[0])/(length-1)))); } var goStep=function() { var i=0, noFn=true; //opera.postError(store.length); for(i=0; i=100)) { this.current=100; o_animationTimer.clear(this.interval); last=true; }; var i=0, prop=null; for ( ; prop=this.properties[i]; i++) { var v = prop.strategy(prop, this.current, this); if (Prototype.Browser.IE && prop.property == 'opacity') { this.style['filter'] = 'alpha( opacity = ' + v * 100 + ' )'; } else { this.style[prop.property] = v; } // alert(typeof(prop.strategy(prop, this.current, this)) + "\n" + prop.strategy(prop, this.current, this)) } if(last) { this.current=0; this._isrunning=false; this.releaseEvent('OAnimationFinish'); if(this.onfinish) this.onfinish(); } else this.releaseEvent('OAnimationFrame'); } Animation.on=true; /** * to add a animation for a certain property. * @param property the property which shall be animated * @param from the start value as string * @param to the end value as string */ Animation.prototype.addAnimation=function(property, from, to, customStrategy) { var strat=null, unit='', delta=0; var pointer_here=this.getProperty(property)||(this.properties[this.properties.length]={}); if(this.reIsColor.test(from)) { pointer_here.property=property; pointer_here.from=from; pointer_here.to=to; pointer_here.fromRGB=this.convertToRGB(from); pointer_here.toRGB=this.convertToRGB(to); pointer_here.deltaRGB= [ (pointer_here.toRGB[0]-pointer_here.fromRGB[0]), (pointer_here.toRGB[1]-pointer_here.fromRGB[1]), (pointer_here.toRGB[2]-pointer_here.fromRGB[2]) ]; pointer_here.strategy=this.strategyColor; } else { if(property=='opacity') { strat=this.strategyFloat; from=parseFloat(from); to=parseFloat(to); } else if(property=='clip') { strat=this.strategyClip; from=from.split(','); from[0]=parseInt(from[0]); from[1]=parseInt(from[1]); from[2]=parseInt(from[2]); from[3]=parseInt(from[3]); to=to.split(','); to[0]=parseInt(to[0]); to[1]=parseInt(to[1]); to[2]=parseInt(to[2]); to[3]=parseInt(to[3]); } else if (property.indexOf('window')==0) { switch (property) { case 'windowMoveTo': strat=this.strategyMoveWindow; from=from.split(','); from[0]=parseInt(from[0]); from[1]=parseInt(from[1]); to=to.split(','); to[0]=parseInt(to[0]); to[1]=parseInt(to[1]); break; case 'windowMoveBy': strat=this.strategyMoveWindow; var by=from.split(','); by[0]=parseInt(by[0]); by[1]=parseInt(by[1]); from=[]; to=[]; from[0]=window.screenLeft; from[1]=window.screenTop; to[0]=from[0]+by[0]; to[1]=from[1]+by[1]; break; case 'windowResizeTo': strat=this.strategyResizeWindow; var to=from.split(','); to[0]=parseInt(to[0]); to[1]=parseInt(to[1]); from=[]; from[0]=window.innerWidth; from[1]=window.innerHeight; break; case 'windowResizeBy': strat=this.strategyResizeWindow; var by=from.split(','); by[0]=parseInt(by[0]); by[1]=parseInt(by[1]); from=[]; to=[]; from=[]; from[0]=window.innerWidth; from[1]=window.innerHeight; to[0]=from[0]+by[0]; to[1]=from[1]+by[1]; break; } } else if (strat=customStrategy) { unit=from.replace(/-?\d*/g,''); from=parseFloat(from); to=parseFloat(to); } else { strat=this.strategyInt; unit=from.replace(/-?\d*/g,''); from=parseInt(from); to=parseInt(to); } pointer_here.property=property; pointer_here.unit=unit; pointer_here.from=from; pointer_here.to=to; pointer_here.delta=to-from; // TODO clan this up pointer_here.strategy=strat; } return this; } Animation.prototype.removeAnimation=function(property) { var i=0, pointer=null; for( ; pointer=this.properties[i]; i++) { if(property==pointer.property) { this.properties.splice(i, 1); return true; } } return false; } Animation.prototype.stop=function() { //opera.postError('s '+this._isrunning); if(this._isrunning) { //opera.postError('ss'); o_animationTimer.clear(this.interval); this.current=0; this._isrunning=false; this.releaseEvent('OAnimationStop'); if(this.onstop) this.onstop(); } } Animation.prototype.pauseAnimation=function() { if(this._isrunning) { o_animationTimer.clear(this.interval); this._isrunning=false; } } Animation.prototype.continueAnimation=function() { var self=this; if(!this._isrunning && this.current) { this._isrunning=true; this.interval=o_animationTimer.set(function(){self.onStep()}); } } Animation.prototype.releaseEvent=function(name) { return; //NB // TODO // why this is removed? if(this.element) { var event=document.createEvent('Events'); event.initEvent(name, true, false); event.data=this; this.element.dispatchEvent(event); } } Animation.prototype.remove=function(bol) { if(this._isrunning) o_animationTimer.clear(this.interval); if(bol && this.element && this.element.parentNode) this.element.parentNode.removeChild(this.element); delete this.element; delete this.style; delete this.onstart; delete this.onfinish; delete this.onstop; delete this.accelerationProfile; }