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..574350715c0b614aee8cf2211cb636011b3f8352 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,50 @@ 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_) |
+ 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_) { |
+ this.queuedRouteChange_ = this.queuedRouteChange_ || {oldRoute: oldRoute}; |
+ this.queuedRouteChange_.newRoute = newRoute; |
+ 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 +119,30 @@ 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 + '"]'); |
+ |
+ // Do nothing if the subpage is already stamped. |
+ if (template.if) |
+ return; |
+ |
+ // Set the subpage's id for use by neon-animated-pages. |
+ var subpage = /** @type {{_content: DocumentFragment}} */(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(); |
+ }, |
+ |
+ /** |
* Buttons in this pageset should use this method to transition to subpages. |
*/ |
setSubpageChain: function(subpage) { |