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 cr.define('uber', function() { | 5 cr.define('uber', function() { |
6 | 6 |
7 /** | 7 /** |
8 * Options for how web history should be handled. | 8 * Options for how web history should be handled. |
9 **/ | 9 **/ |
10 var HISTORY_STATE_OPTION = { | 10 var HISTORY_STATE_OPTION = { |
11 PUSH: 1, // Push a new history state. | 11 PUSH: 1, // Push a new history state. |
12 REPLACE: 2 // Replace the current history state. | 12 REPLACE: 2 // Replace the current history state. |
13 }; | 13 }; |
14 | 14 |
15 /** | 15 /** |
16 * We cache a reference to the #navigation frame here to so we don't need to | 16 * We cache a reference to the #navigation frame here to so we don't need to |
17 * grab it from the DOM on each scroll. | 17 * grab it from the DOM on each scroll. |
18 * @type {Node} | 18 * @type {Node} |
19 * @private | 19 * @private |
20 * @static | 20 * @static |
21 */ | 21 */ |
22 var navFrame; | 22 var navFrame; |
23 | 23 |
24 /** | 24 /** |
25 * Handles page initialization. | 25 * Handles page initialization. |
26 */ | 26 */ |
27 function onLoad(e) { | 27 function onLoad(e) { |
28 // If the pathname points to a sub-page, we may need to alter the location | |
29 // of one of the frames. | |
30 var params = resolvePageInfoFromPath(window.location.pathname); | |
31 if (params.path) { | |
32 var iframe = $(params.id).querySelector('iframe'); | |
33 iframe.contentWindow.location.replace(iframe.src + params.path); | |
34 } | |
35 | |
36 navFrame = $('navigation'); | 28 navFrame = $('navigation'); |
37 | 29 |
38 // Select a page based on the page-URL. | 30 // Select a page based on the page-URL. |
39 showPage(params.id, HISTORY_STATE_OPTION.REPLACE); | 31 var params = resolvePageInfoFromPath(window.location.pathname); |
| 32 showPage(params.id, HISTORY_STATE_OPTION.REPLACE, params.path); |
40 | 33 |
41 window.addEventListener('message', handleWindowMessage); | 34 window.addEventListener('message', handleWindowMessage); |
42 window.setTimeout(function() { | 35 window.setTimeout(function() { |
43 document.documentElement.classList.remove('loading'); | 36 document.documentElement.classList.remove('loading'); |
44 }, 0); | 37 }, 0); |
45 } | 38 } |
46 | 39 |
47 /** | 40 /** |
48 * Find page information from the given path. If the path doesn't point to one | 41 * Find page information from the given path. If the path doesn't point to one |
49 * of our pages, return default parameters. | 42 * of our pages, return default parameters. |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 // Only update the currently displayed title if this is the visible frame. | 176 // Only update the currently displayed title if this is the visible frame. |
184 if (container == getSelectedIframe()) | 177 if (container == getSelectedIframe()) |
185 document.title = title; | 178 document.title = title; |
186 } | 179 } |
187 | 180 |
188 /** | 181 /** |
189 * Selects a subpage. This is called from uber-frame. | 182 * Selects a subpage. This is called from uber-frame. |
190 * @param {String} pageId Should matche an id of one of the iframe containers. | 183 * @param {String} pageId Should matche an id of one of the iframe containers. |
191 * @param {integer} historyOption Indicates whether we should push or replace | 184 * @param {integer} historyOption Indicates whether we should push or replace |
192 * browser history. | 185 * browser history. |
| 186 * @param {String=} path An optional sub-page path. |
193 */ | 187 */ |
194 function showPage(pageId, historyOption) { | 188 function showPage(pageId, historyOption, path) { |
195 var container = $(pageId); | 189 var container = $(pageId); |
196 var lastSelected = document.querySelector('.iframe-container.selected'); | 190 var lastSelected = document.querySelector('.iframe-container.selected'); |
197 if (lastSelected === container) | 191 if (lastSelected === container) |
198 return; | 192 return; |
199 | 193 |
200 // Lazy load of iframe contents. | 194 // Lazy load of iframe contents. |
201 var frame = container.querySelector('iframe'); | 195 var frame = container.querySelector('iframe'); |
| 196 var sourceURL = frame.dataset.url; |
202 if (!frame.getAttribute('src')) | 197 if (!frame.getAttribute('src')) |
203 frame.setAttribute('src', frame.dataset.url); | 198 frame.src = sourceURL; |
| 199 // If there is a non-empty path, alter the location of the frame. |
| 200 if (path && path.length) |
| 201 frame.contentWindow.location.replace(sourceURL + path); |
204 | 202 |
205 if (lastSelected) | 203 if (lastSelected) |
206 lastSelected.classList.remove('selected'); | 204 lastSelected.classList.remove('selected'); |
207 container.classList.add('selected'); | 205 container.classList.add('selected'); |
208 document.title = container.title; | 206 document.title = container.title; |
209 $('favicon').href = container.dataset.favicon; | 207 $('favicon').href = container.dataset.favicon; |
210 | 208 |
211 enableScrollEasing(); | 209 enableScrollEasing(); |
212 adjustToScroll(0); | 210 adjustToScroll(0); |
213 | 211 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 | 250 |
253 return { | 251 return { |
254 onLoad: onLoad, | 252 onLoad: onLoad, |
255 onPopHistoryState: onPopHistoryState | 253 onPopHistoryState: onPopHistoryState |
256 }; | 254 }; |
257 | 255 |
258 }); | 256 }); |
259 | 257 |
260 window.addEventListener('popstate', uber.onPopHistoryState); | 258 window.addEventListener('popstate', uber.onPopHistoryState); |
261 document.addEventListener('DOMContentLoaded', uber.onLoad); | 259 document.addEventListener('DOMContentLoaded', uber.onLoad); |
OLD | NEW |