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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/physical_web/webui/resources/physical_web.html ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/physical_web/webui/resources/physical_web.js
diff --git a/components/physical_web/webui/resources/physical_web.js b/components/physical_web/webui/resources/physical_web.js
index 70d856fe7db71a2222280e9cda9630a922507d4b..7ed9e577eede6245ea284613ec297ff669ff0900 100644
--- a/components/physical_web/webui/resources/physical_web.js
+++ b/components/physical_web/webui/resources/physical_web.js
@@ -9,12 +9,25 @@
* nearby devices
*/
function renderTemplate(nearbyUrlsData) {
+ if (nearbyUrlsData['metadata'].length != 0) {
+ $('empty-list-container').hidden = true;
+ }
+ // This is a workaround with jstemplate. Jstemplate render only works on empty
+ // node. When we need to rerender things, we have to remove previous nodes.
+ let renderContainer = document.getElementById('render-container');
+ // Remove existing childNode.
+ while (renderContainer.hasChildNodes()) {
+ renderContainer.removeChild(renderContainer.lastChild);
+ }
+ let templateDiv = document.getElementById('render-template').cloneNode(true);
+ renderContainer.appendChild(templateDiv);
+
// This is the javascript code that processes the template:
- jstProcess(new JsEvalContext(nearbyUrlsData), $('physicalWebTemplate'));
+ jstProcess(new JsEvalContext(nearbyUrlsData), templateDiv);
}
-function requestNearbyURLs() {
- chrome.send('requestNearbyURLs');
+function physicalWebPageLoaded() {
+ chrome.send('physicalWebPageLoaded');
}
function physicalWebItemClicked(index) {
@@ -22,14 +35,9 @@ function physicalWebItemClicked(index) {
}
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.
- var bodyContainer = $('body-container');
+ let bodyContainer = $('body-container');
renderTemplate(nearbyUrlsData);
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.
-
- if (nearbyUrlsData['metadata'].length == 0) {
- var emptyMessage = $('empty-list-container');
- emptyMessage.hidden = false;
- }
}
-document.addEventListener('DOMContentLoaded', requestNearbyURLs);
+document.addEventListener('DOMContentLoaded', physicalWebPageLoaded);
« 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