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-page-header' shows a basic heading with a 'iron-icon'. | 7 * 'cr-settings-page-header' shows a basic heading with a 'iron-icon'. |
8 * | 8 * |
9 * Example: | 9 * Example: |
10 * | 10 * |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 computed: 'getCurrentPageTitle_(pageStack)', | 63 computed: 'getCurrentPageTitle_(pageStack)', |
64 }, | 64 }, |
65 }, | 65 }, |
66 | 66 |
67 /** | 67 /** |
68 * @param {!Array<!HTMLElement>} pageStack | 68 * @param {!Array<!HTMLElement>} pageStack |
69 * @return {string} The icon for the top page in the stack. | 69 * @return {string} The icon for the top page in the stack. |
70 * @private | 70 * @private |
71 */ | 71 */ |
72 getTopPageIcon_: function(pageStack) { | 72 getTopPageIcon_: function(pageStack) { |
| 73 if (pageStack.length == 0) |
| 74 return ''; |
73 return pageStack[0].icon; | 75 return pageStack[0].icon; |
74 }, | 76 }, |
75 | 77 |
76 /** | 78 /** |
77 * @param {!HTMLElement} page | 79 * @param {!HTMLElement} page |
78 * @return {string} A url link to the given page. | 80 * @return {string} A url link to the given page. |
79 * @private | 81 * @private |
80 */ | 82 */ |
81 urlFor_: function(page) { | 83 urlFor_: function(page) { |
82 return page.route ? urlFor(page.route) : ''; | 84 return page.route ? urlFor(page.route) : ''; |
83 }, | 85 }, |
84 | 86 |
85 /** | 87 /** |
86 * @param {!Array<!HTMLElement>} pageStack | 88 * @param {!Array<!HTMLElement>} pageStack |
87 * @return {string} The title of the current page. | 89 * @return {string} The title of the current page. |
88 * @private | 90 * @private |
89 */ | 91 */ |
90 getCurrentPageTitle_: function(pageStack) { | 92 getCurrentPageTitle_: function(pageStack) { |
| 93 if (pageStack.length == 0) |
| 94 return ''; |
91 return pageStack[0].pageTitle; | 95 return pageStack[0].pageTitle; |
92 }, | 96 }, |
93 | 97 |
94 /** @private */ | 98 /** @private */ |
95 selectedPageChanged_: function() { | 99 selectedPageChanged_: function() { |
96 if (this.selectedPage.subpage) { | 100 if (this.selectedPage && this.selectedPage.subpage) { |
97 // NOTE: Must reassign pageStack rather than doing push() so that the | 101 // NOTE: Must reassign pageStack rather than doing push() so that the |
98 // computed property (parentPages) will be notified of the update. | 102 // computed property (parentPages) will be notified of the update. |
99 this.pageStack = this.pageStack.concat(this.selectedPage); | 103 this.pageStack = this.pageStack.concat(this.selectedPage); |
| 104 } else if (this.selectedPage) { |
| 105 this.pageStack = [this.selectedPage]; |
100 } else { | 106 } else { |
101 this.pageStack = [this.selectedPage]; | 107 this.pageStack = []; |
102 } | 108 } |
103 }, | 109 }, |
104 | 110 |
105 /** | 111 /** |
106 * Gets the parent pages in the given page stack; i.e. returns all pages but | 112 * Gets the parent pages in the given page stack; i.e. returns all pages but |
107 * the topmost subpage. | 113 * the topmost subpage. |
108 * | 114 * |
109 * @param {Array<HTMLElement>} stack | 115 * @param {Array<HTMLElement>} stack |
110 * @return {!Array<HTMLElement>} | 116 * @return {!Array<HTMLElement>} |
111 * @private | 117 * @private |
112 */ | 118 */ |
113 getParentPages_: function(stack) { | 119 getParentPages_: function(stack) { |
114 if (!stack || stack.length <= 1) { | 120 if (!stack || stack.length <= 1) { |
115 return []; | 121 return []; |
116 } | 122 } |
117 | 123 |
118 return stack.slice(0, stack.length - 1); | 124 return stack.slice(0, stack.length - 1); |
119 }, | 125 }, |
120 }); | 126 }); |
OLD | NEW |