| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @fileoverview Deferred resource loader for OOBE/Login screens. | 6 * @fileoverview Deferred resource loader for OOBE/Login screens. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 cr.define('cr.ui.login.ResourceLoader', function() { | 9 cr.define('cr.ui.login.ResourceLoader', function() { |
| 10 'use strict'; | 10 'use strict'; |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 }, { timeout: opt_idleTimeoutMs }); | 201 }, { timeout: opt_idleTimeoutMs }); |
| 202 }; | 202 }; |
| 203 | 203 |
| 204 if (document.readyState == 'complete') { | 204 if (document.readyState == 'complete') { |
| 205 loadOnIdle(); | 205 loadOnIdle(); |
| 206 } else { | 206 } else { |
| 207 window.addEventListener('DOMContentLoaded', loadOnIdle); | 207 window.addEventListener('DOMContentLoaded', loadOnIdle); |
| 208 } | 208 } |
| 209 } | 209 } |
| 210 | 210 |
| 211 /** |
| 212 * Wait until the element with the given |id| has finished its layout, |
| 213 * specifically, after it has an offsetHeight > 0. |
| 214 * @param {string} id Identifier of the element to wait for. |
| 215 * @param {function()} callback Function to invoke when done loading. |
| 216 */ |
| 217 function waitUntilLayoutComplete(id, callback) { |
| 218 var doWait = function() { |
| 219 var element = $(id); |
| 220 if (!element || !element.offsetHeight) { |
| 221 requestAnimationFrame(doWait); |
| 222 return; |
| 223 } |
| 224 |
| 225 callback(element); |
| 226 }; |
| 227 |
| 228 requestAnimationFrame(doWait); |
| 229 } |
| 230 |
| 211 return { | 231 return { |
| 212 alreadyLoadedAssets: alreadyLoadedAssets, | 232 alreadyLoadedAssets: alreadyLoadedAssets, |
| 213 hasDeferredAssets: hasDeferredAssets, | 233 hasDeferredAssets: hasDeferredAssets, |
| 214 loadAssets: loadAssets, | 234 loadAssets: loadAssets, |
| 215 loadAssetsOnIdle: loadAssetsOnIdle, | 235 loadAssetsOnIdle: loadAssetsOnIdle, |
| 236 waitUntilLayoutComplete: waitUntilLayoutComplete, |
| 216 registerAssets: registerAssets | 237 registerAssets: registerAssets |
| 217 }; | 238 }; |
| 218 }); | 239 }); |
| OLD | NEW |