OLD | NEW |
---|---|
(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} sidebarDiv The div corresponding to the sidebar. | |
dpapad
2016/12/07 19:33:20
This is declared as a string here, and as an Eleme
mbrunson
2016/12/07 21:15:56
Done.
| |
17 * @extends {PageManager.Observer} | |
18 */ | |
19 function Sidebar(sidebarDiv) { | |
20 /** @private {!Element} */ | |
21 this.sidebarDiv_ = sidebarDiv; | |
22 /** @private {!Element} */ | |
23 this.sidebarContent_ = this.sidebarDiv_.querySelector('.sidebar-content'); | |
24 /** @private {!Element} */ | |
25 this.sidebarList_ = this.sidebarContent_.querySelector('ul'); | |
26 | |
27 this.sidebarList_.querySelectorAll('li button').forEach(function(item) { | |
28 item.addEventListener('click', this.onItemClick_.bind(this)); | |
29 }, this); | |
30 | |
31 /** @private {!Element} */ | |
32 this.overlayDiv_ = this.sidebarDiv_.querySelector('.overlay'); | |
33 this.overlayDiv_.addEventListener('click', this.close.bind(this)); | |
34 | |
35 window.matchMedia('screen and (max-width: 600px)').addListener( | |
36 function(query) { if (!query.matches) this.close(); }.bind(this)); | |
37 } | |
38 | |
39 Sidebar.prototype = { | |
40 __proto__: PageManager.Observer.prototype, | |
41 | |
42 /** | |
43 * Closes the sidebar. Only applies to layouts with window width <= 600px. | |
44 */ | |
45 close: function() { | |
46 this.sidebarDiv_.classList.remove('open'); | |
47 document.body.style.overflow = ''; | |
48 }, | |
49 | |
50 /** | |
51 * Opens the sidebar. Only applies to layouts with window width <= 600px. | |
52 */ | |
53 open: function() { | |
54 document.body.style.overflow = 'hidden'; | |
55 this.sidebarDiv_.classList.add('open'); | |
56 }, | |
57 | |
58 /** | |
59 * Called when a page is navigated to. | |
60 * @override | |
61 * @param {string} path The path of the page being visited. | |
62 */ | |
63 updateHistory: function(path) { | |
64 this.sidebarContent_.querySelectorAll('li').forEach(function(item) { | |
65 item.classList.toggle('selected', item.dataset.pageName === path); | |
66 }); | |
67 }, | |
68 | |
69 /** | |
70 * Switches the page based on which sidebar list button was clicked. | |
71 * @private | |
72 * @param {!Event} event | |
dpapad
2016/12/07 19:33:20
Nit: Usually @private is the last annotation.
mbrunson
2016/12/07 21:15:56
Done.
| |
73 */ | |
74 onItemClick_: function(event) { | |
75 this.close(); | |
76 PageManager.showPageByName(event.target.parentNode.dataset.pageName); | |
77 }, | |
78 }; | |
79 | |
80 return { | |
81 Sidebar: Sidebar | |
82 }; | |
83 }); | |
OLD | NEW |