OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 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 window.addEventListener('load', function init() { | |
6 chrome.send('requestExtensionId'); | |
7 }); | |
8 | |
9 /** @param {string} extensionId */ | |
10 window['setExtensionId'] = function(extensionId) { | |
11 var ev = document.querySelector('extensionview'); | |
Bernhard Bauer
2016/05/19 14:34:07
Don't use abbreviations in variable names.
sheretov
2016/05/19 16:16:45
Done.
| |
12 | |
13 /** | |
14 * @param {string} str | |
15 * @return {!Array<string>} | |
16 */ | |
17 var splitUrlOnHash = function(str) { | |
18 str = str || ''; | |
19 var pos = str.indexOf('#'); | |
20 return (pos !== -1) ? [str.substr(0, pos), str.substr(pos + 1)] : [str, '']; | |
21 }; | |
22 | |
23 new MutationObserver(function() { | |
24 var newHash = splitUrlOnHash(ev.getAttribute('src'))[1]; | |
25 var oldHash = window.location.hash.substr(1); | |
26 if (newHash !== oldHash) { | |
27 window.location.hash = newHash; | |
28 } | |
29 }).observe(ev, { | |
30 attributes: true | |
31 }); | |
32 | |
33 window.addEventListener('hashchange', function() { | |
34 var newHash = window.location.hash.substr(1); | |
35 var evSrcParts = splitUrlOnHash(ev.getAttribute('src')); | |
36 if (newHash !== evSrcParts[1]) { | |
37 ev.load(evSrcParts[0] + '#' + newHash); | |
38 } | |
39 }); | |
40 | |
41 ev.load('chrome-extension://' + extensionId + '/cast_setup/devices.html'); | |
42 }; | |
43 | |
OLD | NEW |