Chromium Code Reviews| 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 418dc1d6e90c1b5e8daffb35b8fbd841900eae08..f203d2e48822f8f15e3929910bfa9ba3ed3f7eab 100644 |
| --- a/components/physical_web/webui/resources/physical_web.js |
| +++ b/components/physical_web/webui/resources/physical_web.js |
| @@ -2,6 +2,8 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| +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
|
| + |
| /** |
| * Takes the |nearbyUrlsData| input argument which holds metadata for web pages |
| * broadcast by nearby devices. |
| @@ -9,8 +11,9 @@ |
| * nearby devices |
| */ |
| function renderTemplate(nearbyUrlsData) { |
| + resetTemplate(); |
| // This is the javascript code that processes the template: |
| - jstProcess(new JsEvalContext(nearbyUrlsData), $('physicalWebTemplate')); |
| + jstProcess(new JsEvalContext(nearbyUrlsData), $(Render_ID)); |
| } |
| function requestNearbyURLs() { |
| @@ -28,4 +31,19 @@ function returnNearbyURLs(nearbyUrlsData) { |
| bodyContainer.style.visibility = 'visible'; |
| } |
| +// This is a workaround with jstemplate. Jstemplate render only works on empty |
| +// node. When we need to rerender things, we have to remove the previous nodes. |
| +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
|
| + // Remove existing childNode. |
| + var templateDiv = document.getElementById('render-result'); |
| + while (templateDiv.hasChildNodes()) { |
| + templateDiv.removeChild(templateDiv.lastChild); |
| + } |
| + |
| + var templateFormat = |
| + document.getElementById('render-template').cloneNode(true); |
| + templateFormat.id = Render_ID; |
| + templateDiv.appendChild(templateFormat); |
| +} |
| + |
| document.addEventListener('DOMContentLoaded', requestNearbyURLs); |