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
3 // found in the LICENSE file.
7 * 'cr-settings-page-header' shows a basic heading with a 'iron-icon'.
11 * <cr-settings-page-header page="{{page}}">
12 * </cr-settings-page-header>
14 * @group Chrome Settings Elements
15 * @element cr-settings-page-header
18 is: 'cr-settings-page-header',
22 * The current stack of pages being viewed. I.e., may contain subpages.
23 * @type {!Array<!HTMLElement>}
27 value: function() { return []; },
31 * The currently selected page.
32 * @type {?HTMLElement}
36 observer: 'selectedPageChanged_',
40 * The icon of the page at the root of the stack.
45 computed: 'getTopPageIcon_(pageStack)',
49 * The parent pages of the current page.
50 * @private {!Array<!HTMLElement>}
54 computed: 'getParentPages_(pageStack)',
58 * The title of the current page.
63 computed: 'getCurrentPageTitle_(pageStack)',
68 * @param {!Array<!HTMLElement>} pageStack
69 * @return {string} The icon for the top page in the stack.
72 getTopPageIcon_: function(pageStack) {
73 if (pageStack.length == 0)
75 return pageStack[0].icon;
79 * @param {!HTMLElement} page
80 * @return {string} A url link to the given page.
83 urlFor_: function(page) {
84 return page.route ? MoreRouting.urlFor(page.route) : '';
88 * @param {!Array<!HTMLElement>} pageStack
89 * @return {string} The title of the current page.
92 getCurrentPageTitle_: function(pageStack) {
93 if (pageStack.length == 0)
95 return pageStack[pageStack.length - 1].pageTitle;
99 selectedPageChanged_: function() {
100 if (this.selectedPage && this.selectedPage.subpage) {
101 // NOTE: Must reassign pageStack rather than doing push() so that the
102 // computed property (parentPages) will be notified of the update.
103 this.pageStack = this.pageStack.concat(this.selectedPage);
104 } else if (this.selectedPage) {
105 this.pageStack = [this.selectedPage];
110 * Gets the parent pages in the given page stack; i.e. returns all pages but
111 * the topmost subpage.
113 * @param {Array<HTMLElement>} stack
114 * @return {!Array<HTMLElement>}
117 getParentPages_: function(stack) {
118 if (!stack || stack.length <= 1) {
122 return stack.slice(0, stack.length - 1);