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

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 js dedup and rebase 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
« no previous file with comments | « components/physical_web/webui/resources/physical_web.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 if (nearbyUrlsData['metadata'].length != 0) {
13 $('empty-list-container').hidden = true;
14 }
15 // This is a workaround with jstemplate. Jstemplate render only works on empty
16 // node. When we need to rerender things, we have to remove previous nodes.
17 let renderContainer = document.getElementById('render-container');
18 // Remove existing childNode.
19 while (renderContainer.hasChildNodes()) {
20 renderContainer.removeChild(renderContainer.lastChild);
21 }
22 let templateDiv = document.getElementById('render-template').cloneNode(true);
23 renderContainer.appendChild(templateDiv);
24
12 // This is the javascript code that processes the template: 25 // This is the javascript code that processes the template:
13 jstProcess(new JsEvalContext(nearbyUrlsData), $('physicalWebTemplate')); 26 jstProcess(new JsEvalContext(nearbyUrlsData), templateDiv);
14 } 27 }
15 28
16 function requestNearbyURLs() { 29 function physicalWebPageLoaded() {
17 chrome.send('requestNearbyURLs'); 30 chrome.send('physicalWebPageLoaded');
18 } 31 }
19 32
20 function physicalWebItemClicked(index) { 33 function physicalWebItemClicked(index) {
21 chrome.send('physicalWebItemClicked', [index]); 34 chrome.send('physicalWebItemClicked', [index]);
22 } 35 }
23 36
24 function returnNearbyURLs(nearbyUrlsData) { 37 function returnNearbyURLs(nearbyUrlsData) {
mmocny 2017/03/24 17:19:11 Nit: Also rename this function if you rename the C
Ran 2017/03/24 18:45:20 Done.
25 var bodyContainer = $('body-container'); 38 let bodyContainer = $('body-container');
26 renderTemplate(nearbyUrlsData); 39 renderTemplate(nearbyUrlsData);
27 bodyContainer.hidden = false; 40 bodyContainer.hidden = false;
mmocny 2017/03/24 17:19:11 Nit: I think you should also move this .hidden=fal
Ran 2017/03/24 18:45:20 Done.
28
29 if (nearbyUrlsData['metadata'].length == 0) {
30 var emptyMessage = $('empty-list-container');
31 emptyMessage.hidden = false;
32 }
33 } 41 }
34 42
35 document.addEventListener('DOMContentLoaded', requestNearbyURLs); 43 document.addEventListener('DOMContentLoaded', physicalWebPageLoaded);
OLDNEW
« no previous file with comments | « components/physical_web/webui/resources/physical_web.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698