Chromium Code Reviews| 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 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 206 } else { | 206 } else { |
| 207 // DOMContentLoaded has already been called if document.readyState is | 207 // DOMContentLoaded has already been called if document.readyState is |
| 208 // 'interactive' or 'complete', so invoke the callback immediately. | 208 // 'interactive' or 'complete', so invoke the callback immediately. |
| 209 loadOnIdle(); | 209 loadOnIdle(); |
| 210 } | 210 } |
| 211 } | 211 } |
| 212 | 212 |
| 213 /** | 213 /** |
| 214 * Wait until the element with the given |id| has finished its layout, | 214 * Wait until the element with the given |id| has finished its layout, |
| 215 * specifically, after it has an offsetHeight > 0. | 215 * specifically, after it has an offsetHeight > 0. |
| 216 * @param {string} id Identifier of the element to wait for. | 216 * @param {string} id Identifier of the element to wait for. |
|
jdufault
2016/06/23 19:51:15
Update docs.
sammiequon
2016/06/24 18:07:55
Done.
| |
| 217 * @param {function()} callback Function to invoke when done loading. | 217 * @param {function()} callback Function to invoke when done loading. |
| 218 */ | 218 */ |
| 219 function waitUntilLayoutComplete(id, callback) { | 219 function waitUntilLayoutComplete(selector, callback) { |
| 220 var type = typeof selector; | |
| 221 if (type != 'string' && type != 'function') | |
|
jdufault
2016/06/23 19:51:15
Crashing is typically better than silently failing
sammiequon
2016/06/24 18:07:55
Done.
| |
| 222 return; | |
| 223 | |
| 220 var doWait = function() { | 224 var doWait = function() { |
| 221 var element = $(id); | 225 var element; |
| 226 if (type == 'string') | |
|
jdufault
2016/06/23 19:51:15
Alternatively, you could make selector always be a
sammiequon
2016/06/24 18:07:55
Done.
| |
| 227 element = $(selector); | |
| 228 else | |
| 229 element = selector(); | |
| 230 | |
| 222 if (!element || !element.offsetHeight) { | 231 if (!element || !element.offsetHeight) { |
| 223 requestAnimationFrame(doWait); | 232 requestAnimationFrame(doWait); |
| 224 return; | 233 return; |
| 225 } | 234 } |
| 226 | 235 |
| 227 callback(element); | 236 callback(element); |
| 228 }; | 237 }; |
| 229 | 238 |
| 230 requestAnimationFrame(doWait); | 239 requestAnimationFrame(doWait); |
| 231 } | 240 } |
| 232 | 241 |
| 233 return { | 242 return { |
| 234 alreadyLoadedAssets: alreadyLoadedAssets, | 243 alreadyLoadedAssets: alreadyLoadedAssets, |
| 235 hasDeferredAssets: hasDeferredAssets, | 244 hasDeferredAssets: hasDeferredAssets, |
| 236 loadAssets: loadAssets, | 245 loadAssets: loadAssets, |
| 237 loadAssetsOnIdle: loadAssetsOnIdle, | 246 loadAssetsOnIdle: loadAssetsOnIdle, |
| 238 waitUntilLayoutComplete: waitUntilLayoutComplete, | 247 waitUntilLayoutComplete: waitUntilLayoutComplete, |
| 239 registerAssets: registerAssets | 248 registerAssets: registerAssets |
| 240 }; | 249 }; |
| 241 }); | 250 }); |
| OLD | NEW |