| 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 * |
| 11 * <cr-settings-main pages="{{pages}}" selectedPageId="{{selectedId}}"> | 11 * <cr-settings-main pages="{{pages}}" currentPageIndex="{{index}}"> |
| 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 'core-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('cr-settings-main', { |
| 20 publish: { | 20 publish: { |
| 21 /** | 21 /** |
| 22 * Preferences state. | 22 * Preferences state. |
| 23 * | 23 * |
| 24 * @attribute prefs | 24 * @attribute prefs |
| 25 * @type CrSettingsPrefsElement | 25 * @type CrSettingsPrefsElement |
| 26 * @default null | 26 * @default null |
| 27 */ | 27 */ |
| 28 prefs: null, | 28 prefs: null, |
| 29 | 29 |
| 30 /** | 30 /** |
| 31 * Pages that may be shown. | 31 * Pages that may be shown. |
| 32 * | 32 * |
| 33 * @attribute pages | 33 * @attribute pages |
| 34 * @type Array<!Object> | 34 * @type Array<!CrSettingsPage> |
| 35 * @default null | 35 * @default null |
| 36 */ | 36 */ |
| 37 pages: null, | 37 pages: null, |
| 38 | 38 |
| 39 /** | 39 /** |
| 40 * ID of the currently selected page. | 40 * ID of the currently selected page. |
| 41 * | 41 * |
| 42 * @attribute selectedPageId | 42 * @attribute selectedPageId |
| 43 * @type string | 43 * @type string |
| 44 * default '' | 44 * default '' |
| 45 */ | 45 */ |
| 46 selectedPageId: '', | 46 selectedPageId: '', |
| 47 |
| 48 /** |
| 49 /** |
| 50 * Index of the currently selected page. |
| 51 * |
| 52 * @attribute selectedPageIndex |
| 53 * @type number |
| 54 * default 0 |
| 55 */ |
| 56 selectedPageIndex: 0, |
| 47 }, | 57 }, |
| 48 | 58 |
| 49 /** @override */ | 59 /** @override */ |
| 50 created: function() { | 60 created: function() { |
| 51 this.pages = []; | 61 this.pages = []; |
| 52 }, | 62 }, |
| 53 | 63 |
| 54 /** @override */ | 64 /** @override */ |
| 55 ready: function() { | 65 ready: function() { |
| 56 var observer = new MutationObserver(this.pagesUpdated_.bind(this)); | 66 var observer = new MutationObserver(this.pagesUpdated_.bind(this)); |
| 57 observer.observe(this.$.pages, | 67 observer.observe(this.$.pages, |
| 58 /** @type {MutationObserverInit} */ { | 68 /** @type {MutationObserverInit} */ { |
| 59 childList: true, | 69 childList: true, |
| 60 }); | 70 }); |
| 61 this.pages = this.$.pages.items; | 71 this.pages = this.$.pages.items; |
| 62 this.ensureSelection_(); | 72 this.ensureSelection_(); |
| 63 }, | 73 }, |
| 64 | 74 |
| 65 /** | 75 /** |
| 66 * If no page is selected, selects the first page. This happens on load and | 76 * If no page is selected, select the first page. This happens on load and |
| 67 * when a selected page is removed. | 77 * when a selected page is removed. |
| 68 */ | 78 */ |
| 69 ensureSelection_: function() { | 79 ensureSelection_: function() { |
| 70 if (!this.pages.length) | 80 if (!this.pages.length) |
| 71 return; | 81 return; |
| 72 if (this.selectedPageId == '') | 82 if (this.selectedPageId == '') |
| 73 this.selectedPageId = this.pages[0].PAGE_ID; | 83 this.selectedPageId = this.pages[0].PAGE_ID; |
| 74 }, | 84 }, |
| 75 | 85 |
| 76 /** | 86 /** |
| 77 * Updates the list of pages using the pages in core-animated-pages. | 87 * Updates the list of pages found in core-animated-pages. |
| 78 * | 88 * |
| 79 * @private | 89 * @private |
| 80 */ | 90 */ |
| 81 pagesUpdated_: function() { | 91 pagesUpdated_: function() { |
| 82 this.pages = this.$.pages.items; | 92 this.pages = this.$.pages.items; |
| 83 this.ensureSelection_(); | 93 this.ensureSelection_(); |
| 84 }, | 94 }, |
| 95 |
| 96 /** Helper to rall PlatformInfo.isChromeOs from a template expression. */ |
| 97 isChromeOs: function() { |
| 98 return PlatformInfo.isChromeOs(); |
| 99 }, |
| 85 }); | 100 }); |
| OLD | NEW |