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

Unified Diff: chrome/browser/resources/bluetooth_internals/sidebar.js

Issue 2538653002: bluetooth: Add sidebar and page manager for chrome://bluetooth-internals. (Closed)
Patch Set: Fix header width Created 4 years 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/bluetooth_internals/sidebar.js
diff --git a/chrome/browser/resources/bluetooth_internals/sidebar.js b/chrome/browser/resources/bluetooth_internals/sidebar.js
new file mode 100644
index 0000000000000000000000000000000000000000..3b7abbbc246d9f2984146d59672309cc6991dc19
--- /dev/null
+++ b/chrome/browser/resources/bluetooth_internals/sidebar.js
@@ -0,0 +1,72 @@
+// Copyright 2016 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.
+
+/**
+ * Javascript for Sidebar, served from chrome://bluetooth-internals/.
+ */
+
+cr.define('sidebar', function() {
+ /** @const {!cr.ui.pageManager.PageManager}*/
+ var PageManager = cr.ui.pageManager.PageManager;
+
+ /**
+ * A side menu that lists the currently navigable pages.
+ * @constructor
+ * @param {string} sidebarDivId ID of the div corresponding to the sidebar.
+ * @param {string} overlayDivId ID of the div corresponding to the overlay.
+ * @extends {PageManager.Observer}
+ */
+ function Sidebar(sidebarDivId, overlayDivId) {
+ /** @private {!Element} */
+ this.sidebarDiv_ = $(sidebarDivId);
+ /** @private {!Element} */
+ this.sidebarList_ = this.sidebarDiv_.querySelector('ul');
+
+ this.sidebarDiv_.querySelectorAll('li').forEach(function(item) {
+ item.addEventListener('click', function() {
+ this.close();
+ PageManager.showPageByName(item.dataset.pageName);
+ }.bind(this));
+ }.bind(this));
+
+ /** @private {!Element} */
+ this.overlayDiv_ = $(overlayDivId);
+ this.overlayDiv_.addEventListener('click', this.close.bind(this));
+ }
+
+ Sidebar.prototype = {
+ __proto__: PageManager.Observer.prototype,
+
+ /**
+ * Closes the sidebar. Only applies to mobile layouts.
ortuno 2016/12/01 06:27:03 Can you be more specific? What do you mean when yo
mbrunson 2016/12/02 02:31:45 Done.
+ */
+ close: function() {
+ this.sidebarDiv_.classList.remove('open');
+ this.overlayDiv_.classList.remove('open');
+ },
+
+ /**
+ * Opens the sidebar. Only applies to mobile layouts.
+ */
+ open: function() {
+ this.sidebarDiv_.classList.add('open');
+ this.overlayDiv_.classList.add('open');
+ },
+
+ /**
+ * Called when a page is navigated to.
+ * @override
+ * @param {string} path The path of the page being visited.
+ */
+ updateHistory: function(path) {
+ this.sidebarDiv_.querySelectorAll('li').forEach(function(item) {
+ item.classList.toggle('selected', item.dataset.pageName === path);
+ });
+ }
+ };
+
+ return {
+ Sidebar: Sidebar
+ };
+});

Powered by Google App Engine
This is Rietveld 408576698