| 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"> | 10 // <include src="../../../../ui/webui/resources/js/util.js"> |
| 11 <include src="uber_utils.js"> | 11 // <include src="uber_utils.js"> |
| 12 | 12 |
| 13 cr.define('uber_frame', function() { | 13 cr.define('uber_frame', function() { |
| 14 | 14 |
| 15 /** | 15 /** |
| 16 * Handles page initialization. | 16 * Handles page initialization. |
| 17 */ | 17 */ |
| 18 function onLoad() { | 18 function onLoad() { |
| 19 var navigationItems = document.querySelectorAll('li'); | 19 var navigationItems = document.querySelectorAll('li'); |
| 20 | 20 |
| 21 for (var i = 0; i < navigationItems.length; ++i) { | 21 for (var i = 0; i < navigationItems.length; ++i) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 38 */ | 38 */ |
| 39 function onNavItemClicked(e) { | 39 function onNavItemClicked(e) { |
| 40 // Though pointer-event: none; is applied to the .selected nav item, users | 40 // Though pointer-event: none; is applied to the .selected nav item, users |
| 41 // can still tab to them and press enter/space which simulates a click. | 41 // can still tab to them and press enter/space which simulates a click. |
| 42 if (e.target.classList.contains('selected')) | 42 if (e.target.classList.contains('selected')) |
| 43 return; | 43 return; |
| 44 | 44 |
| 45 // Extensions can override Uber content (e.g., if the user has a history | 45 // Extensions can override Uber content (e.g., if the user has a history |
| 46 // extension, it should display when the 'History' navigation is clicked). | 46 // extension, it should display when the 'History' navigation is clicked). |
| 47 if (e.currentTarget.getAttribute('override') == 'yes') { | 47 if (e.currentTarget.getAttribute('override') == 'yes') { |
| 48 window.open('chrome://' + e.currentTarget.getAttribute('controls'), | 48 window.open( |
| 49 '_blank'); | 49 'chrome://' + e.currentTarget.getAttribute('controls'), '_blank'); |
| 50 return; | 50 return; |
| 51 } | 51 } |
| 52 | 52 |
| 53 uber.invokeMethodOnParent('showPage', | 53 uber.invokeMethodOnParent( |
| 54 {pageId: e.currentTarget.getAttribute('controls')}); | 54 'showPage', {pageId: e.currentTarget.getAttribute('controls')}); |
| 55 | 55 |
| 56 setSelection(/** @type {Element} */(e.currentTarget)); | 56 setSelection(/** @type {Element} */ (e.currentTarget)); |
| 57 } | 57 } |
| 58 | 58 |
| 59 /** | 59 /** |
| 60 * Handles postMessage from chrome://chrome. | 60 * Handles postMessage from chrome://chrome. |
| 61 * @param {Event} e The post data. | 61 * @param {Event} e The post data. |
| 62 */ | 62 */ |
| 63 function handleWindowMessage(e) { | 63 function handleWindowMessage(e) { |
| 64 if (e.data.method === 'changeSelection') | 64 if (e.data.method === 'changeSelection') |
| 65 changeSelection(e.data.params); | 65 changeSelection(e.data.params); |
| 66 else if (e.data.method === 'adjustToScroll') | 66 else if (e.data.method === 'adjustToScroll') |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 function setContentChanging(enabled) { | 131 function setContentChanging(enabled) { |
| 132 assert(isRTL()); | 132 assert(isRTL()); |
| 133 document.documentElement.classList.toggle('changing-content', enabled); | 133 document.documentElement.classList.toggle('changing-content', enabled); |
| 134 } | 134 } |
| 135 | 135 |
| 136 /** | 136 /** |
| 137 * Handles mouse wheels on the top level element. Forwards them to uber.js. | 137 * Handles mouse wheels on the top level element. Forwards them to uber.js. |
| 138 * @param {Event} e The mouse wheel event. | 138 * @param {Event} e The mouse wheel event. |
| 139 */ | 139 */ |
| 140 function onMouseWheel(e) { | 140 function onMouseWheel(e) { |
| 141 uber.invokeMethodOnParent('mouseWheel', | 141 uber.invokeMethodOnParent( |
| 142 {deltaX: e.wheelDeltaX, deltaY: e.wheelDeltaY}); | 142 'mouseWheel', {deltaX: e.wheelDeltaX, deltaY: e.wheelDeltaY}); |
| 143 } | 143 } |
| 144 | 144 |
| 145 /** | 145 /** |
| 146 * Handles mouse presses on the top level element. Forwards them to uber.js. | 146 * Handles mouse presses on the top level element. Forwards them to uber.js. |
| 147 * @param {Event} e The mouse down event. | 147 * @param {Event} e The mouse down event. |
| 148 */ | 148 */ |
| 149 function onMouseDown(e) { | 149 function onMouseDown(e) { |
| 150 uber.invokeMethodOnParent('mouseDown'); | 150 uber.invokeMethodOnParent('mouseDown'); |
| 151 } | 151 } |
| 152 | 152 |
| 153 /** | 153 /** |
| 154 * @return {Element} The currently selected iframe container. | 154 * @return {Element} The currently selected iframe container. |
| 155 * @private | 155 * @private |
| 156 */ | 156 */ |
| 157 function getSelectedIframe() { | 157 function getSelectedIframe() { |
| 158 return document.querySelector('.iframe-container.selected'); | 158 return document.querySelector('.iframe-container.selected'); |
| 159 } | 159 } |
| 160 | 160 |
| 161 /** | 161 /** |
| 162 * Finds the <li> element whose 'controls' attribute is |controls| and sets | 162 * Finds the <li> element whose 'controls' attribute is |controls| and sets |
| 163 * its 'override' attribute to |override|. | 163 * its 'override' attribute to |override|. |
| 164 * @param {string} controls The value of the 'controls' attribute of the | 164 * @param {string} controls The value of the 'controls' attribute of the |
| 165 * element to change. | 165 * element to change. |
| 166 * @param {string} override The value to set for the 'override' attribute of | 166 * @param {string} override The value to set for the 'override' attribute of |
| 167 * that element (either 'yes' or 'no'). | 167 * that element (either 'yes' or 'no'). |
| 168 */ | 168 */ |
| 169 function setNavigationOverride(controls, override) { | 169 function setNavigationOverride(controls, override) { |
| 170 var navItem = | 170 var navItem = document.querySelector('li[controls="' + controls + '"]'); |
| 171 document.querySelector('li[controls="' + controls + '"]'); | |
| 172 navItem.setAttribute('override', override); | 171 navItem.setAttribute('override', override); |
| 173 } | 172 } |
| 174 | 173 |
| 175 return { | 174 return { |
| 176 onLoad: onLoad, | 175 onLoad: onLoad, |
| 177 setNavigationOverride: setNavigationOverride, | 176 setNavigationOverride: setNavigationOverride, |
| 178 }; | 177 }; |
| 179 | 178 |
| 180 }); | 179 }); |
| 181 | 180 |
| 182 document.addEventListener('DOMContentLoaded', uber_frame.onLoad); | 181 document.addEventListener('DOMContentLoaded', uber_frame.onLoad); |
| OLD | NEW |