Commit f7aca39a authored by Noel Gordon's avatar Noel Gordon Committed by Commit Bot

File manager main: use readyState "loading" DOMContentLoaded

main_scripts.js has a defer attribute: add DOMContentLoaded if needed,
ie., only if the document is loading. And modernize the remaining code
while here.

Bug: 887792
Change-Id: I04b9d346025d0f9a607772c2a340d80573489079
Reviewed-on: https://chromium-review.googlesource.com/1237801Reviewed-by: default avatarLuciano Pacheco <lucmult@chromium.org>
Commit-Queue: Luciano Pacheco <lucmult@chromium.org>
Cr-Commit-Position: refs/heads/master@{#593111}
parent dba33237
...@@ -3,32 +3,38 @@ ...@@ -3,32 +3,38 @@
// found in the LICENSE file. // found in the LICENSE file.
/** /**
* Creates the fileManager object. Note the DOM and external scripts are not
* fully loaded yet.
* @type {FileManager} * @type {FileManager}
*/ */
var fileManager; const fileManager = new FileManager();
/** /**
* Initializes the File Manager UI and starts the File Manager dialog. Called * Initialize the core stuff, which doesn't require access to the DOM, or to
* by main.html after the DOM and all scripts have been loaded. * external scripts.
* @param event DOMContentLoaded event.
*/ */
function init(event) { fileManager.initializeCore();
fileManager.initializeUI(document.body).then(function() {
util.testSendMessage('ready'); /**
* Initializes the File Manager's UI. Called after the DOM, and all external
* scripts, have been loaded.
*/
function initializeUI() {
fileManager.initializeUI(document.body).then(() => {
metrics.recordInterval('Load.Total'); metrics.recordInterval('Load.Total');
fileManager.tracker.send(metrics.Management.WINDOW_CREATED); fileManager.tracker.send(metrics.Management.WINDOW_CREATED);
}); });
} }
// Creates the File Manager object. Note that the DOM, or any external /**
// scripts, may not be ready yet. * Final initialization performed after DOM and all scripts have loaded. See
fileManager = new FileManager(); * also crbug.com/581028 which added a 'defer' attribute to main_scripts.js.
*/
// Initialize the core stuff, which doesn't require access to the DOM or if (document.readyState === 'loading') {
// to external scripts. document.addEventListener('DOMContentLoaded', initializeUI);
fileManager.initializeCore(); } else {
initializeUI();
// Final initialization performed after DOM and all scripts have loaded. }
document.addEventListener('DOMContentLoaded', init);
metrics.recordInterval('Load.Script'); // Must be the last line. /** Record script load metric: must be the last line. */
metrics.recordInterval('Load.Script');
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment