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

Side by Side Diff: chrome/browser/resources/bluetooth_internals/sidebar.js

Issue 2538653002: bluetooth: Add sidebar and page manager for chrome://bluetooth-internals. (Closed)
Patch Set: Fix styles, change sidebar class assignment, move page header 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 /**
6 * Javascript for Sidebar, served from chrome://bluetooth-internals/.
7 */
8
9 cr.define('sidebar', function() {
10 /** @const {!cr.ui.pageManager.PageManager}*/
11 var PageManager = cr.ui.pageManager.PageManager;
12
13 /**
14 * A side menu that lists the currently navigable pages.
15 * @constructor
16 * @param {string} sidebarDivId ID of the div corresponding to the sidebar.
17 * @extends {PageManager.Observer}
18 */
19 function Sidebar(sidebarDivId) {
20 /** @private {!Element} */
21 this.sidebarDiv_ = $(sidebarDivId);
22 /** @private {!Element} */
23 this.sidebarContent_ = this.sidebarDiv_.querySelector('.sidebar-content');
24
25 this.sidebarContent_.querySelectorAll('li').forEach(function(item) {
26 item.addEventListener('click', this.close.bind(this));
27 }, this);
28
29 /** @private {!Element} */
30 this.overlayDiv_ = this.sidebarDiv_.querySelector('.overlay');
31 this.overlayDiv_.addEventListener('click', this.close.bind(this));
32
33 window.matchMedia('screen and (max-width: 600px)').addListener(
34 function(query) { if (!query.matches) this.close(); }.bind(this));
35 }
36
37 Sidebar.prototype = {
38 __proto__: PageManager.Observer.prototype,
39
40 /**
41 * Closes the sidebar. Only applies to layouts with window width <= 600px.
42 */
43 close: function() {
44 this.sidebarDiv_.classList.remove('open');
45 document.body.style.overflow = '';
46 },
47
48 /**
49 * Opens the sidebar. Only applies to layouts with window width <= 600px.
50 */
51 open: function() {
52 document.body.style.overflow = 'hidden';
53 this.sidebarDiv_.classList.add('open');
54 },
55
56 /**
57 * Called when a page is navigated to.
58 * @override
59 * @param {string} path The path of the page being visited.
60 */
61 updateHistory: function(path) {
62 this.sidebarContent_.querySelectorAll('li').forEach(function(item) {
63 item.classList.toggle('selected', item.dataset.pageName === path);
64 });
65 }
66 };
67
68 return {
69 Sidebar: Sidebar
70 };
71 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698