Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 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 | |
| 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. | |
| 9 | |
| 10 <include src="uber_utils.js"></include> | |
| 11 | |
| 12 cr.define('uber_frame', function() { | |
| 13 | |
| 14 /** | |
| 15 * Handles page initialization. | |
| 16 */ | |
| 17 function onLoad() { | |
| 18 var navigationItems = document.querySelectorAll('li'); | |
| 19 | |
| 20 for (var i = 0; i < navigationItems.length; ++i) { | |
| 21 navigationItems[i].addEventListener('click', onNavItemClicked); | |
| 22 } | |
|
Dan Beam
2012/01/20 00:59:02
guess curlies are OK
| |
| 23 | |
| 24 window.addEventListener('message', handleWindowMessage); | |
|
Dan Beam
2012/01/20 00:59:02
Don't we generally expose and addEventListener() o
Evan Stade
2012/01/20 03:27:07
only if the event can happen before load
| |
| 25 uber.invokeMethodOnParent('navigationControlsLoaded'); | |
| 26 } | |
| 27 | |
| 28 /** | |
| 29 * Handles clicks on the navigation controls (switches the page and updates | |
| 30 * the URL). | |
| 31 * @param {Event} e The click event. | |
| 32 */ | |
| 33 function onNavItemClicked(e) { | |
| 34 uber.invokeMethodOnParent('showPage', | |
| 35 {pageId: e.currentTarget.getAttribute('controls')}); | |
| 36 | |
| 37 setSelection(e.currentTarget); | |
| 38 } | |
| 39 | |
| 40 /** | |
| 41 * Handles postMessage from chrome://chrome. | |
| 42 * @param {Event} e The post data. | |
| 43 */ | |
| 44 function handleWindowMessage(e) { | |
| 45 if (e.data.method === 'changeSelection') | |
| 46 changeSelection(e.data.params); | |
| 47 else | |
| 48 console.error('Received unexpected message: ' + e.data); | |
| 49 } | |
| 50 | |
| 51 /** | |
| 52 * Changes the selected nav control. | |
| 53 * @param {Object} params Must contain pageId. | |
| 54 */ | |
| 55 function changeSelection(params) { | |
| 56 var navItem = | |
| 57 document.querySelector('li[controls="' + params.pageId + '"]'); | |
|
Dan Beam
2012/01/20 00:59:02
this yells "injectable" but guess there's nothing
| |
| 58 setSelection(navItem); | |
| 59 } | |
| 60 | |
| 61 /** | |
| 62 * Sets selection on the given nav item. | |
| 63 * @param {Boolean} newSelection The item to be selected. | |
| 64 */ | |
| 65 function setSelection(newSelection) { | |
| 66 var lastSelectedNavItem = document.querySelector('li.selected'); | |
| 67 if (lastSelectedNavItem !== newSelection) { | |
| 68 newSelection.classList.add('selected'); | |
| 69 lastSelectedNavItem.classList.remove('selected'); | |
| 70 } | |
| 71 } | |
| 72 | |
| 73 /** | |
| 74 * @return {Object} The currently selected iframe container. | |
| 75 * @private | |
| 76 */ | |
| 77 function getSelectedIframe() { | |
| 78 return document.querySelector('.iframe-container.selected'); | |
| 79 } | |
| 80 | |
| 81 return { | |
| 82 onLoad: onLoad, | |
| 83 }; | |
| 84 | |
| 85 }); | |
| 86 | |
| 87 document.addEventListener('DOMContentLoaded', uber_frame.onLoad); | |
| OLD | NEW |