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

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: 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 var Render_ID = 'RenderId';
mmocny 2017/03/10 17:38:41 Is this the right ID? Also, why set a constant fo
Ran 2017/03/10 18:19:10 This id can be any string. It's only used in this
Ran 2017/03/10 18:19:10 Done.
mmocny 2017/03/10 18:32:36 I understand now, its used to help get a handle to
6
5 /** 7 /**
6 * Takes the |nearbyUrlsData| input argument which holds metadata for web pages 8 * Takes the |nearbyUrlsData| input argument which holds metadata for web pages
7 * broadcast by nearby devices. 9 * broadcast by nearby devices.
8 * @param {Object} nearbyUrlsData Information about web pages broadcast by 10 * @param {Object} nearbyUrlsData Information about web pages broadcast by
9 * nearby devices 11 * nearby devices
10 */ 12 */
11 function renderTemplate(nearbyUrlsData) { 13 function renderTemplate(nearbyUrlsData) {
14 resetTemplate();
12 // This is the javascript code that processes the template: 15 // This is the javascript code that processes the template:
13 jstProcess(new JsEvalContext(nearbyUrlsData), $('physicalWebTemplate')); 16 jstProcess(new JsEvalContext(nearbyUrlsData), $(Render_ID));
14 } 17 }
15 18
16 function requestNearbyURLs() { 19 function requestNearbyURLs() {
17 chrome.send('requestNearbyURLs'); 20 chrome.send('requestNearbyURLs');
18 } 21 }
19 22
20 function physicalWebItemClicked(index) { 23 function physicalWebItemClicked(index) {
21 chrome.send('physicalWebItemClicked', [index]); 24 chrome.send('physicalWebItemClicked', [index]);
22 } 25 }
23 26
24 function returnNearbyURLs(nearbyUrlsData) { 27 function returnNearbyURLs(nearbyUrlsData) {
25 var bodyContainer = $('body-container'); 28 var bodyContainer = $('body-container');
26 renderTemplate(nearbyUrlsData); 29 renderTemplate(nearbyUrlsData);
27 30
28 bodyContainer.style.visibility = 'visible'; 31 bodyContainer.style.visibility = 'visible';
29 } 32 }
30 33
34 // This is a workaround with jstemplate. Jstemplate render only works on empty
35 // node. When we need to rerender things, we have to remove the previous nodes.
36 function resetTemplate() {
mmocny 2017/03/10 17:38:41 Did replaceChild not work?
Ran 2017/03/10 18:19:10 With the new implementation (make a hidden templat
mmocny 2017/03/10 18:32:35 Okay I understand now, this is fine. Possibly we
37 // Remove existing childNode.
38 var templateDiv = document.getElementById('render-result');
39 while (templateDiv.hasChildNodes()) {
40 templateDiv.removeChild(templateDiv.lastChild);
41 }
42
43 var templateFormat =
44 document.getElementById('render-template').cloneNode(true);
45 templateFormat.id = Render_ID;
46 templateDiv.appendChild(templateFormat);
47 }
48
31 document.addEventListener('DOMContentLoaded', requestNearbyURLs); 49 document.addEventListener('DOMContentLoaded', requestNearbyURLs);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698