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 14 matching lines...) Expand all Loading... | |
25 * | 25 * |
26 * @type {?CrSettingsPrefsElement} | 26 * @type {?CrSettingsPrefsElement} |
27 */ | 27 */ |
28 prefs: { | 28 prefs: { |
29 type: Object, | 29 type: Object, |
30 notify: true, | 30 notify: true, |
31 }, | 31 }, |
32 | 32 |
33 /** | 33 /** |
34 * Pages that may be shown. | 34 * Pages that may be shown. |
35 * @type {?Array<!HTMLElement>} | 35 * @type {!Array<!HTMLElement>} |
36 */ | 36 */ |
37 pages: Array, | 37 pages: { |
38 type: Array, | |
39 value: function() { return []; }, | |
40 notify: true, | |
41 readOnly: true, | |
42 observer: 'pagesChanged_', | |
michaelpg
2015/05/13 19:59:19
pagesChanged_ is undefined?
Jeremy Klein
2015/05/13 21:13:56
Ah I had added that for debugging and then removed
| |
43 }, | |
38 | 44 |
39 /** | 45 /** |
40 * Currently selected page. | 46 * Currently selected page. |
41 * @type {?HTMLElement} | 47 * @type {?HTMLElement} |
42 */ | 48 */ |
43 selectedPage: { | 49 selectedPage: { |
44 type: Object, | 50 type: Object, |
45 notify: true, | 51 notify: true, |
46 }, | 52 }, |
47 | 53 |
48 /** | 54 /** |
49 * ID of the currently selected page. | 55 * ID of the currently selected page. |
50 */ | 56 */ |
51 selectedPageId: { | 57 selectedPageId: { |
52 type: String, | 58 type: String, |
53 notify: true, | 59 notify: true, |
54 observe: 'selectedPageIdChanged_', | 60 value: '', |
61 observer: 'selectedPageIdChanged_', | |
55 }, | 62 }, |
56 }, | 63 }, |
57 | 64 |
58 /** @override */ | 65 /** @override */ |
59 ready: function() { | 66 ready: function() { |
60 var observer = new MutationObserver(this.pageContainerUpdated_.bind(this)); | 67 var observer = new MutationObserver(this.pageContainerUpdated_.bind(this)); |
61 observer.observe(this.$.pageContainer, | 68 observer.observe(this.$.pageContainer, |
62 /** @type {MutationObserverInit} */ { | 69 /** @type {MutationObserverInit} */ { |
63 childList: true, | 70 childList: true, |
64 }); | 71 }); |
(...skipping 12 matching lines...) Expand all Loading... | |
77 * We observe $.pageContainer.on-iron-select instead of using data binding | 84 * We observe $.pageContainer.on-iron-select instead of using data binding |
78 * for two reasons: | 85 * for two reasons: |
79 * 1) We need to exclude subpages | 86 * 1) We need to exclude subpages |
80 * 2) There is a bug with data binding or our useage of it here causing | 87 * 2) There is a bug with data binding or our useage of it here causing |
81 * this.selectedPage to get set to the index of $.pageContainer instead of | 88 * this.selectedPage to get set to the index of $.pageContainer instead of |
82 * the valueattr identifier (PAGE_ID). TODO(stevenjb/jlklien): Investigate | 89 * the valueattr identifier (PAGE_ID). TODO(stevenjb/jlklien): Investigate |
83 * fixing this and using filters once we switch to Polymer 0.8. | 90 * fixing this and using filters once we switch to Polymer 0.8. |
84 * @private | 91 * @private |
85 */ | 92 */ |
86 onIronSelect_: function(event) { | 93 onIronSelect_: function(event) { |
87 if (event.target != this.$.pageContainer || !event.detail.isSelected || | 94 if (event.target != this.$.pageContainer || event.detail.item.subpage) { |
88 event.detail.item.subpage) { | |
89 return; | 95 return; |
90 } | 96 } |
91 this.selectedPageId = event.detail.item.PAGE_ID; | 97 this.selectedPageId = event.detail.item.PAGE_ID; |
92 }, | 98 }, |
93 | 99 |
94 /** | 100 /** |
95 * If no page is selected, selects the first page. This happens on load and | 101 * If no page is selected, selects the first page. This happens on load and |
96 * when a selected page is removed. | 102 * when a selected page is removed. |
97 * @private | 103 * @private |
98 */ | 104 */ |
99 ensureSelection_: function() { | 105 ensureSelection_: function() { |
100 if (!this.pages.length) | 106 if (!this.pages.length) |
101 return; | 107 return; |
102 if (this.selectedPageId == '') | 108 if (this.selectedPageId == '') |
103 this.selectedPageId = this.pages[0].PAGE_ID; | 109 this.selectedPageId = this.pages[0].PAGE_ID; |
104 }, | 110 }, |
105 | 111 |
106 /** | 112 /** |
107 * Updates the list of pages using the pages in iron-pages. | 113 * Updates the list of pages using the pages in iron-pages. |
108 * @private | 114 * @private |
109 */ | 115 */ |
110 pageContainerUpdated_: function() { | 116 pageContainerUpdated_: function() { |
111 this.pages = this.$.pageContainer.items.filter(function(item) { | 117 this._setPages(this.$.pageContainer.items.filter(function(item) { |
112 return !item.subpage; | 118 return !item.subpage; |
113 }); | 119 })); |
114 this.ensureSelection_(); | 120 this.ensureSelection_(); |
115 }, | 121 }, |
116 }); | 122 }); |
OLD | NEW |