1
- ( function ( ) {
1
+ module Application {
2
2
"use strict" ;
3
3
4
4
var appView = Windows . UI . ViewManagement . ApplicationView ;
5
5
var nav = WinJS . Navigation ;
6
6
7
- WinJS . Namespace . define ( "Application" , {
8
- PageControlNavigator : WinJS . Class . define (
9
- // Define the constructor function for the PageControlNavigator.
10
- function PageControlNavigator ( element , options ) {
11
- this . _element = element || document . createElement ( "div" ) ;
12
- this . _element . appendChild ( this . _createPageElement ( ) ) ;
13
-
14
- this . home = options . home ;
15
- this . _lastViewstate = appView . value ;
16
-
17
- nav . onnavigated = this . _navigated . bind ( this ) ;
18
- window . onresize = this . _resized . bind ( this ) ;
19
-
20
- document . body . onkeyup = this . _keyupHandler . bind ( this ) ;
21
- document . body . onkeypress = this . _keypressHandler . bind ( this ) ;
22
- document . body . onmspointerup = this . _mspointerupHandler . bind ( this ) ;
23
-
24
- Application . navigator = this ;
25
- } , {
26
- home : "" ,
27
- /// <field domElement="true" />
28
- _element : null ,
29
- _lastNavigationPromise : WinJS . Promise . as ( ) ,
30
- _lastViewstate : 0 ,
31
-
32
- // This is the currently loaded Page object.
33
- pageControl : {
34
- get : function ( ) { return this . pageElement && this . pageElement . winControl ; }
35
- } ,
36
-
37
- // This is the root element of the current page.
38
- pageElement : {
39
- get : function ( ) { return this . _element . firstElementChild ; }
40
- } ,
41
-
42
- // Creates a container for a new page to be loaded into.
43
- _createPageElement : function ( ) {
44
- var element = document . createElement ( "div" ) ;
45
- element . setAttribute ( "dir" , window . getComputedStyle ( this . _element , null ) . direction ) ;
46
- element . style . width = "100%" ;
47
- element . style . height = "100%" ;
48
- return element ;
49
- } ,
50
-
51
- // Retrieves a list of animation elements for the current page.
52
- // If the page does not define a list, animate the entire page.
53
- _getAnimationElements : function ( ) {
54
- if ( this . pageControl && this . pageControl . getAnimationElements ) {
55
- return this . pageControl . getAnimationElements ( ) ;
56
- }
57
- return this . pageElement ;
58
- } ,
59
-
60
- // Navigates back whenever the backspace key is pressed and
61
- // not captured by an input field.
62
- _keypressHandler : function ( args ) {
63
- if ( args . key === "Backspace" ) {
64
- nav . back ( ) ;
65
- }
66
- } ,
67
-
68
- // Navigates back or forward when alt + left or alt + right
69
- // key combinations are pressed.
70
- _keyupHandler : function ( args ) {
71
- if ( ( args . key === "Left" && args . altKey ) || ( args . key === "BrowserBack" ) ) {
72
- nav . back ( ) ;
73
- } else if ( ( args . key === "Right" && args . altKey ) || ( args . key === "BrowserForward" ) ) {
74
- nav . forward ( ) ;
75
- }
76
- } ,
77
-
78
- // This function responds to clicks to enable navigation using
79
- // back and forward mouse buttons.
80
- _mspointerupHandler : function ( args ) {
81
- if ( args . button === 3 ) {
82
- nav . back ( ) ;
83
- } else if ( args . button === 4 ) {
84
- nav . forward ( ) ;
85
- }
86
- } ,
87
-
88
- // Responds to navigation by adding new pages to the DOM.
89
- _navigated : function ( args ) {
90
- var newElement = this . _createPageElement ( ) ;
91
- var parentedComplete ;
92
- var parented = new WinJS . Promise ( function ( c ) { parentedComplete = c ; } ) ;
93
-
94
- this . _lastNavigationPromise . cancel ( ) ;
95
-
96
- this . _lastNavigationPromise = WinJS . Promise . timeout ( ) . then ( function ( ) {
97
- return WinJS . UI . Pages . render ( args . detail . location , newElement , args . detail . state , parented ) ;
98
- } ) . then ( function parentElement ( control ) {
7
+ export var navigator : any ;
8
+
9
+ export var PageControlNavigator = WinJS . Class . define (
10
+ // Define the constructor function for the PageControlNavigator.
11
+ function PageControlNavigator ( element , options ) {
12
+ this . _element = element || document . createElement ( "div" ) ;
13
+ this . _element . appendChild ( this . _createPageElement ( ) ) ;
14
+
15
+ this . home = options . home ;
16
+ this . _lastViewstate = appView . value ;
17
+
18
+ nav . onnavigated = this . _navigated . bind ( this ) ;
19
+ window . onresize = this . _resized . bind ( this ) ;
20
+
21
+ document . body . onkeyup = this . _keyupHandler . bind ( this ) ;
22
+ document . body . onkeypress = this . _keypressHandler . bind ( this ) ;
23
+ document . body . onmspointerup = this . _mspointerupHandler . bind ( this ) ;
24
+
25
+ Application . navigator = this ;
26
+ } , {
27
+ home : "" ,
28
+ /// <field domElement="true" />
29
+ _element : null ,
30
+ _lastNavigationPromise : WinJS . Promise . as ( ) ,
31
+ _lastViewstate : 0 ,
32
+
33
+ // This is the currently loaded Page object.
34
+ pageControl : {
35
+ get : function ( ) { return this . pageElement && this . pageElement . winControl ; }
36
+ } ,
37
+
38
+ // This is the root element of the current page.
39
+ pageElement : {
40
+ get : function ( ) { return this . _element . firstElementChild ; }
41
+ } ,
42
+
43
+ // Creates a container for a new page to be loaded into.
44
+ _createPageElement : function ( ) {
45
+ var element = document . createElement ( "div" ) ;
46
+ element . setAttribute ( "dir" , window . getComputedStyle ( this . _element , null ) . direction ) ;
47
+ element . style . width = "100%" ;
48
+ element . style . height = "100%" ;
49
+ return element ;
50
+ } ,
51
+
52
+ // Retrieves a list of animation elements for the current page.
53
+ // If the page does not define a list, animate the entire page.
54
+ _getAnimationElements : function ( ) {
55
+ if ( this . pageControl && this . pageControl . getAnimationElements ) {
56
+ return this . pageControl . getAnimationElements ( ) ;
57
+ }
58
+ return this . pageElement ;
59
+ } ,
60
+
61
+ // Navigates back whenever the backspace key is pressed and
62
+ // not captured by an input field.
63
+ _keypressHandler : function ( args ) {
64
+ if ( args . key === "Backspace" ) {
65
+ nav . back ( ) ;
66
+ }
67
+ } ,
68
+
69
+ // Navigates back or forward when alt + left or alt + right
70
+ // key combinations are pressed.
71
+ _keyupHandler : function ( args ) {
72
+ if ( ( args . key === "Left" && args . altKey ) || ( args . key === "BrowserBack" ) ) {
73
+ nav . back ( ) ;
74
+ } else if ( ( args . key === "Right" && args . altKey ) || ( args . key === "BrowserForward" ) ) {
75
+ nav . forward ( ) ;
76
+ }
77
+ } ,
78
+
79
+ // This function responds to clicks to enable navigation using
80
+ // back and forward mouse buttons.
81
+ _mspointerupHandler : function ( args ) {
82
+ if ( args . button === 3 ) {
83
+ nav . back ( ) ;
84
+ } else if ( args . button === 4 ) {
85
+ nav . forward ( ) ;
86
+ }
87
+ } ,
88
+
89
+ // Responds to navigation by adding new pages to the DOM.
90
+ _navigated : function ( args ) {
91
+ var newElement = this . _createPageElement ( ) ;
92
+ var parentedComplete ;
93
+ var parented = new WinJS . Promise ( function ( c ) { parentedComplete = c ; } ) ;
94
+
95
+ this . _lastNavigationPromise . cancel ( ) ;
96
+
97
+ this . _lastNavigationPromise = WinJS . Promise . timeout ( ) . then ( function ( ) {
98
+ return WinJS . UI . Pages . render ( args . detail . location , newElement , args . detail . state , parented ) ;
99
+ } ) . then ( function parentElement ( control ) {
99
100
var oldElement = this . pageElement ;
100
101
if ( oldElement . winControl && oldElement . winControl . unload ) {
101
102
oldElement . winControl . unload ( ) ;
108
109
WinJS . UI . Animation . enterPage ( this . _getAnimationElements ( ) ) . done ( ) ;
109
110
} . bind ( this ) ) ;
110
111
111
- args . detail . setPromise ( this . _lastNavigationPromise ) ;
112
- } ,
112
+ args . detail . setPromise ( this . _lastNavigationPromise ) ;
113
+ } ,
113
114
114
- // Responds to resize events and call the updateLayout function
115
- // on the currently loaded page.
116
- _resized : function ( args ) {
117
- if ( this . pageControl && this . pageControl . updateLayout ) {
118
- this . pageControl . updateLayout . call ( this . pageControl , this . pageElement , appView . value , this . _lastViewstate ) ;
119
- }
120
- this . _lastViewstate = appView . value ;
121
- } ,
122
-
123
- // Updates the back button state. Called after navigation has
124
- // completed.
125
- _updateBackButton : function ( ) {
126
- var backButton = this . pageElement . querySelector ( "header[role=banner] .win-backbutton" ) ;
127
- if ( backButton ) {
128
- backButton . onclick = function ( ) { nav . back ( ) ; } ;
129
-
130
- if ( nav . canGoBack ) {
131
- backButton . removeAttribute ( "disabled" ) ;
132
- } else {
133
- backButton . setAttribute ( "disabled" , "disabled" ) ;
134
- }
115
+ // Responds to resize events and call the updateLayout function
116
+ // on the currently loaded page.
117
+ _resized : function ( args ) {
118
+ if ( this . pageControl && this . pageControl . updateLayout ) {
119
+ this . pageControl . updateLayout . call ( this . pageControl , this . pageElement , appView . value , this . _lastViewstate ) ;
120
+ }
121
+ this . _lastViewstate = appView . value ;
122
+ } ,
123
+
124
+ // Updates the back button state. Called after navigation has
125
+ // completed.
126
+ _updateBackButton : function ( ) {
127
+ var backButton = this . pageElement . querySelector ( "header[role=banner] .win-backbutton" ) ;
128
+ if ( backButton ) {
129
+ backButton . onclick = function ( ) { nav . back ( ) ; } ;
130
+
131
+ if ( nav . canGoBack ) {
132
+ backButton . removeAttribute ( "disabled" ) ;
133
+ } else {
134
+ backButton . setAttribute ( "disabled" , "disabled" ) ;
135
135
}
136
- } ,
137
- }
136
+ }
137
+ } ,
138
+ }
138
139
)
139
- } ) ;
140
- } ) ( ) ;
140
+
141
+ }
0 commit comments