Chromium Code Reviews| Index: chrome/browser/resources/settings/settings_page/settings_animated_pages.js |
| diff --git a/chrome/browser/resources/settings/settings_page/settings_animated_pages.js b/chrome/browser/resources/settings/settings_page/settings_animated_pages.js |
| index 26f406593e79f9b2c969050019429a5b14d7cd9b..c374b93fb7b23c5dfbc4d49dc73d4b8c77a51a38 100644 |
| --- a/chrome/browser/resources/settings/settings_page/settings_animated_pages.js |
| +++ b/chrome/browser/resources/settings/settings_page/settings_animated_pages.js |
| @@ -41,6 +41,10 @@ Polymer({ |
| /** @override */ |
| created: function() { |
| + // Observe the light DOM so we know when it's ready. |
| + this.lightDomObserver_ = Polymer.dom(this).observeNodes( |
| + this.lightDomChanged_.bind(this)); |
| + |
| this.addEventListener('subpage-back', function() { |
| assert(this.currentRoute.section == this.section); |
| assert(this.currentRoute.subpage.length >= 1); |
| @@ -49,14 +53,52 @@ Polymer({ |
| }.bind(this)); |
| }, |
| + /** |
| + * Called initially once the effective children are ready. |
| + * @private |
| + */ |
| + lightDomChanged_: function() { |
| + if (this.lightDomReady_) |
| + return; |
| + |
| + this.lightDomReady_ = true; |
| + Polymer.dom(this).unobserveNodes(this.lightDomObserver_); |
| + this.runQueuedRouteChange_(); |
| + }, |
| + |
| + /** |
| + * Calls currentRouteChanged_ with the deferred route change info. |
| + * @private |
| + */ |
| + runQueuedRouteChange_: function() { |
| + if (!this._queuedRouteChange) |
|
Dan Beam
2016/03/25 03:21:59
shouldn't this be queuedRouteChange_?
michaelpg
2016/03/29 22:04:03
Done.
|
| + return; |
| + this.async(this.currentRouteChanged_.bind( |
| + this, |
| + this._queuedRouteChange.newRoute, |
| + this._queuedRouteChange.oldRoute)); |
| + }, |
| + |
| /** @private */ |
| currentRouteChanged_: function(newRoute, oldRoute) { |
| + // Don't manipulate the light DOM until it's ready. |
| + if (!this.lightDomReady_) { |
| + if (!this._queuedRouteChange) |
| + this._queuedRouteChange = {newRoute: newRoute, oldRoute: oldRoute}; |
| + else |
| + this._queuedRouteChange.newRoute = newRoute; |
|
Dan Beam
2016/03/25 03:21:59
nit:
this.queuedRouteChange_ = this.queuedRouteCh
michaelpg
2016/03/29 22:04:03
Done.
|
| + return; |
| + } |
| + |
| // route.section is only non-empty when the user is within a subpage. |
| // When the user is not in a subpage, but on the Basic page, route.section |
| // is an empty string. |
| var newRouteIsSubpage = newRoute && newRoute.section == this.section; |
| var oldRouteIsSubpage = oldRoute && oldRoute.section == this.section; |
| + if (newRouteIsSubpage) |
| + this.ensureSubpageInstance_(); |
| + |
| if (!newRouteIsSubpage || !oldRouteIsSubpage || |
| newRoute.subpage.length == oldRoute.subpage.length) { |
| // If two routes are at the same level, or if either the new or old route |
| @@ -79,6 +121,25 @@ Polymer({ |
| }, |
| /** |
| + * Ensures that the template enclosing the subpage is stamped. |
| + * @private |
| + */ |
| + ensureSubpageInstance_: function() { |
| + var id = this.currentRoute.subpage.slice(-1)[0]; |
| + var template = Polymer.dom(this).querySelector( |
| + 'template[name="' + id + '"]'); |
| + |
| + // Set the subpage's id for use by neon-animated-pages. |
| + var subpage = template._content.querySelector('settings-subpage'); |
| + if (!subpage.id) |
| + subpage.id = id; |
| + |
| + // Render synchronously so neon-animated-pages can select the subpage. |
| + template.if = true; |
| + template.render(); |
|
Dan Beam
2016/03/25 03:21:59
why is this better than using the standard declara
michaelpg
2016/03/29 22:04:03
for declarative binding, we'd have to define ensur
|
| + }, |
| + |
| + /** |
| * Buttons in this pageset should use this method to transition to subpages. |
| */ |
| setSubpageChain: function(subpage) { |