123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346 |
- define("dojox/app/animation", ["dojo/_base/kernel",
- "dojo/_base/lang",
- "dojo/_base/declare",
- "dojo/_base/array",
- "dojo/_base/Deferred",
- "dojo/DeferredList",
- "dojo/on",
- "dojo/_base/sniff"],
- function(dojo, lang, declare, array, deferred, deferredList, on, has){
-
- var transitionEndEventName = "transitionend";
- var transitionPrefix = "t";
- var translateMethodStart = "translate3d(";
- var translateMethodEnd = ",0,0)";
- if(has("webkit")){
- transitionPrefix = "WebkitT";
- transitionEndEventName = "webkitTransitionEnd";
- }else if(has("mozilla")){
- transitionPrefix = "MozT";
- translateMethodStart = "translateX(";
- translateMethodEnd = ")";
- }
-
-
-
- declare("dojox.app.animation", null, {
-
- constructor: function(args){
-
-
- var defaultConfig = {
- startState: {},
- endState: {},
- node: null,
- duration: 250,
- "in": true,
- direction: 1,
- autoClear: true
- };
-
- lang.mixin(this, defaultConfig);
- lang.mixin(this, args);
-
-
-
-
- if(!this.deferred){
- this.deferred = new deferred();
- }
- },
-
- play: function(){
-
- dojox.app.animation.groupedPlay([this]);
- },
-
-
- _applyState: function(state){
- var style = this.node.style;
- for(var property in state){
- if(state.hasOwnProperty(property)){
- style[property] = state[property];
- }
- }
- },
-
-
- initState: function(){
-
-
- this.node.style[transitionPrefix + "ransitionProperty"] = "none";
- this.node.style[transitionPrefix + "ransitionDuration"] = "0ms";
- this._applyState(this.startState);
-
- },
-
- _beforeStart: function(){
- if (this.node.style.display === "none"){
- this.node.style.display = "";
- }
- this.beforeStart();
- },
-
- _beforeClear: function(){
- this.node.style[transitionPrefix + "ransitionProperty"] = null;
- this.node.style[transitionPrefix + "ransitionDuration"] = null;
- if(this["in"] !== true){
- this.node.style.display = "none";
- }
- this.beforeClear();
- },
-
- _onAfterEnd: function(){
- this.deferred.resolve(this.node);
- if(this.node.id && dojox.app.animation.playing[this.node.id]===this.deferred){
- delete dojox.app.animation.playing[this.node.id];
- }
- this.onAfterEnd();
- },
-
- beforeStart: function(){
-
- },
-
- beforeClear: function(){
-
- },
-
- onAfterEnd: function(){
-
- },
-
-
- start: function(){
- this._beforeStart();
-
- var self = this;
-
- self.node.style[transitionPrefix + "ransitionProperty"] = "all";
- self.node.style[transitionPrefix + "ransitionDuration"] = self.duration + "ms";
-
-
-
-
- on.once(self.node, transitionEndEventName, function(){
- self.clear();
- });
-
- this._applyState(this.endState);
- },
-
-
- clear: function(){
- this._beforeClear();
- this._removeState(this.endState);
- console.log(this.node.id + " clear.");
- this._onAfterEnd();
- },
-
-
- _removeState: function(state){
- var style = this.node.style;
- for(var property in state){
- if(state.hasOwnProperty(property)){
- style[property] = null;
- }
- }
- }
-
- });
-
-
-
-
- dojox.app.animation.slide = function(node, config){
-
- var ret = new dojox.app.animation(config);
- ret.node = node;
-
- var startX = "0";
- var endX = "0";
-
- if(ret["in"]){
- if(ret.direction === 1){
- startX = "100%";
- }else{
- startX = "-100%";
- }
- }else{
- if(ret.direction === 1){
- endX = "-100%";
- }else{
- endX = "100%";
- }
- }
-
-
- ret.startState[transitionPrefix + "ransform"]=translateMethodStart+startX+translateMethodEnd;
-
- ret.endState[transitionPrefix + "ransform"]=translateMethodStart+endX+translateMethodEnd;
-
- return ret;
- };
-
-
-
- dojox.app.animation.fade = function(node, config){
-
- var ret = new dojox.app.animation(config);
- ret.node = node;
-
- var startOpacity = "0";
- var endOpacity = "0";
-
- if(ret["in"]){
- endOpacity = "1";
- }else{
- startOpacity = "1";
- }
-
- lang.mixin(ret, {
- startState:{
- "opacity": startOpacity
- },
- endState:{
- "opacity": endOpacity
- }
- });
-
- return ret;
- };
-
-
- dojox.app.animation.flip = function(node, config){
-
- var ret = new dojox.app.animation(config);
- ret.node = node;
-
- if(ret["in"]){
-
-
- lang.mixin(ret,{
- startState:{
- "opacity": "0"
- },
- endState:{
- "opacity": "1"
- }
- });
- ret.startState[transitionPrefix + "ransform"]="scale(0,0.8) skew(0,-30deg)";
- ret.endState[transitionPrefix + "ransform"]="scale(1,1) skew(0,0)";
- }else{
- lang.mixin(ret,{
- startState:{
- "opacity": "1"
- },
- endState:{
- "opacity": "0"
- }
- });
- ret.startState[transitionPrefix + "ransform"]="scale(1,1) skew(0,0)";
- ret.endState[transitionPrefix + "ransform"]="scale(0,0.8) skew(0,30deg)";
- }
-
- return ret;
- };
-
- var getWaitingList = function(/*Array*/ nodes){
- var defs = [];
- array.forEach(nodes, function(node){
-
- if(node.id && dojox.app.animation.playing[node.id]){
-
- defs.push(dojox.app.animation.playing[node.id]);
- }
-
- });
- return new deferredList(defs);
- };
-
- dojox.app.animation.getWaitingList = getWaitingList;
-
-
-
-
- dojox.app.animation.groupedPlay = function(/*Array*/args){
-
-
- var animNodes = array.filter(args, function(item){
- return item.node;
- });
-
- var waitingList = getWaitingList(animNodes);
-
- array.forEach(args, function(item){
- if(item.node.id){
- dojox.app.animation.playing[item.node.id] = item.deferred;
- }
- });
-
-
- dojo.when(waitingList, function(){
- array.forEach(args, function(item){
-
- item.initState();
- });
-
-
-
-
- setTimeout(function(){
- array.forEach(args, function(item){
- item.start();
- });
- }, 33);
- });
- };
-
-
- dojox.app.animation.chainedPlay = function(/*Array*/args){
-
-
- var animNodes = array.filter(args, function(item){
- return item.node;
- });
-
- var waitingList = getWaitingList(animNodes);
-
- array.forEach(args, function(item){
- if(item.node.id){
- dojox.app.animation.playing[item.node.id] = item.deferred;
- }
- });
-
- dojo.when(waitingList, function(){
- array.forEach(args, function(item){
-
- item.initState();
- });
-
-
- for (var i=1, len=args.length; i < len; i++){
- args[i-1].deferred.then(lang.hitch(args[i], function(){
- this.start();
- }));
- }
-
-
-
-
- setTimeout(function(){
- args[0].start();
- }, 33);
- });
- };
-
-
- dojox.app.animation.playing = {};
-
- return dojox.app.animation;
- });
|