/
transit.js
92 lines (87 loc) · 3.14 KB
/
transit.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
define(["dojo/_base/array","dojo/dom-style","dojo/DeferredList","./transition"],
function(darray, domStyle, DeferredList, transition){
// module:
// dojox/css3/transit
// summary:
// This module defines the transit method which is used
// to transit the specific region of an application from
// one view/page to another view/page. This module relies
// on utilities provided by dojox/css3/transition for the
// transition effects.
var transit = function(from, to, options){
// summary:
// The method to transit from node out of display and
// transit to node into display.
// options:
// The argument to specify the transit effect and direction.
// The effect can be specified in options.transition. The
// valid values are 'slide', 'flip', 'fade', 'none'.
// The direction can be specified in options.reverse. If it
// is true, the transit effects will be conducted in the
// reverse direction to the default direction.
var rev = (options && options.reverse) ? -1 : 1;
if(!options || !options.transition || !transition[options.transition]){
domStyle.set(from,"display","none");
domStyle.set(to, "display", "");
if(options.transitionDefs){
if(options.transitionDefs[from.id]){
options.transitionDefs[from.id].resolve(from);
}
if(options.transitionDefs[to.id]){
options.transitionDefs[to.id].resolve(to);
}
}
// return a fired DeferredList if the options.transition="none"
return new DeferredList([]);
}else{
var defs=[];
var transit=[];
var duration = 250;
if(options.transition === "fade"){
duration = 600;
}else if (options.transition === "flip"){
duration = 200;
}
domStyle.set(from, "display", "");
domStyle.set(to, "display", "");
if (from){
//create transition to transit "from" out
var fromTransit = transition[options.transition](from, {
"in": false,
direction: rev,
duration: duration,
deferred: (options.transitionDefs && options.transitionDefs[from.id]) ? options.transitionDefs[from.id] : null
});
defs.push(fromTransit.deferred);//every transition object should have a deferred.
transit.push(fromTransit);
}
//create transition to transit "to" in
var toTransit = transition[options.transition](to, {
direction: rev,
duration: duration,
deferred: (options.transitionDefs && options.transitionDefs[to.id]) ? options.transitionDefs[to.id] : null
});
defs.push(toTransit.deferred);//every transition object should have a deferred.
transit.push(toTransit);
//If it is flip use the chainedPlay, otherwise
//play fromTransit and toTransit together
if(options.transition === "flip"){
transition.chainedPlay(transit);
}else{
transition.groupedPlay(transit);
}
return new DeferredList(defs);
}
};
/*=====
return {
// summary:
// This module defines the transit function which is used
// to transit the specific region of an application from
// one view/page to another view/page. This module relies
// on utilities provided by dojox/css3/transition for the
// transition effects.
};
=====*/
return transit;
});