| 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); |
| 27 |
| 28 let bodyContainer = $('body-container'); |
| 29 bodyContainer.hidden = false; |
| 14 } | 30 } |
| 15 | 31 |
| 16 function requestNearbyURLs() { | 32 function physicalWebPageLoaded() { |
| 17 chrome.send('requestNearbyURLs'); | 33 chrome.send('physicalWebPageLoaded'); |
| 18 } | 34 } |
| 19 | 35 |
| 20 function physicalWebItemClicked(index) { | 36 function physicalWebItemClicked(index) { |
| 21 chrome.send('physicalWebItemClicked', [index]); | 37 chrome.send('physicalWebItemClicked', [index]); |
| 22 } | 38 } |
| 23 | 39 |
| 24 function returnNearbyURLs(nearbyUrlsData) { | 40 function pushNearbyURLs(nearbyUrlsData) { |
| 25 var bodyContainer = $('body-container'); | |
| 26 renderTemplate(nearbyUrlsData); | 41 renderTemplate(nearbyUrlsData); |
| 27 bodyContainer.hidden = false; | |
| 28 | |
| 29 if (nearbyUrlsData['metadata'].length == 0) { | |
| 30 var emptyMessage = $('empty-list-container'); | |
| 31 emptyMessage.hidden = false; | |
| 32 } | |
| 33 } | 42 } |
| 34 | 43 |
| 35 document.addEventListener('DOMContentLoaded', requestNearbyURLs); | 44 document.addEventListener('DOMContentLoaded', physicalWebPageLoaded); |
| OLD | NEW |