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-main' displays the selected settings page.
11 * <cr-settings-main pages="[[pages]]" selected-page-id="{{selectedId}}">
14 * See cr-settings-drawer for example of use in 'paper-drawer-panel'.
16 * @group Chrome Settings Elements
17 * @element cr-settings-main
20 is: 'cr-settings-main',
26 * @type {?CrSettingsPrefsElement}
34 * Pages that may be shown.
35 * @type {!Array<!HTMLElement>}
39 value: function() { return []; },
45 * Currently selected page.
46 * @type {?HTMLElement}
54 * ID of the currently selected page.
60 observer: 'selectedPageIdChanged_',
66 var observer = new MutationObserver(this.pageContainerUpdated_.bind(this));
67 observer.observe(this.$.pageContainer,
68 /** @type {MutationObserverInit} */ {
71 this.pageContainerUpdated_();
75 * Polymer changed event for selectedPageId. See note for onIronSelect_ below.
78 selectedPageIdChanged_: function() {
79 this.$.pageContainer.selected = this.selectedPageId;
83 * We observe $.pageContainer.on-iron-select instead of using data binding
85 * 1) We need to exclude subpages
86 * 2) There is a bug with data binding or our useage of it here causing
87 * this.selectedPage to get set to the index of $.pageContainer instead of
88 * the valueattr identifier (PAGE_ID). TODO(stevenjb/jlklien): Investigate
89 * fixing this and using filters once we switch to Polymer 0.8.
92 onIronSelect_: function(event) {
93 if (event.target != this.$.pageContainer || event.detail.item.subpage) {
96 this.selectedPageId = event.detail.item.PAGE_ID;
100 * If no page is selected, selects the first page. This happens on load and
101 * when a selected page is removed.
104 ensureSelection_: function() {
105 if (!this.pages.length)
107 if (this.selectedPageId == '')
108 this.selectedPageId = this.pages[0].PAGE_ID;
112 * Updates the list of pages using the pages in iron-pages.
115 pageContainerUpdated_: function() {
116 this._setPages(this.$.pageContainer.items.filter(function(item) {
117 return !item.subpage;
119 this.ensureSelection_();