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

Unified Diff: chrome/browser/resources/settings/settings_main/settings_main.js

Issue 981203007: Scaffold for MD-Settings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: license Created 5 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/settings/settings_main/settings_main.js
diff --git a/chrome/browser/resources/settings/settings_main/settings_main.js b/chrome/browser/resources/settings/settings_main/settings_main.js
new file mode 100644
index 0000000000000000000000000000000000000000..582cfb479449cc78c056e188355e2cedabf33dba
--- /dev/null
+++ b/chrome/browser/resources/settings/settings_main/settings_main.js
@@ -0,0 +1,87 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+/**
+ * @fileoverview
+ * 'cr-settings-main' displays the selected settings page.
+ *
+ * Example:
+ *
+ * <cr-settings-main pages="{{pages}}" selectedPageId="{{selectedId}}">
+ * </cr-settings-main>
+ *
+ * See cr-settings-drawer for example of use in 'core-drawer-panel'.
+ *
+ * @group Chrome Settings Elements
+ * @element cr-settings-main
+ */
+Polymer('cr-settings-main', {
+ publish: {
+ /**
+ * Preferences state.
+ *
+ * @attribute prefs
+ * @type CrSettingsPrefsElement
+ * @default null
+ */
+ prefs: null,
+
+ /**
+ * Pages that may be shown.
+ *
+ * @attribute pages
+ * @type Array<!Object>
+ * @default null
+ */
+ pages: null,
+
+ /**
+ * ID of the currently selected page.
+ *
+ * @attribute selectedPageId
+ * @type string
+ * default ''
+ */
+ selectedPageId: '',
+ },
+
+ /** @override */
+ created: function() {
+ this.pages = [];
+ },
+
+ /** @override */
+ ready: function() {
+ var observer = new MutationObserver(this.pageContainerUpdated_.bind(this));
+ observer.observe(this.$.pageContainer,
+ /** @type {MutationObserverInit} */ {
+ childList: true,
+ });
+ this.pages = this.$.pageContainer.items;
+ this.ensureSelection_();
+ },
+
+ /**
+ * If no page is selected, selects the first page. This happens on load and
+ * when a selected page is removed.
+ *
+ * @private
+ */
+ ensureSelection_: function() {
+ if (!this.pages.length)
+ return;
+ if (this.selectedPageId == '')
+ this.selectedPageId = this.pages[0].PAGE_ID;
+ },
+
+ /**
+ * Updates the list of pages using the pages in core-animated-pages.
+ *
+ * @private
+ */
+ pageContainerUpdated_: function() {
+ this.pages = this.$.pageContainer.items;
+ this.ensureSelection_();
+ },
+});

Powered by Google App Engine
This is Rietveld 408576698