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} sidebarDivId ID of the div corresponding to the sidebar. |
| 17 * @param {string} overlayDivId ID of the div corresponding to the overlay. |
| 18 * @extends {PageManager.Observer} |
| 19 */ |
| 20 function Sidebar(sidebarDivId, overlayDivId) { |
| 21 /** @private {!Element} */ |
| 22 this.sidebarDiv_ = $(sidebarDivId); |
| 23 /** @private {!Element} */ |
| 24 this.sidebarList_ = this.sidebarDiv_.querySelector('ul'); |
| 25 |
| 26 this.sidebarDiv_.querySelectorAll('li').forEach(function(item) { |
| 27 item.addEventListener('click', function() { |
| 28 this.close(); |
| 29 PageManager.showPageByName(item.dataset.pageName); |
| 30 }.bind(this)); |
| 31 }.bind(this)); |
| 32 |
| 33 /** @private {!Element} */ |
| 34 this.overlayDiv_ = $(overlayDivId); |
| 35 this.overlayDiv_.addEventListener('click', this.close.bind(this)); |
| 36 } |
| 37 |
| 38 Sidebar.prototype = { |
| 39 __proto__: PageManager.Observer.prototype, |
| 40 |
| 41 /** |
| 42 * Closes the sidebar. Only applies to mobile layouts. |
| 43 */ |
| 44 close: function() { |
| 45 this.sidebarList_.classList.remove('open'); |
| 46 this.overlayDiv_.classList.remove('open'); |
| 47 }, |
| 48 |
| 49 /** |
| 50 * Opens the sidebar. Only applies to mobile layouts. |
| 51 */ |
| 52 open: function() { |
| 53 this.sidebarList_.classList.add('open'); |
| 54 this.overlayDiv_.classList.add('open'); |
| 55 }, |
| 56 |
| 57 /** |
| 58 * Called when a page is navigated to. |
| 59 * @override |
| 60 * @param {string} path The path of the page being visited. |
| 61 */ |
| 62 updateHistory: function(path) { |
| 63 this.sidebarDiv_.querySelectorAll('li').forEach(function(item) { |
| 64 item.classList.toggle('active', item.dataset.pageName === path); |
| 65 }); |
| 66 } |
| 67 }; |
| 68 |
| 69 return { |
| 70 Sidebar: Sidebar |
| 71 }; |
| 72 }); |
OLD | NEW |