Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(287)

Side by Side Diff: chrome/browser/resources/settings/settings_main/settings_main.js

Issue 1141603003: Convert cr-settings-main to Polymer 0.8 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 *
11 * <cr-settings-main pages="{{pages}}" selectedPageId="{{selectedId}}"> 11 * <cr-settings-main pages="[[pages]]" selectedPageId="{{selectedId}}">
Jeremy Klein 2015/05/12 18:18:39 selected-page-id https://www.polymer-project.org/
12 * </cr-settings-main> 12 * </cr-settings-main>
13 * 13 *
14 * See cr-settings-drawer for example of use in 'core-drawer-panel'. 14 * See cr-settings-drawer for example of use in 'paper-drawer-panel'.
15 * 15 *
16 * @group Chrome Settings Elements 16 * @group Chrome Settings Elements
17 * @element cr-settings-main 17 * @element cr-settings-main
18 */ 18 */
19 Polymer('cr-settings-main', { 19 Polymer({
20 publish: { 20 is: 'cr-settings-main',
21
22 properties: {
21 /** 23 /**
22 * Preferences state. 24 * Preferences state.
23 * 25 *
24 * @attribute prefs 26 * @type {CrSettingsPrefsElement}
Jeremy Klein 2015/05/12 18:18:39 ?CrSettingsPrefsElement
michaelpg 2015/05/12 18:42:50 Done.
25 * @type CrSettingsPrefsElement
26 * @default null
27 */ 27 */
28 prefs: null, 28 prefs: {
29 type: Object,
30 notify: true,
31 },
29 32
30 /** 33 /**
31 * Pages that may be shown. 34 * Pages that may be shown.
32 * 35 *
33 * @attribute pages 36 * @type {Array<!Object>}
Jeremy Klein 2015/05/12 18:18:39 ?Array or initialize to [].
34 * @type Array<!Object>
35 * @default null
36 */ 37 */
37 pages: null, 38 pages: Array,
39
40 /**
41 * Currently selected page.
Jeremy Klein 2015/05/12 18:18:39 "@type {?HTMLElement}"? We'll need to think a bit
michaelpg 2015/05/12 18:42:50 Done.
42 */
43 selectedPage: {
44 type: Object,
45 notify: true,
46 },
38 47
39 /** 48 /**
40 * ID of the currently selected page. 49 * ID of the currently selected page.
41 *
42 * @attribute selectedPageId
43 * @type string
44 * default ''
45 */ 50 */
46 selectedPageId: '', 51 selectedPageId: {
52 type: String,
53 notify: true,
54 observe: 'selectedPageIdChanged',
55 },
47 }, 56 },
48 57
49 /** @override */ 58 /** @override */
50 created: function() {
51 this.pages = [];
52 },
53
54 /** @override */
55 ready: function() { 59 ready: function() {
56 var observer = new MutationObserver(this.pageContainerUpdated_.bind(this)); 60 var observer = new MutationObserver(this.pageContainerUpdated_.bind(this));
57 observer.observe(this.$.pageContainer, 61 observer.observe(this.$.pageContainer,
58 /** @type {MutationObserverInit} */ { 62 /** @type {MutationObserverInit} */ {
59 childList: true, 63 childList: true,
60 }); 64 });
61 this.pageContainerUpdated_(); 65 this.pageContainerUpdated_();
62 }, 66 },
63 67
64 /** 68 /**
65 * Polymer changed event for selectedPageId. See note for onCoreSelect_ below. 69 * Polymer changed event for selectedPageId. See note for onIronSelect_ below.
66 */ 70 */
67 selectedPageIdChanged: function() { 71 selectedPageIdChanged: function() {
Jeremy Klein 2015/05/12 18:18:39 nit: Can this be private?
michaelpg 2015/05/12 18:42:49 Done.
68 this.$.pageContainer.selected = this.selectedPageId; 72 this.$.pageContainer.selected = this.selectedPageId;
69 }, 73 },
70 74
71 /** 75 /**
72 * We observe $.pageContainer.on-core-select instead of using data binding 76 * We observe $.pageContainer.on-iron-select instead of using data binding
73 * for two reasons: 77 * for two reasons:
74 * 1) We need to exclude subpages 78 * 1) We need to exclude subpages
75 * 2) There is a bug with data binding or our useage of it here causing 79 * 2) There is a bug with data binding or our useage of it here causing
76 * this.selectedPage to get set to the index of $.pageContainer instead of 80 * this.selectedPage to get set to the index of $.pageContainer instead of
77 * the valueattr identifier (PAGE_ID). TODO(stevenjb/jlklien): Investigate 81 * the valueattr identifier (PAGE_ID). TODO(stevenjb/jlklien): Investigate
78 * fixing this and using filters once we switch to Polymer 0.8. 82 * fixing this and using filters once we switch to Polymer 0.8.
79 * @private 83 * @private
80 */ 84 */
81 onCoreSelect_: function(event) { 85 onIronSelect_: function(event) {
82 if (event.target != this.$.pageContainer || !event.detail.isSelected || 86 if (event.target != this.$.pageContainer || !event.detail.isSelected ||
83 event.detail.item.subpage) { 87 event.detail.item.subpage) {
84 return; 88 return;
85 } 89 }
86 this.selectedPageId = event.detail.item.PAGE_ID; 90 this.selectedPageId = event.detail.item.PAGE_ID;
87 }, 91 },
88 92
89 /** 93 /**
90 * If no page is selected, selects the first page. This happens on load and 94 * If no page is selected, selects the first page. This happens on load and
91 * when a selected page is removed. 95 * when a selected page is removed.
92 * 96 *
93 * @private 97 * @private
94 */ 98 */
95 ensureSelection_: function() { 99 ensureSelection_: function() {
96 if (!this.pages.length) 100 if (!this.pages.length)
97 return; 101 return;
98 if (this.selectedPageId == '') 102 if (this.selectedPageId == '')
99 this.selectedPageId = this.pages[0].PAGE_ID; 103 this.selectedPageId = this.pages[0].PAGE_ID;
100 }, 104 },
101 105
102 /** 106 /**
103 * Updates the list of pages using the pages in core-animated-pages. 107 * Updates the list of pages using the pages in iron-pages.
104 * 108 *
105 * @private 109 * @private
106 */ 110 */
107 pageContainerUpdated_: function() { 111 pageContainerUpdated_: function() {
108 this.pages = this.$.pageContainer.items.filter(function(item) { 112 this.pages = this.$.pageContainer.items.filter(function(item) {
109 return !item.subpage; 113 return !item.subpage;
110 }); 114 });
111 this.ensureSelection_(); 115 this.ensureSelection_();
112 }, 116 },
113 }); 117 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698