21
21
* <http://www.gnu.org/licenses/>.
22
22
*/
23
23
24
- // Import Chromeless libraries
24
+ // Import Chromeless modules
25
25
var favicon = require ( "favicon" ) ;
26
+ var web_content = require ( "web-content" ) ;
26
27
const url = require ( "url" ) ;
28
+ const fullscreen = require ( "fullscreen" ) ;
27
29
28
30
// Set up console for debugging
29
31
//console.log('hello world');
@@ -56,82 +58,28 @@ function clock() {
56
58
* Make iFrame
57
59
*
58
60
* Creates a special iFrame which acts like a browser and will contain the
59
- * content of a new window. Event listeners are added to monitor progress
60
- * of page loading.
61
+ * content of a new window.
61
62
*
62
63
* @return new iFrame object
63
64
*/
64
65
function makeIframe ( windowId ) {
65
66
var iFrame = document . createElement ( "iframe" ) ;
66
67
$ ( iFrame ) . attr ( "privilege" , "content" ) ;
67
68
$ ( iFrame ) . attr ( "class" , "window_iframe" ) ;
68
-
69
- var url_input = $ ( '#window_' + windowId + ' .url_input' ) ;
70
-
71
- // Add event listeners to iFrame...
72
-
73
- // Check progress of page load...
74
- iFrame . addEventListener ( "ChromelessLoadProgress" , function ( e ) {
75
- $ ( url_input ) . addClass ( 'loading' ) ;
76
- $ ( url_input ) . css ( '-moz-background-size' , e . percentage + "%" ) ;
77
- $ ( url_input ) . css ( 'background-size' , e . percentage + "%" ) ;
78
- }
79
- , false ) ;
80
-
81
- // When page starts to load...
82
- iFrame . addEventListener ( "ChromelessLoadStart" , function ( e ) {
83
- // Update address bar
84
- $ ( url_input ) . val ( e . url ) ;
85
- // Set go button as stop button
86
- $ ( "#window_" + windowId + " .go_button" ) . attr ( "src" , "stop.png" ) ;
87
- // If URL has changed, add to history and update index
88
- if ( e . url !== urlHistory [ windowId ] [ urlHistory [ windowId ] [ 0 ] ] ) {
89
- // Remove previous future if new future being created!
90
- if ( urlHistory [ windowId ] [ 0 ] < urlHistory [ windowId ] . length ) {
91
- urlHistory [ windowId ] . splice (
92
- urlHistory [ windowId ] [ 0 ] + 1 ,
93
- urlHistory [ windowId ] . length - urlHistory [ windowId ] [ 0 ] ) ;
94
- }
95
-
96
- // Add new URL to history
97
- urlHistory [ windowId ] . push ( e . url ) ;
98
-
99
- // Update index
100
- urlHistory [ windowId ] [ 0 ] ++ ;
101
- }
102
- } , false , true ) ;
103
-
104
- // When page and contents are completely loaded...
105
- iFrame . addEventListener ( "ChromelessLoadStop" , function ( e ) {
106
- // Set URL input textbox to loaded state
107
- $ ( url_input ) . removeClass ( 'loading' ) ;
108
- $ ( url_input ) . addClass ( 'loaded' ) ;
109
- // Change "Go" button to "Refresh"
110
- $ ( '#window_' + windowId + ' .go_button' ) . attr ( "src" , "refresh.png" ) ;
111
- // Display document title if set
112
- var window_iframe = $ ( "#windows .selected .window_iframe" ) [ 0 ] ;
113
- var document_title = require ( "iframe-controls" ) . title ( window_iframe ) ;
114
- if ( document_title ) {
115
- $ ( '#window_' + windowId + ' .document_title' ) . addClass ( "active" ) ;
116
- $ ( '#window_' + windowId + ' .document_title' ) . text ( document_title ) ;
117
- } else {
118
- $ ( '#window_' + windowId + ' .document_title' ) . removeClass ( "active" ) ;
119
- }
120
- } , false , true ) ;
121
-
122
69
return iFrame ;
123
70
}
124
71
125
72
/**
126
73
* Register Window Event Listeners
127
74
*
128
75
* Registers event listeners for the currently selected window to detect
129
- * user actions like go, back forward etc.
76
+ * user actions like go, back forward etc. and attaches progress monitor to
77
+ * iFrame.
130
78
*
131
79
* @param {String } windowId of window to register listeners for
132
80
*/
133
81
function registerWindowEventListeners ( windowId ) {
134
- var url_input = $ ( " #window_" + windowId + " .url_input" ) ;
82
+ var url_input = $ ( ' #window_' + windowId + ' .url_input' ) ;
135
83
var go_button = $ ( "#window_" + windowId + " .go_button" ) ;
136
84
137
85
// When URL input text box is selected, change "Refresh" button to "Go" button and remove loaded state
@@ -152,11 +100,11 @@ function registerWindowEventListeners(windowId) {
152
100
$ ( "#window_" + windowId + " .url_form" ) . submit ( function ( ) {
153
101
navigate ( $ ( this ) . parents ( ".window" ) . attr ( "id" ) . substring ( 7 ) ) ; return false ;
154
102
} ) ;
155
- $ ( "#window_" + windowId + " . go_button" ) . click ( function ( ) {
103
+ $ ( go_button ) . click ( function ( ) {
156
104
// If loading then act as stop button
157
105
if ( $ ( '#windows .selected .url_input' ) . hasClass ( 'loading' ) ) {
158
106
var window_iframe = $ ( "#windows .selected .window_iframe" ) [ 0 ] ;
159
- require ( "iframe-controls" ) . stopload ( window_iframe ) ;
107
+ web_content . stopload ( window_iframe ) ;
160
108
$ ( go_button ) . attr ( "src" , "refresh.png" ) ;
161
109
} else {
162
110
// otherwise act as go/refresh
@@ -194,6 +142,71 @@ function registerWindowEventListeners(windowId) {
194
142
} ) ;
195
143
}
196
144
145
+ /**
146
+ * Attach iFrame Progress Monitor
147
+ *
148
+ * Attach progress monitor to react to page load progress.
149
+ *
150
+ * @param {String } windowId of window containing iFrame to listen to
151
+ */
152
+ function attachIframeProgressMonitor ( windowId ) {
153
+ var progressMonitor = web_content . ProgressMonitor ( ) ;
154
+ var window_iframe = $ ( '#window_' + windowId + ' .window_iframe' ) ;
155
+ var url_input = $ ( '#window_' + windowId + ' .url_input' ) ;
156
+
157
+ // Add progress monitor to iFrame...
158
+ progressMonitor . attach ( window_iframe [ 0 ] ) ;
159
+
160
+ // Check progress of page load...
161
+ progressMonitor . on ( 'progress' , function ( percent ) {
162
+ $ ( url_input ) . addClass ( 'loading' ) ;
163
+ $ ( url_input ) . css ( '-moz-background-size' , percent + "%" ) ;
164
+ $ ( url_input ) . css ( 'background-size' , percent + "%" ) ;
165
+ } ) ;
166
+
167
+ // When page starts to load...
168
+ progressMonitor . on ( 'load-start' , function ( url ) {
169
+ // Update address bar
170
+ $ ( url_input ) . val ( url ) ;
171
+ // Set go button as stop button
172
+ $ ( "#window_" + windowId + " .go_button" ) . attr ( "src" , "stop.png" ) ;
173
+ // If URL has changed, add to history and update index
174
+ if ( url !== urlHistory [ windowId ] [ urlHistory [ windowId ] [ 0 ] ] ) {
175
+ // Remove previous future if new future being created!
176
+ if ( urlHistory [ windowId ] [ 0 ] < urlHistory [ windowId ] . length ) {
177
+ urlHistory [ windowId ] . splice (
178
+ urlHistory [ windowId ] [ 0 ] + 1 ,
179
+ urlHistory [ windowId ] . length - urlHistory [ windowId ] [ 0 ] ) ;
180
+ }
181
+
182
+ // Add new URL to history
183
+ urlHistory [ windowId ] . push ( url ) ;
184
+
185
+ // Update index
186
+ urlHistory [ windowId ] [ 0 ] ++ ;
187
+ }
188
+ } ) ;
189
+
190
+ // When page and contents are completely loaded...
191
+ progressMonitor . on ( 'load-stop' , function ( ) {
192
+ // Set URL input textbox to loaded state
193
+ $ ( url_input ) . removeClass ( 'loading' ) ;
194
+ $ ( url_input ) . addClass ( 'loaded' ) ;
195
+ // Change "Go" button to "Refresh"
196
+ $ ( '#window_' + windowId + ' .go_button' ) . attr ( "src" , "refresh.png" ) ;
197
+ } ) ;
198
+
199
+
200
+ // When title changes...
201
+ progressMonitor . on ( 'title-change' , function ( document_title ) {
202
+ if ( document_title ) {
203
+ $ ( '#window_' + windowId + ' .document_title' ) . addClass ( "active" ) ;
204
+ $ ( '#window_' + windowId + ' .document_title' ) . text ( document_title ) ;
205
+ }
206
+ } ) ;
207
+
208
+ }
209
+
197
210
/**
198
211
* Select Tab
199
212
*
@@ -244,6 +257,9 @@ function newTab(url) {
244
257
// Register window event listeners
245
258
registerWindowEventListeners ( windowId ) ;
246
259
260
+ // Attach iFrame progress monitor
261
+ attachIframeProgressMonitor ( windowId ) ;
262
+
247
263
// Create history array for window, using first element as index
248
264
urlHistory [ windowId ] = [ ] ;
249
265
urlHistory [ windowId ] [ 0 ] = 0 ;
@@ -331,18 +347,6 @@ function activateWindows() {
331
347
$ ( "#tabs" ) . removeClass ( "detached" ) ;
332
348
}
333
349
334
-
335
- /**
336
- * Full Screen
337
- *
338
- * Toggle full screen mode
339
- */
340
- function fullScreen ( ) {
341
- const fullscreen = require ( "fullscreen" ) ;
342
- fullscreen . toggle ( window ) ;
343
- }
344
-
345
-
346
350
// When Shell starts up...
347
351
$ ( document ) . ready ( function ( ) {
348
352
@@ -368,5 +372,5 @@ $(document).ready(function() {
368
372
} ) ;
369
373
370
374
// Wait for MS Windows to catch up, then toggle full screen mode
371
- setTimeout ( "fullScreen( )" , 2000 ) ;
375
+ setTimeout ( "fullscreen.toggle(window )" , 2000 ) ;
372
376
} ) ;
0 commit comments