OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // This file contains the navigation controls that are visible on the left side | 5 // This file contains the navigation controls that are visible on the left side |
6 // of the uber page. It exists separately from uber.js so that it may be loaded | 6 // of the uber page. It exists separately from uber.js so that it may be loaded |
7 // in an iframe. Iframes can be layered on top of each other, but not mixed in | 7 // in an iframe. Iframes can be layered on top of each other, but not mixed in |
8 // with page content, so all overlapping content on uber must be framed. | 8 // with page content, so all overlapping content on uber must be framed. |
9 | 9 |
10 <include src="../../../../ui/webui/resources/js/util.js"></include> | 10 <include src="../../../../ui/webui/resources/js/util.js"></include> |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
70 } | 70 } |
71 | 71 |
72 /** | 72 /** |
73 * Changes the selected nav control. | 73 * Changes the selected nav control. |
74 * @param {Object} params Must contain pageId. | 74 * @param {Object} params Must contain pageId. |
75 */ | 75 */ |
76 function changeSelection(params) { | 76 function changeSelection(params) { |
77 var navItem = | 77 var navItem = |
78 document.querySelector('li[controls="' + params.pageId + '"]'); | 78 document.querySelector('li[controls="' + params.pageId + '"]'); |
79 setSelection(navItem); | 79 setSelection(navItem); |
80 showNavItems(); | |
81 } | |
82 | |
83 /** | |
84 * @return {Object} The currently selected nav item, if any. | |
Dan Beam
2014/06/09 21:22:24
{Element}
michaelpg
2014/06/09 22:47:21
Done.
| |
85 */ | |
86 function getSelectedNavItem() { | |
87 return document.querySelector('li.selected'); | |
80 } | 88 } |
81 | 89 |
82 /** | 90 /** |
83 * Sets selection on the given nav item. | 91 * Sets selection on the given nav item. |
84 * @param {boolean} newSelection The item to be selected. | 92 * @param {Object} newSelection The item to be selected. |
85 */ | 93 */ |
86 function setSelection(newSelection) { | 94 function setSelection(newSelection) { |
87 var lastSelectedNavItem = document.querySelector('li.selected'); | 95 var lastSelectedNavItem = getSelectedNavItem(); |
88 if (lastSelectedNavItem !== newSelection) { | 96 if (lastSelectedNavItem !== newSelection) { |
89 newSelection.classList.add('selected'); | 97 newSelection.classList.add('selected'); |
90 if (lastSelectedNavItem) | 98 if (lastSelectedNavItem) |
91 lastSelectedNavItem.classList.remove('selected'); | 99 lastSelectedNavItem.classList.remove('selected'); |
92 } | 100 } |
93 } | 101 } |
94 | 102 |
95 /** | 103 /** |
104 * Shows nav items belonging to the same group as the selected item. | |
105 */ | |
106 function showNavItems() { | |
107 var navItems = document.querySelectorAll('li'); | |
108 var selectedNavItem = getSelectedNavItem(); | |
109 assert(selectedNavItem); | |
110 | |
111 var selectedGroup = selectedNavItem.getAttribute('group'); | |
112 for (var i = 0; i < navItems.length; ++i) | |
Dan Beam
2014/06/09 21:22:24
nit: curlies
michaelpg
2014/06/09 22:47:21
Done.
| |
113 navItems[i].hidden = navItems[i].getAttribute('group') != selectedGroup; | |
114 } | |
115 | |
116 /** | |
96 * Adjusts this frame's content to scrolls from the outer frame. This is done | 117 * Adjusts this frame's content to scrolls from the outer frame. This is done |
97 * to obscure text in RTL as a user scrolls over the content of this frame (as | 118 * to obscure text in RTL as a user scrolls over the content of this frame (as |
98 * currently RTL scrollbars still draw on the right). | 119 * currently RTL scrollbars still draw on the right). |
99 * @param {number} scroll document.body.scrollLeft of the content frame. | 120 * @param {number} scroll document.body.scrollLeft of the content frame. |
100 */ | 121 */ |
101 function adjustToScroll(scrollLeft) { | 122 function adjustToScroll(scrollLeft) { |
102 assert(isRTL()); | 123 assert(isRTL()); |
103 document.body.style.webkitTransform = 'translateX(' + -scrollLeft + 'px)'; | 124 document.body.style.webkitTransform = 'translateX(' + -scrollLeft + 'px)'; |
104 } | 125 } |
105 | 126 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 } | 167 } |
147 | 168 |
148 return { | 169 return { |
149 onLoad: onLoad, | 170 onLoad: onLoad, |
150 setNavigationOverride: setNavigationOverride, | 171 setNavigationOverride: setNavigationOverride, |
151 }; | 172 }; |
152 | 173 |
153 }); | 174 }); |
154 | 175 |
155 document.addEventListener('DOMContentLoaded', uber_frame.onLoad); | 176 document.addEventListener('DOMContentLoaded', uber_frame.onLoad); |
OLD | NEW |