From a089699c8915636ba4f158d77dba9b012bc93208 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 4 Mar 2011 19:02:28 +0300 Subject: build custom layer of Dojo to speed up loading of tt-rss (refs #293) --- lib/dojo/fx.js | 634 +++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 393 insertions(+), 241 deletions(-) (limited to 'lib/dojo/fx.js') diff --git a/lib/dojo/fx.js b/lib/dojo/fx.js index 39ae253fd..5c70d5b9e 100644 --- a/lib/dojo/fx.js +++ b/lib/dojo/fx.js @@ -5,248 +5,400 @@ */ -if(!dojo._hasResource["dojo.fx"]){ -dojo._hasResource["dojo.fx"]=true; +if(!dojo._hasResource["dojo.fx"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. +dojo._hasResource["dojo.fx"] = true; dojo.provide("dojo.fx"); -dojo.require("dojo.fx.Toggler"); -(function(){ -var d=dojo,_1={_fire:function(_2,_3){ -if(this[_2]){ -this[_2].apply(this,_3||[]); -} -return this; -}}; -var _4=function(_5){ -this._index=-1; -this._animations=_5||[]; -this._current=this._onAnimateCtx=this._onEndCtx=null; -this.duration=0; -d.forEach(this._animations,function(a){ -this.duration+=a.duration; -if(a.delay){ -this.duration+=a.delay; -} -},this); -}; -d.extend(_4,{_onAnimate:function(){ -this._fire("onAnimate",arguments); -},_onEnd:function(){ -d.disconnect(this._onAnimateCtx); -d.disconnect(this._onEndCtx); -this._onAnimateCtx=this._onEndCtx=null; -if(this._index+1==this._animations.length){ -this._fire("onEnd"); -}else{ -this._current=this._animations[++this._index]; -this._onAnimateCtx=d.connect(this._current,"onAnimate",this,"_onAnimate"); -this._onEndCtx=d.connect(this._current,"onEnd",this,"_onEnd"); -this._current.play(0,true); -} -},play:function(_6,_7){ -if(!this._current){ -this._current=this._animations[this._index=0]; -} -if(!_7&&this._current.status()=="playing"){ -return this; -} -var _8=d.connect(this._current,"beforeBegin",this,function(){ -this._fire("beforeBegin"); -}),_9=d.connect(this._current,"onBegin",this,function(_a){ -this._fire("onBegin",arguments); -}),_b=d.connect(this._current,"onPlay",this,function(_c){ -this._fire("onPlay",arguments); -d.disconnect(_8); -d.disconnect(_9); -d.disconnect(_b); -}); -if(this._onAnimateCtx){ -d.disconnect(this._onAnimateCtx); -} -this._onAnimateCtx=d.connect(this._current,"onAnimate",this,"_onAnimate"); -if(this._onEndCtx){ -d.disconnect(this._onEndCtx); -} -this._onEndCtx=d.connect(this._current,"onEnd",this,"_onEnd"); -this._current.play.apply(this._current,arguments); -return this; -},pause:function(){ -if(this._current){ -var e=d.connect(this._current,"onPause",this,function(_d){ -this._fire("onPause",arguments); -d.disconnect(e); -}); -this._current.pause(); -} -return this; -},gotoPercent:function(_e,_f){ -this.pause(); -var _10=this.duration*_e; -this._current=null; -d.some(this._animations,function(a){ -if(a.duration<=_10){ -this._current=a; -return true; -} -_10-=a.duration; -return false; -}); -if(this._current){ -this._current.gotoPercent(_10/this._current.duration,_f); -} -return this; -},stop:function(_11){ -if(this._current){ -if(_11){ -for(;this._index+1this._animations.length){ -this._fire("onEnd"); -} -},_call:function(_19,_1a){ -var t=this._pseudoAnimation; -t[_19].apply(t,_1a); -},play:function(_1b,_1c){ -this._finished=0; -this._doAction("play",arguments); -this._call("play",arguments); -return this; -},pause:function(){ -this._doAction("pause",arguments); -this._call("pause",arguments); -return this; -},gotoPercent:function(_1d,_1e){ -var ms=this.duration*_1d; -d.forEach(this._animations,function(a){ -a.gotoPercent(a.duration this._animations.length){ + this._fire("onEnd"); + } + }, + _call: function(action, args){ + var t = this._pseudoAnimation; + t[action].apply(t, args); + }, + play: function(/*int?*/ delay, /*Boolean?*/ gotoStart){ + this._finished = 0; + this._doAction("play", arguments); + this._call("play", arguments); + return this; + }, + pause: function(){ + this._doAction("pause", arguments); + this._call("pause", arguments); + return this; + }, + gotoPercent: function(/*Decimal*/percent, /*Boolean?*/ andPlay){ + var ms = this.duration * percent; + d.forEach(this._animations, function(a){ + a.gotoPercent(a.duration < ms ? 1 : (ms / a.duration), andPlay); + }); + this._call("gotoPercent", arguments); + return this; + }, + stop: function(/*boolean?*/ gotoEnd){ + this._doAction("stop", arguments); + this._call("stop", arguments); + return this; + }, + status: function(){ + return this._pseudoAnimation.status(); + }, + destroy: function(){ + d.forEach(this._connects, dojo.disconnect); + } + }); + d.extend(_combine, _baseObj); + + dojo.fx.combine = function(/*dojo.Animation[]*/ animations){ + // summary: + // Combine a list of `dojo.Animation`s to run in parallel + // + // description: + // Combine an array of `dojo.Animation`s to run in parallel, + // providing a new `dojo.Animation` instance encompasing each + // animation, firing standard animation events. + // + // example: + // Fade out `node` while fading in `otherNode` simultaneously + // | dojo.fx.combine([ + // | dojo.fadeIn({ node:node }), + // | dojo.fadeOut({ node:otherNode }) + // | ]).play(); + // + // example: + // When the longest animation ends, execute a function: + // | var anim = dojo.fx.combine([ + // | dojo.fadeIn({ node: n, duration:700 }), + // | dojo.fadeOut({ node: otherNode, duration: 300 }) + // | ]); + // | dojo.connect(anim, "onEnd", function(){ + // | // overall animation is done. + // | }); + // | anim.play(); // play the animation + // + return new _combine(animations); // dojo.Animation + }; + + dojo.fx.wipeIn = function(/*Object*/ args){ + // summary: + // Expand a node to it's natural height. + // + // description: + // Returns an animation that will expand the + // node defined in 'args' object from it's current height to + // it's natural height (with no scrollbar). + // Node must have no margin/border/padding. + // + // args: Object + // A hash-map of standard `dojo.Animation` constructor properties + // (such as easing: node: duration: and so on) + // + // example: + // | dojo.fx.wipeIn({ + // | node:"someId" + // | }).play() + var node = args.node = d.byId(args.node), s = node.style, o; + + var anim = d.animateProperty(d.mixin({ + properties: { + height: { + // wrapped in functions so we wait till the last second to query (in case value has changed) + start: function(){ + // start at current [computed] height, but use 1px rather than 0 + // because 0 causes IE to display the whole panel + o = s.overflow; + s.overflow = "hidden"; + if(s.visibility == "hidden" || s.display == "none"){ + s.height = "1px"; + s.display = ""; + s.visibility = ""; + return 1; + }else{ + var height = d.style(node, "height"); + return Math.max(height, 1); + } + }, + end: function(){ + return node.scrollHeight; + } + } + } + }, args)); + + d.connect(anim, "onEnd", function(){ + s.height = "auto"; + s.overflow = o; + }); + + return anim; // dojo.Animation + } + + dojo.fx.wipeOut = function(/*Object*/ args){ + // summary: + // Shrink a node to nothing and hide it. + // + // description: + // Returns an animation that will shrink node defined in "args" + // from it's current height to 1px, and then hide it. + // + // args: Object + // A hash-map of standard `dojo.Animation` constructor properties + // (such as easing: node: duration: and so on) + // + // example: + // | dojo.fx.wipeOut({ node:"someId" }).play() + + var node = args.node = d.byId(args.node), s = node.style, o; + + var anim = d.animateProperty(d.mixin({ + properties: { + height: { + end: 1 // 0 causes IE to display the whole panel + } + } + }, args)); + + d.connect(anim, "beforeBegin", function(){ + o = s.overflow; + s.overflow = "hidden"; + s.display = ""; + }); + d.connect(anim, "onEnd", function(){ + s.overflow = o; + s.height = "auto"; + s.display = "none"; + }); + + return anim; // dojo.Animation + } + + dojo.fx.slideTo = function(/*Object*/ args){ + // summary: + // Slide a node to a new top/left position + // + // description: + // Returns an animation that will slide "node" + // defined in args Object from its current position to + // the position defined by (args.left, args.top). + // + // args: Object + // A hash-map of standard `dojo.Animation` constructor properties + // (such as easing: node: duration: and so on). Special args members + // are `top` and `left`, which indicate the new position to slide to. + // + // example: + // | dojo.fx.slideTo({ node: node, left:"40", top:"50", units:"px" }).play() + + var node = args.node = d.byId(args.node), + top = null, left = null; + + var init = (function(n){ + return function(){ + var cs = d.getComputedStyle(n); + var pos = cs.position; + top = (pos == 'absolute' ? n.offsetTop : parseInt(cs.top) || 0); + left = (pos == 'absolute' ? n.offsetLeft : parseInt(cs.left) || 0); + if(pos != 'absolute' && pos != 'relative'){ + var ret = d.position(n, true); + top = ret.y; + left = ret.x; + n.style.position="absolute"; + n.style.top=top+"px"; + n.style.left=left+"px"; + } + }; + })(node); + init(); + + var anim = d.animateProperty(d.mixin({ + properties: { + top: args.top || 0, + left: args.left || 0 + } + }, args)); + d.connect(anim, "beforeBegin", anim, init); + + return anim; // dojo.Animation + } + })(); + } -- cgit v1.2.3