Chromium Code Reviews| 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 * 'cr-settings-main' displays the selected settings page. | 7 * 'cr-settings-main' displays the selected settings page. |
| 8 * | 8 * |
| 9 * Example: | 9 * Example: |
| 10 * | 10 * |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 46 selectedPageId: '', | 46 selectedPageId: '', |
| 47 }, | 47 }, |
| 48 | 48 |
| 49 /** @override */ | 49 /** @override */ |
| 50 created: function() { | 50 created: function() { |
| 51 this.pages = []; | 51 this.pages = []; |
| 52 }, | 52 }, |
| 53 | 53 |
| 54 /** @override */ | 54 /** @override */ |
| 55 ready: function() { | 55 ready: function() { |
| 56 // Observe the core-animated-pages to keep this.pages in sync. | |
| 56 var observer = new MutationObserver(this.pageContainerUpdated_.bind(this)); | 57 var observer = new MutationObserver(this.pageContainerUpdated_.bind(this)); |
| 57 observer.observe(this.$.pageContainer, | 58 observer.observe(this.$.pageContainer, |
| 58 /** @type {MutationObserverInit} */ { | 59 /** @type {MutationObserverInit} */ { |
| 59 childList: true, | 60 childList: true, |
| 60 }); | 61 }); |
| 61 this.pages = this.$.pageContainer.items; | 62 this.pages = this.$.pageContainer.items; |
| 62 this.ensureSelection_(); | 63 |
| 64 if (this.pages.length) { | |
| 65 this.ensureSelection_(); | |
| 66 // Size the container once the selected page becomes visible. | |
| 67 this.async(function() { | |
| 68 this.sizeToPage_(this.$.pageContainer.selectedItem); | |
| 69 }.bind(this)); | |
|
Jeremy Klein
2015/03/18 00:12:05
this.async already binds to this:
https://www.pol
michaelpg
2015/03/18 01:40:09
Acknowledged.
| |
| 70 } | |
| 63 }, | 71 }, |
| 64 | 72 |
| 65 /** | 73 /** |
| 66 * If no page is selected, selects the first page. This happens on load and | 74 * If no page is selected, selects the first page. This happens on load and |
| 67 * when a selected page is removed. | 75 * when a selected page is removed. |
| 68 * | 76 * |
| 69 * @private | 77 * @private |
| 70 */ | 78 */ |
| 71 ensureSelection_: function() { | 79 ensureSelection_: function() { |
| 72 if (!this.pages.length) | 80 if (!this.pages.length) |
| 73 return; | 81 return; |
| 74 if (this.selectedPageId == '') | 82 if (this.selectedPageId == '') |
| 75 this.selectedPageId = this.pages[0].PAGE_ID; | 83 this.selectedPageId = this.pages[0].PAGE_ID; |
| 76 }, | 84 }, |
| 77 | 85 |
| 78 /** | 86 /** |
| 87 * Updates the height style for core-animated-pages using the page's | |
|
Jeremy Klein
2015/03/18 00:12:05
Is this really necessary? Does the core-animated-p
michaelpg
2015/03/18 01:40:09
This was my attempt to keep <paper-shadow> outside
| |
| 88 * scrollHeight. | |
| 89 * | |
| 90 * @param {HTMLElement} page | |
| 91 * @private | |
| 92 */ | |
| 93 sizeToPage_: function(page) { | |
| 94 if (page) | |
|
Kyle Horimoto
2015/03/17 23:53:48
When would page be falsey?
| |
| 95 this.$.pageContainer.style.height = page.scrollHeight + 'px'; | |
|
Kyle Horimoto
2015/03/17 23:53:48
Can you add a comment explaining this? It's not cl
| |
| 96 }, | |
| 97 | |
| 98 /** | |
| 79 * Updates the list of pages using the pages in core-animated-pages. | 99 * Updates the list of pages using the pages in core-animated-pages. |
| 80 * | 100 * |
| 81 * @private | 101 * @private |
| 82 */ | 102 */ |
| 83 pageContainerUpdated_: function() { | 103 pageContainerUpdated_: function() { |
| 84 this.pages = this.$.pageContainer.items; | 104 this.pages = this.$.pageContainer.items; |
| 85 this.ensureSelection_(); | 105 this.ensureSelection_(); |
| 86 }, | 106 }, |
| 107 | |
| 108 /** | |
| 109 * Updates the height of the core-animated-pages. Necessary because the | |
| 110 * pages are position: absolute, so the container won't size to the page. | |
|
Jeremy Klein
2015/03/18 00:12:05
It seems like the intended design here is to have
michaelpg
2015/03/18 00:18:00
I can't find a demo where the actual height of the
| |
| 111 * | |
| 112 * @private | |
| 113 */ | |
| 114 pageTransitionPrepared_: function() { | |
| 115 this.sizeToPage_(this.$.pageContainer.selectedItem); | |
| 116 }, | |
| 87 }); | 117 }); |
| OLD | NEW |