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

Side by Side Diff: components/physical_web/webui/resources/physical_web.js

Issue 2741823002: Update Physical Web WebUI to show new results automatically (Closed)
Patch Set: remove renderID Created 3 years, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2016 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 /** 5 /**
6 * Takes the |nearbyUrlsData| input argument which holds metadata for web pages 6 * Takes the |nearbyUrlsData| input argument which holds metadata for web pages
7 * broadcast by nearby devices. 7 * broadcast by nearby devices.
8 * @param {Object} nearbyUrlsData Information about web pages broadcast by 8 * @param {Object} nearbyUrlsData Information about web pages broadcast by
9 * nearby devices 9 * nearby devices
10 */ 10 */
11 function renderTemplate(nearbyUrlsData) { 11 function renderTemplate(nearbyUrlsData) {
12 // This is a workaround with jstemplate. Jstemplate render only works on empty
13 // node. When we need to rerender things, we have to remove previous nodes.
14 let renderContainer = document.getElementById('render-container');
15 // Remove existing childNode.
16 while (renderContainer.hasChildNodes()) {
17 renderContainer.removeChild(renderContainer.lastChild);
18 }
19
20 let templateDiv = document.getElementById('render-template').cloneNode(true);
21 renderContainer.appendChild(templateDiv);
22
12 // This is the javascript code that processes the template: 23 // This is the javascript code that processes the template:
13 jstProcess(new JsEvalContext(nearbyUrlsData), $('physicalWebTemplate')); 24 jstProcess(new JsEvalContext(nearbyUrlsData), templateDiv);
14 } 25 }
15 26
16 function requestNearbyURLs() { 27 function requestNearbyURLs() {
17 chrome.send('requestNearbyURLs'); 28 chrome.send('requestNearbyURLs');
18 } 29 }
19 30
20 function physicalWebItemClicked(index) { 31 function physicalWebItemClicked(index) {
21 chrome.send('physicalWebItemClicked', [index]); 32 chrome.send('physicalWebItemClicked', [index]);
22 } 33 }
23 34
24 function returnNearbyURLs(nearbyUrlsData) { 35 function returnNearbyURLs(nearbyUrlsData) {
25 var bodyContainer = $('body-container'); 36 let bodyContainer = $('body-container');
26 renderTemplate(nearbyUrlsData); 37 renderTemplate(nearbyUrlsData);
27 38
28 bodyContainer.style.visibility = 'visible'; 39 bodyContainer.style.visibility = 'visible';
29 } 40 }
30 41
31 document.addEventListener('DOMContentLoaded', requestNearbyURLs); 42 document.addEventListener('DOMContentLoaded', requestNearbyURLs);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698