Chromium Code Reviews| Index: chrome/browser/resources/uber/uber.js |
| diff --git a/chrome/browser/resources/uber/uber.js b/chrome/browser/resources/uber/uber.js |
| index a55a6efc9ecb76be20dff7bd1daa93051c8ba790..4f4d8ae4ddf92ff7d6e4c7cfa4d8fd927ba49eb1 100644 |
| --- a/chrome/browser/resources/uber/uber.js |
| +++ b/chrome/browser/resources/uber/uber.js |
| @@ -8,20 +8,9 @@ cr.define('uber', function() { |
| * Handles page initialization. |
| */ |
| function onLoad() { |
| - var navigationItems = document.querySelectorAll('#navigation li'); |
| - var iframes = document.querySelectorAll('.iframe-container'); |
| - |
| - for (var i = 0; i < navigationItems.length; ++i) { |
| - var navItem = navigationItems[i]; |
| - navItem.associatedIframe = iframes[i]; |
| - iframes[i].associatedNavItem = navItem; |
| - navItem.addEventListener('click', onNavItemClicked); |
| - } |
| - |
| // Update the URL if need be. |
| if (window.location.pathname === '/') { |
| - var selectedNavItem = document.querySelector('#navigation li.selected'); |
| - var pageId = selectedNavItem.associatedIframe.id; |
| + var pageId = getSelectedIframe().id; |
| window.history.replaceState({pageId: pageId}, '', '/' + pageId); |
| } |
| @@ -29,18 +18,6 @@ cr.define('uber', function() { |
| } |
| /** |
| - * Handles clicks on the navigation controls (switches the page and updates |
| - * the URL). |
| - * @param {Event} e The click event. |
| - */ |
| - function onNavItemClicked(e) { |
| - if (selectPageForNavItem(e.currentTarget)) { |
| - var pageId = e.currentTarget.associatedIframe.id; |
| - window.history.pushState({pageId: pageId}, '', '/' + pageId); |
| - } |
| - } |
| - |
| - /** |
| * Selects the page for |navItem|, or does nothing if that item has already |
| * been selected. |
| * @param {Object} navItem The navigation control li. |
| @@ -51,7 +28,7 @@ cr.define('uber', function() { |
| // Note that |iframe| is the containing element of the underlying iframe, as |
| // opposed to the iframe element itself. |
| var iframe = navItem.associatedIframe; |
| - var currentIframe = getSelectedIframe_(); |
| + var currentIframe = getSelectedIframe(); |
| if (currentIframe == iframe) |
| return false; |
| @@ -59,6 +36,7 @@ cr.define('uber', function() { |
| if (iframe.title) |
| document.title = iframe.title; |
| + console.log('removing'); |
|
Dan Beam
2012/01/20 00:59:02
remove the removing
Evan Stade
2012/01/20 03:27:07
Done.
|
| currentIframe.classList.remove('selected'); |
| iframe.classList.add('selected'); |
| @@ -75,14 +53,14 @@ cr.define('uber', function() { |
| */ |
| function onPopHistoryState(e) { |
| if (e.state && e.state.pageId) |
| - selectPageForNavItem($(e.state.pageId).associatedNavItem); |
| + showPage(e.state.pageId); |
| } |
| /** |
| * @return {Object} The currently selected iframe container. |
| * @private |
|
csilv
2012/01/20 03:30:11
The naming change implies that this is no longer p
Evan Stade
2012/01/20 03:36:07
good catch, i should remove @private
|
| */ |
| - function getSelectedIframe_() { |
| + function getSelectedIframe() { |
| return document.querySelector('.iframe-container.selected'); |
| } |
| @@ -102,12 +80,16 @@ cr.define('uber', function() { |
| * @param {Event} e The posted object. |
| */ |
| function handleWindowMessage(e) { |
| - if (e.data.method === 'showOverlay') |
| - showOverlay_(); |
| - else if (e.data.method === 'hideOverlay') |
| - hideOverlay_(); |
| + if (e.data.method === 'beginInterceptingEvents') |
| + backgroundNavigation(); |
| + else if (e.data.method === 'stopInterceptingEvents') |
| + foregroundNavigation(); |
| else if (e.data.method === 'setTitle') |
| setTitle_(e.origin, e.data.params); |
| + else if (e.data.method === 'showPage') |
| + showPage(e.data.params.pageId); |
| + else if (e.data.method === 'navigationControlsLoaded') |
| + onNavigationControlsLoaded(); |
| else |
| console.error('Received unexpected message: ' + e.data); |
| } |
| @@ -115,15 +97,15 @@ cr.define('uber', function() { |
| /** |
| * @private |
| */ |
| - function showOverlay_() { |
| - document.querySelector('.overlay').classList.add('showing'); |
| + function backgroundNavigation() { |
|
csilv
2012/01/20 03:30:11
Why remove the underscores on these two methods?
Evan Stade
2012/01/20 03:36:07
because they are not methods, they are functions
|
| + $('navigation').classList.add('background'); |
| } |
| /** |
| * @private |
| */ |
| - function hideOverlay_() { |
| - document.querySelector('.overlay').classList.remove('showing'); |
| + function foregroundNavigation() { |
| + $('navigation').classList.remove('background'); |
| } |
| /** |
| @@ -144,10 +126,43 @@ cr.define('uber', function() { |
| container.title = params.title; |
| // Only update the currently displayed title if this is the visible frame. |
| - if (container == getSelectedIframe_()) |
| + if (container == getSelectedIframe()) |
| document.title = params.title; |
| } |
| + /** |
| + * Selects a subpage. This is called from uber-frame. |
| + * @param {String} pageId Should matche an id of one of the iframe containers. |
| + */ |
| + function showPage(pageId) { |
| + var container = $(pageId); |
| + var lastSelected = document.querySelector('.iframe-container.selected'); |
| + if (lastSelected === container) |
| + return; |
| + |
| + console.log('removing'); |
|
Dan Beam
2012/01/20 00:59:02
here too
|
| + lastSelected.classList.remove('selected'); |
| + container.classList.add('selected'); |
| + document.title = container.title; |
| + |
| + window.history.pushState({pageId: pageId}, '', '/' + pageId); |
| + updateNavigationControls(); |
| + } |
| + |
| + function onNavigationControlsLoaded() { |
| + updateNavigationControls(); |
| + } |
| + |
| + /** |
| + * Sends a message to uber-frame to update the appearance of the nav controls. |
| + * It should be called whenever the selected iframe changes. |
| + */ |
| + function updateNavigationControls() { |
| + var iframe = getSelectedIframe(); |
| + uber.invokeMethodOnWindow($('navigation').firstChild.contentWindow, |
| + 'changeSelection', {pageId: iframe.id}); |
| + } |
| + |
| return { |
| onLoad: onLoad, |
| onPopHistoryState: onPopHistoryState |