Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7655)

Unified Diff: chrome/browser/resources/uber/uber_frame.js

Issue 9265020: [uber] make the navigation controls an iframe (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/uber/uber_frame.js
diff --git a/chrome/browser/resources/uber/uber_frame.js b/chrome/browser/resources/uber/uber_frame.js
new file mode 100644
index 0000000000000000000000000000000000000000..05abf0e6653a3c25e2f32c363ad801e6d2f4d3c7
--- /dev/null
+++ b/chrome/browser/resources/uber/uber_frame.js
@@ -0,0 +1,87 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// This file contains the navigation controls that are visible on the left side
+// of the uber page. It exists separately from uber.js so that it may be loaded
+// in an iframe. Iframes can be layered on top of each other, but not mixed in
+// with page content, so all overlapping content on uber must be framed.
+
+<include src="uber_utils.js"></include>
+
+cr.define('uber_frame', function() {
+
+ /**
+ * Handles page initialization.
+ */
+ function onLoad() {
+ var navigationItems = document.querySelectorAll('li');
+
+ for (var i = 0; i < navigationItems.length; ++i) {
+ navigationItems[i].addEventListener('click', onNavItemClicked);
+ }
Dan Beam 2012/01/20 00:59:02 guess curlies are OK
+
+ 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
+ uber.invokeMethodOnParent('navigationControlsLoaded');
+ }
+
+ /**
+ * Handles clicks on the navigation controls (switches the page and updates
+ * the URL).
+ * @param {Event} e The click event.
+ */
+ function onNavItemClicked(e) {
+ uber.invokeMethodOnParent('showPage',
+ {pageId: e.currentTarget.getAttribute('controls')});
+
+ setSelection(e.currentTarget);
+ }
+
+ /**
+ * Handles postMessage from chrome://chrome.
+ * @param {Event} e The post data.
+ */
+ function handleWindowMessage(e) {
+ if (e.data.method === 'changeSelection')
+ changeSelection(e.data.params);
+ else
+ console.error('Received unexpected message: ' + e.data);
+ }
+
+ /**
+ * Changes the selected nav control.
+ * @param {Object} params Must contain pageId.
+ */
+ function changeSelection(params) {
+ var navItem =
+ document.querySelector('li[controls="' + params.pageId + '"]');
Dan Beam 2012/01/20 00:59:02 this yells "injectable" but guess there's nothing
+ setSelection(navItem);
+ }
+
+ /**
+ * Sets selection on the given nav item.
+ * @param {Boolean} newSelection The item to be selected.
+ */
+ function setSelection(newSelection) {
+ var lastSelectedNavItem = document.querySelector('li.selected');
+ if (lastSelectedNavItem !== newSelection) {
+ newSelection.classList.add('selected');
+ lastSelectedNavItem.classList.remove('selected');
+ }
+ }
+
+ /**
+ * @return {Object} The currently selected iframe container.
+ * @private
+ */
+ function getSelectedIframe() {
+ return document.querySelector('.iframe-container.selected');
+ }
+
+ return {
+ onLoad: onLoad,
+ };
+
+});
+
+document.addEventListener('DOMContentLoaded', uber_frame.onLoad);

Powered by Google App Engine
This is Rietveld 408576698