Chromium Code Reviews| OLD | NEW |
|---|---|
| 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); |
| OLD | NEW |