1
1
/**
2
- * Durandal 2.0.1 Copyright (c) 2012 Blue Spire Consulting, Inc. All Rights Reserved.
2
+ * Durandal 2.1.0 Copyright (c) 2012 Blue Spire Consulting, Inc. All Rights Reserved.
3
3
* Available via the MIT license.
4
4
* see: http://durandaljs.com or https://github.com/BlueSpire/Durandal for details.
5
5
*/
13
13
define ( [ 'durandal/system' , 'durandal/composition' , 'jquery' ] , function ( system , composition , $ ) {
14
14
var fadeOutDuration = 100 ;
15
15
var endValues = {
16
- marginRight : 0 ,
17
- marginLeft : 0 ,
16
+ left : '0px' ,
18
17
opacity : 1
19
18
} ;
20
19
var clearValues = {
21
- marginLeft : '' ,
22
- marginRight : '' ,
23
- opacity : '' ,
24
- display : ''
20
+ left : '' ,
21
+ top : '' ,
22
+ right : '' ,
23
+ bottom :'' ,
24
+ position :'' ,
25
+ opacity : ''
25
26
} ;
26
27
28
+ var isIE = navigator . userAgent . match ( / T r i d e n t / ) || navigator . userAgent . match ( / M S I E / ) ;
29
+
30
+ var animation = false ,
31
+ domPrefixes = 'Webkit Moz O ms Khtml' . split ( ' ' ) ,
32
+ elm = document . createElement ( 'div' ) ;
33
+
34
+ if ( elm . style . animationName !== undefined ) {
35
+ animation = true ;
36
+ }
37
+
38
+ if ( ! animation ) {
39
+ for ( var i = 0 ; i < domPrefixes . length ; i ++ ) {
40
+ if ( elm . style [ domPrefixes [ i ] + 'AnimationName' ] !== undefined ) {
41
+ animation = true ;
42
+ break ;
43
+ }
44
+ }
45
+ }
46
+
47
+ if ( animation ) {
48
+ if ( isIE ) {
49
+ system . log ( 'Using CSS3/jQuery mixed animations.' ) ;
50
+ } else {
51
+ system . log ( 'Using CSS3 animations.' ) ;
52
+ }
53
+ } else {
54
+ system . log ( 'Using jQuery animations.' ) ;
55
+ }
56
+
57
+ function removeAnimationClasses ( ele , fadeOnly ) {
58
+ ele . classList . remove ( fadeOnly ? 'entrance-in-fade' : 'entrance-in' ) ;
59
+ ele . classList . remove ( 'entrance-out' ) ;
60
+ }
61
+
27
62
/**
28
63
* @class EntranceModule
29
64
* @constructor
@@ -44,34 +79,55 @@ define(['durandal/system', 'durandal/composition', 'jquery'], function(system, c
44
79
$ ( context . activeView ) . fadeOut ( fadeOutDuration , endTransition ) ;
45
80
} else {
46
81
var duration = context . duration || 500 ;
82
+ var $child = $ ( context . child ) ;
47
83
var fadeOnly = ! ! context . fadeOnly ;
84
+ var startValues = {
85
+ display : 'block' ,
86
+ opacity : 0 ,
87
+ position : 'absolute' ,
88
+ left : fadeOnly || animation ? '0px' : '20px' ,
89
+ right : 0 ,
90
+ top : 0 ,
91
+ bottom : 0
92
+ } ;
48
93
49
94
function startTransition ( ) {
50
95
scrollIfNeeded ( ) ;
51
96
context . triggerAttach ( ) ;
52
97
53
- var startValues = {
54
- marginLeft : fadeOnly ? '0' : '20px' ,
55
- marginRight : fadeOnly ? '0' : '-20px' ,
56
- opacity : 0 ,
57
- display : 'block'
58
- } ;
59
-
60
- var $child = $ ( context . child ) ;
61
-
62
- $child . css ( startValues ) ;
63
- $child . animate ( endValues , {
64
- duration : duration ,
65
- easing : 'swing' ,
66
- always : function ( ) {
98
+ if ( animation ) {
99
+ removeAnimationClasses ( context . child , fadeOnly ) ;
100
+ context . child . classList . add ( fadeOnly ? 'entrance-in-fade' : 'entrance-in' ) ;
101
+ setTimeout ( function ( ) {
102
+ removeAnimationClasses ( context . child , fadeOnly ) ;
103
+ if ( context . activeView ) {
104
+ removeAnimationClasses ( context . activeView , fadeOnly ) ;
105
+ }
67
106
$child . css ( clearValues ) ;
68
107
endTransition ( ) ;
69
- }
70
- } ) ;
108
+ } , duration ) ;
109
+ } else {
110
+ $child . animate ( endValues , {
111
+ duration : duration ,
112
+ easing : 'swing' ,
113
+ always : function ( ) {
114
+ $child . css ( clearValues ) ;
115
+ endTransition ( ) ;
116
+ }
117
+ } ) ;
118
+ }
71
119
}
72
120
73
- if ( context . activeView ) {
74
- $ ( context . activeView ) . fadeOut ( { duration : fadeOutDuration , always : startTransition } ) ;
121
+ $child . css ( startValues ) ;
122
+
123
+ if ( context . activeView ) {
124
+ if ( animation && ! isIE ) {
125
+ removeAnimationClasses ( context . activeView , fadeOnly ) ;
126
+ context . activeView . classList . add ( 'entrance-out' ) ;
127
+ setTimeout ( startTransition , fadeOutDuration ) ;
128
+ } else {
129
+ $ ( context . activeView ) . fadeOut ( { duration : fadeOutDuration , always : startTransition } ) ;
130
+ }
75
131
} else {
76
132
startTransition ( ) ;
77
133
}
0 commit comments