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

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: Rearrange HTML layout, change code structure 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', function() { this.close(); }.bind(this));
27 }, this);
ortuno 2016/12/05 05:45:28 q: Why do you need the this here?
mbrunson 2016/12/06 00:25:46 The this object in the forEach is the Window objec
ortuno 2016/12/06 10:16:04 Ah got it. Thanks for the explanation.
28
29 /** @private {!Element} */
30 this.overlayDiv_ = this.sidebarDiv_.querySelector('.overlay');
31 this.overlayDiv_.addEventListener('click', this.close.bind(this));
ortuno 2016/12/05 05:45:28 Oh cool. Could we do the same on line 26?
mbrunson 2016/12/06 00:25:46 Done.
32 }
33
34 Sidebar.prototype = {
35 __proto__: PageManager.Observer.prototype,
36
37 /**
38 * Closes the sidebar. Only applies to layouts with window width <= 600px.
39 */
40 close: function() {
41 this.sidebarContent_.classList.remove('open');
ortuno 2016/12/05 05:45:28 You can just set the class in aside by changing so
mbrunson 2016/12/06 00:25:46 Done.
42 this.overlayDiv_.classList.remove('open');
43 },
44
45 /**
46 * Opens the sidebar. Only applies to layouts with window width <= 600px.
47 */
48 open: function() {
ortuno 2016/12/05 05:45:28 Could you set overflow: hidden; in body when the b
mbrunson 2016/12/06 00:25:46 Done.
49 this.sidebarContent_.classList.add('open');
50 this.overlayDiv_.classList.add('open');
51 },
52
ortuno 2016/12/05 05:45:28 One of the reasons I thought using a listener in j
mbrunson 2016/12/06 00:25:46 Oh. I see. In that case, the listener would be goo
53 /**
54 * Called when a page is navigated to.
55 * @override
56 * @param {string} path The path of the page being visited.
57 */
58 updateHistory: function(path) {
59 this.sidebarContent_.querySelectorAll('li').forEach(function(item) {
60 item.classList.toggle('selected', item.dataset.pageName === path);
61 });
62 }
63 };
64
65 return {
66 Sidebar: Sidebar
67 };
68 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698