| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 | 6 * @fileoverview |
| 7 * 'settings-animated-pages' is a container for a page and animated subpages. | 7 * 'settings-animated-pages' is a container for a page and animated subpages. |
| 8 * It provides a set of common behaviors and animations. | 8 * It provides a set of common behaviors and animations. |
| 9 * | 9 * |
| 10 * Example: | 10 * Example: |
| 11 * | 11 * |
| 12 * <settings-animated-pages section="privacy"> | 12 * <settings-animated-pages section="privacy"> |
| 13 * <!-- Insert your section controls here --> | 13 * <!-- Insert your section controls here --> |
| 14 * </settings-animated-pages> | 14 * </settings-animated-pages> |
| 15 */ | 15 */ |
| 16 |
| 16 Polymer({ | 17 Polymer({ |
| 17 is: 'settings-animated-pages', | 18 is: 'settings-animated-pages', |
| 18 | 19 |
| 19 behaviors: [settings.RouteObserverBehavior], | 20 behaviors: [settings.RouteObserverBehavior], |
| 20 | 21 |
| 21 properties: { | 22 properties: { |
| 22 /** | 23 /** |
| 23 * Routes with this section activate this element. For instance, if this | 24 * Routes with this section activate this element. For instance, if this |
| 24 * property is 'search', and currentRoute.section is also set to 'search', | 25 * property is 'search', and currentRoute.section is also set to 'search', |
| 25 * this element will display the subpage in currentRoute.subpage. | 26 * this element will display the subpage in currentRoute.subpage. |
| 26 * | 27 * |
| 27 * The section name must match the name specified in route.js. | 28 * The section name must match the name specified in route.js. |
| 28 */ | 29 */ |
| 29 section: { | 30 section: String, |
| 30 type: String, | 31 |
| 31 }, | 32 /** |
| 33 * A Map specifying which element should be focused when exiting a subpage. |
| 34 * The key of the map holds a settings.Route path, and the value holds a |
| 35 * query selector that identifies the desired element. |
| 36 * @type {?Map<string, string>} |
| 37 */ |
| 38 focusConfig: Object, |
| 32 }, | 39 }, |
| 33 | 40 |
| 41 /** |
| 42 * The last "previous" route reported by the router. |
| 43 * @private {?settings.Route} |
| 44 */ |
| 45 previousRoute_: null, |
| 46 |
| 34 /** @override */ | 47 /** @override */ |
| 35 created: function() { | 48 created: function() { |
| 36 // Observe the light DOM so we know when it's ready. | 49 // Observe the light DOM so we know when it's ready. |
| 37 this.lightDomObserver_ = Polymer.dom(this).observeNodes( | 50 this.lightDomObserver_ = Polymer.dom(this).observeNodes( |
| 38 this.lightDomChanged_.bind(this)); | 51 this.lightDomChanged_.bind(this)); |
| 39 }, | 52 }, |
| 40 | 53 |
| 41 /** | 54 /** |
| 55 * @param {!Event} e |
| 56 * @private |
| 57 */ |
| 58 onIronSelect_: function(e) { |
| 59 if (!this.focusConfig || !this.previousRoute_ || |
| 60 e.detail.item.tagName != 'NEON-ANIMATABLE') { |
| 61 return; |
| 62 } |
| 63 |
| 64 var selector = this.focusConfig.get(this.previousRoute_.path); |
| 65 if (selector) { |
| 66 // neon-animatable has "display: none" until the animation finishes, so |
| 67 // calling focus() on any of its children has no effect until |
| 68 // "display: none" is removed. Therefore can't call focus() from within |
| 69 // the currentRouteChanged callback. Using 'iron-select' listener which |
| 70 // fires after the animation has finished allows focus() to work as |
| 71 // expected. |
| 72 this.querySelector(selector).focus(); |
| 73 } |
| 74 }, |
| 75 |
| 76 /** |
| 42 * Called initially once the effective children are ready. | 77 * Called initially once the effective children are ready. |
| 43 * @private | 78 * @private |
| 44 */ | 79 */ |
| 45 lightDomChanged_: function() { | 80 lightDomChanged_: function() { |
| 46 if (this.lightDomReady_) | 81 if (this.lightDomReady_) |
| 47 return; | 82 return; |
| 48 | 83 |
| 49 this.lightDomReady_ = true; | 84 this.lightDomReady_ = true; |
| 50 Polymer.dom(this).unobserveNodes(this.lightDomObserver_); | 85 Polymer.dom(this).unobserveNodes(this.lightDomObserver_); |
| 51 this.runQueuedRouteChange_(); | 86 this.runQueuedRouteChange_(); |
| 52 }, | 87 }, |
| 53 | 88 |
| 54 /** | 89 /** |
| 55 * Calls currentRouteChanged with the deferred route change info. | 90 * Calls currentRouteChanged with the deferred route change info. |
| 56 * @private | 91 * @private |
| 57 */ | 92 */ |
| 58 runQueuedRouteChange_: function() { | 93 runQueuedRouteChange_: function() { |
| 59 if (!this.queuedRouteChange_) | 94 if (!this.queuedRouteChange_) |
| 60 return; | 95 return; |
| 61 this.async(this.currentRouteChanged.bind( | 96 this.async(this.currentRouteChanged.bind( |
| 62 this, | 97 this, |
| 63 this.queuedRouteChange_.newRoute, | 98 this.queuedRouteChange_.newRoute, |
| 64 this.queuedRouteChange_.oldRoute)); | 99 this.queuedRouteChange_.oldRoute)); |
| 65 }, | 100 }, |
| 66 | 101 |
| 67 /** @protected */ | 102 /** @protected */ |
| 68 currentRouteChanged: function(newRoute, oldRoute) { | 103 currentRouteChanged: function(newRoute, oldRoute) { |
| 104 this.previousRoute_ = oldRoute; |
| 105 |
| 69 if (newRoute.section == this.section && newRoute.isSubpage()) { | 106 if (newRoute.section == this.section && newRoute.isSubpage()) { |
| 70 this.switchToSubpage_(newRoute, oldRoute); | 107 this.switchToSubpage_(newRoute, oldRoute); |
| 71 } else { | 108 } else { |
| 72 this.$.animatedPages.exitAnimation = 'fade-out-animation'; | 109 this.$.animatedPages.exitAnimation = 'fade-out-animation'; |
| 73 this.$.animatedPages.entryAnimation = 'fade-in-animation'; | 110 this.$.animatedPages.entryAnimation = 'fade-in-animation'; |
| 74 this.$.animatedPages.selected = 'default'; | 111 this.$.animatedPages.selected = 'default'; |
| 75 } | 112 } |
| 76 }, | 113 }, |
| 77 | 114 |
| 78 /** | 115 /** |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 // instance, such that the stamped instance will also be ignored by the | 181 // instance, such that the stamped instance will also be ignored by the |
| 145 // searching algorithm. | 182 // searching algorithm. |
| 146 if (template.hasAttribute('no-search')) | 183 if (template.hasAttribute('no-search')) |
| 147 subpage.setAttribute('no-search', ''); | 184 subpage.setAttribute('no-search', ''); |
| 148 | 185 |
| 149 // Render synchronously so neon-animated-pages can select the subpage. | 186 // Render synchronously so neon-animated-pages can select the subpage. |
| 150 template.if = true; | 187 template.if = true; |
| 151 template.render(); | 188 template.render(); |
| 152 }, | 189 }, |
| 153 }); | 190 }); |
| OLD | NEW |