123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666 |
- define("dojo/_base/fx", ["./kernel", "./lang", "../Evented", "./Color", "./connect", "./sniff", "../dom", "../dom-style"], function(dojo, lang, Evented, Color, connect, has, dom, style){
-
-
-
-
-
-
-
- var _mixin = lang.mixin;
- dojo._Line = function(/*int*/ start, /*int*/ end){
-
-
-
-
-
-
-
- this.start = start;
- this.end = end;
- };
- dojo._Line.prototype.getValue = function(/*float*/ n){
-
-
- return ((this.end - this.start) * n) + this.start;
- };
- dojo.Animation = function(args){
-
-
-
-
-
-
-
-
-
-
-
-
-
- _mixin(this, args);
- if(lang.isArray(this.curve)){
- this.curve = new dojo._Line(this.curve[0], this.curve[1]);
- }
- };
- dojo.Animation.prototype = new Evented();
-
- dojo._Animation = dojo.Animation;
- lang.extend(dojo.Animation, {
-
-
- duration: 350,
-
-
-
- repeat: 0,
-
-
-
- rate: 20 ,
-
- _percent: 0,
- _startRepeatCount: 0,
- _getStep: function(){
- var _p = this._percent,
- _e = this.easing
- ;
- return _e ? _e(_p) : _p;
- },
- _fire: function(/*Event*/ evt, /*Array?*/ args){
-
-
-
-
-
-
-
-
-
-
-
-
- var a = args||[];
- if(this[evt]){
- if(dojo.config.debugAtAllCosts){
- this[evt].apply(this, a);
- }else{
- try{
- this[evt].apply(this, a);
- }catch(e){
-
-
-
-
-
- console.error("exception in animation handler for:", evt);
- console.error(e);
- }
- }
- }
- return this;
- },
- play: function(/*int?*/ delay, /*Boolean?*/ gotoStart){
-
-
-
-
-
-
-
-
-
- var _t = this;
- if(_t._delayTimer){ _t._clearTimer(); }
- if(gotoStart){
- _t._stopTimer();
- _t._active = _t._paused = false;
- _t._percent = 0;
- }else if(_t._active && !_t._paused){
- return _t;
- }
- _t._fire("beforeBegin", [_t.node]);
- var de = delay || _t.delay,
- _p = lang.hitch(_t, "_play", gotoStart);
- if(de > 0){
- _t._delayTimer = setTimeout(_p, de);
- return _t;
- }
- _p();
- return _t;
- },
- _play: function(gotoStart){
- var _t = this;
- if(_t._delayTimer){ _t._clearTimer(); }
- _t._startTime = new Date().valueOf();
- if(_t._paused){
- _t._startTime -= _t.duration * _t._percent;
- }
- _t._active = true;
- _t._paused = false;
- var value = _t.curve.getValue(_t._getStep());
- if(!_t._percent){
- if(!_t._startRepeatCount){
- _t._startRepeatCount = _t.repeat;
- }
- _t._fire("onBegin", [value]);
- }
- _t._fire("onPlay", [value]);
- _t._cycle();
- return _t;
- },
- pause: function(){
-
- var _t = this;
- if(_t._delayTimer){ _t._clearTimer(); }
- _t._stopTimer();
- if(!_t._active){ return _t; }
- _t._paused = true;
- _t._fire("onPause", [_t.curve.getValue(_t._getStep())]);
- return _t;
- },
- gotoPercent: function(/*Decimal*/ percent, /*Boolean?*/ andPlay){
-
-
-
-
-
-
- var _t = this;
- _t._stopTimer();
- _t._active = _t._paused = true;
- _t._percent = percent;
- if(andPlay){ _t.play(); }
- return _t;
- },
- stop: function(/*boolean?*/ gotoEnd){
-
-
- var _t = this;
- if(_t._delayTimer){ _t._clearTimer(); }
- if(!_t._timer){ return _t; }
- _t._stopTimer();
- if(gotoEnd){
- _t._percent = 1;
- }
- _t._fire("onStop", [_t.curve.getValue(_t._getStep())]);
- _t._active = _t._paused = false;
- return _t;
- },
- status: function(){
-
-
-
- if(this._active){
- return this._paused ? "paused" : "playing";
- }
- return "stopped";
- },
- _cycle: function(){
- var _t = this;
- if(_t._active){
- var curr = new Date().valueOf();
- var step = (curr - _t._startTime) / (_t.duration);
- if(step >= 1){
- step = 1;
- }
- _t._percent = step;
-
- if(_t.easing){
- step = _t.easing(step);
- }
- _t._fire("onAnimate", [_t.curve.getValue(step)]);
- if(_t._percent < 1){
- _t._startTimer();
- }else{
- _t._active = false;
- if(_t.repeat > 0){
- _t.repeat--;
- _t.play(null, true);
- }else if(_t.repeat == -1){
- _t.play(null, true);
- }else{
- if(_t._startRepeatCount){
- _t.repeat = _t._startRepeatCount;
- _t._startRepeatCount = 0;
- }
- }
- _t._percent = 0;
- _t._fire("onEnd", [_t.node]);
- !_t.repeat && _t._stopTimer();
- }
- }
- return _t;
- },
- _clearTimer: function(){
-
- clearTimeout(this._delayTimer);
- delete this._delayTimer;
- }
- });
-
- var ctr = 0,
- timer = null,
- runner = {
- run: function(){}
- };
- lang.extend(dojo.Animation, {
- _startTimer: function(){
- if(!this._timer){
- this._timer = connect.connect(runner, "run", this, "_cycle");
- ctr++;
- }
- if(!timer){
- timer = setInterval(lang.hitch(runner, "run"), this.rate);
- }
- },
- _stopTimer: function(){
- if(this._timer){
- connect.disconnect(this._timer);
- this._timer = null;
- ctr--;
- }
- if(ctr <= 0){
- clearInterval(timer);
- timer = null;
- ctr = 0;
- }
- }
- });
- var _makeFadeable =
- has("ie") ? function(node){
-
-
- var ns = node.style;
-
-
- if(!ns.width.length && style.get(node, "width") == "auto"){
- ns.width = "auto";
- }
- } :
- function(){};
- dojo._fade = function(/*Object*/ args){
-
-
-
-
- args.node = dom.byId(args.node);
- var fArgs = _mixin({ properties: {} }, args),
- props = (fArgs.properties.opacity = {});
- props.start = !("start" in fArgs) ?
- function(){
- return +style.get(fArgs.node, "opacity")||0;
- } : fArgs.start;
- props.end = fArgs.end;
- var anim = dojo.animateProperty(fArgs);
- connect.connect(anim, "beforeBegin", lang.partial(_makeFadeable, fArgs.node));
- return anim;
- };
-
- dojo.fadeIn = function(/*dojo.__FadeArgs*/ args){
-
-
-
- return dojo._fade(_mixin({ end: 1 }, args));
- };
- dojo.fadeOut = function(/*dojo.__FadeArgs*/ args){
-
-
-
- return dojo._fade(_mixin({ end: 0 }, args));
- };
- dojo._defaultEasing = function(/*Decimal?*/ n){
-
- return 0.5 + ((Math.sin((n + 1.5) * Math.PI)) / 2);
- };
- var PropLine = function(properties){
-
-
-
-
- this._properties = properties;
- for(var p in properties){
- var prop = properties[p];
- if(prop.start instanceof Color){
-
- prop.tempColor = new Color();
- }
- }
- };
- PropLine.prototype.getValue = function(r){
- var ret = {};
- for(var p in this._properties){
- var prop = this._properties[p],
- start = prop.start;
- if(start instanceof Color){
- ret[p] = Color.blendColors(start, prop.end, r, prop.tempColor).toCss();
- }else if(!lang.isArray(start)){
- ret[p] = ((prop.end - start) * r) + start + (p != "opacity" ? prop.units || "px" : 0);
- }
- }
- return ret;
- };
-
- dojo.animateProperty = function(/*dojo.__AnimArgs*/ args){
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- var n = args.node = dom.byId(args.node);
- if(!args.easing){ args.easing = dojo._defaultEasing; }
- var anim = new dojo.Animation(args);
- connect.connect(anim, "beforeBegin", anim, function(){
- var pm = {};
- for(var p in this.properties){
-
-
-
-
- if(p == "width" || p == "height"){
- this.node.display = "block";
- }
- var prop = this.properties[p];
- if(lang.isFunction(prop)){
- prop = prop(n);
- }
- prop = pm[p] = _mixin({}, (lang.isObject(prop) ? prop: { end: prop }));
- if(lang.isFunction(prop.start)){
- prop.start = prop.start(n);
- }
- if(lang.isFunction(prop.end)){
- prop.end = prop.end(n);
- }
- var isColor = (p.toLowerCase().indexOf("color") >= 0);
- function getStyle(node, p){
-
- var v = { height: node.offsetHeight, width: node.offsetWidth }[p];
- if(v !== undefined){ return v; }
- v = style.get(node, p);
- return (p == "opacity") ? +v : (isColor ? v : parseFloat(v));
- }
- if(!("end" in prop)){
- prop.end = getStyle(n, p);
- }else if(!("start" in prop)){
- prop.start = getStyle(n, p);
- }
- if(isColor){
- prop.start = new Color(prop.start);
- prop.end = new Color(prop.end);
- }else{
- prop.start = (p == "opacity") ? +prop.start : parseFloat(prop.start);
- }
- }
- this.curve = new PropLine(pm);
- });
- connect.connect(anim, "onAnimate", lang.hitch(style, "set", anim.node));
- return anim;
- };
- dojo.anim = function( /*DOMNode|String*/ node,
- /*Object*/ properties,
- /*Integer?*/ duration,
- /*Function?*/ easing,
- /*Function?*/ onEnd,
- /*Integer?*/ delay){
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- return dojo.animateProperty({
- node: node,
- duration: duration || dojo.Animation.prototype.duration,
- properties: properties,
- easing: easing,
- onEnd: onEnd
- }).play(delay || 0);
- };
- return {
- _Line: dojo._Line,
- Animation: dojo.Animation,
- _fade: dojo._fade,
- fadeIn: dojo.fadeIn,
- fadeOut: dojo.fadeOut,
- _defaultEasing: dojo._defaultEasing,
- animateProperty: dojo.animateProperty,
- anim: dojo.anim
- };
- });
|