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

Side by Side Diff: components/physical_web/webui/resources/physical_web.js

Issue 2717363003: Add Physical Web WebUI Default Url Icon (Closed)
Patch Set: rebase Created 3 years, 8 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
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) { 12 if (nearbyUrlsData['metadata'].length != 0) {
13 $('empty-list-container').hidden = true; 13 $('empty-list-container').hidden = true;
14 } 14 }
15 // This is a workaround with jstemplate. Jstemplate render only works on empty 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. 16 // node. When we need to rerender things, we have to remove previous nodes.
17 let renderContainer = document.getElementById('render-container'); 17 let renderContainer = document.getElementById('render-container');
18 // Remove existing childNode. 18 // Remove existing childNode.
19 while (renderContainer.hasChildNodes()) { 19 while (renderContainer.hasChildNodes()) {
20 renderContainer.removeChild(renderContainer.lastChild); 20 renderContainer.removeChild(renderContainer.lastChild);
21 } 21 }
22 let templateDiv = document.getElementById('render-template').cloneNode(true); 22 let templateDiv = document.getElementById('render-template').cloneNode(true);
23 renderContainer.appendChild(templateDiv); 23 renderContainer.appendChild(templateDiv);
24 24
25 // This is the javascript code that processes the template: 25 // This is the javascript code that processes the template:
26 jstProcess(new JsEvalContext(nearbyUrlsData), templateDiv); 26 jstProcess(new JsEvalContext(nearbyUrlsData), templateDiv);
27 27
28 assignImageLoadErrorHandlers();
29
28 let bodyContainer = $('body-container'); 30 let bodyContainer = $('body-container');
29 bodyContainer.hidden = false; 31 bodyContainer.hidden = false;
30 } 32 }
31 33
32 function physicalWebPageLoaded() { 34 function physicalWebPageLoaded() {
33 chrome.send('physicalWebPageLoaded'); 35 chrome.send('physicalWebPageLoaded');
34 } 36 }
35 37
36 function physicalWebItemClicked(index) { 38 function physicalWebItemClicked(index) {
37 chrome.send('physicalWebItemClicked', [index]); 39 chrome.send('physicalWebItemClicked', [index]);
38 } 40 }
39 41
40 function pushNearbyURLs(nearbyUrlsData) { 42 function pushNearbyURLs(nearbyUrlsData) {
41 renderTemplate(nearbyUrlsData); 43 renderTemplate(nearbyUrlsData);
42 } 44 }
43 45
46 function assignImageLoadErrorHandlers() {
47 var pwIcons = document.querySelectorAll('.physicalWebIcon');
48 pwIcons.forEach(function(e) {
49 let img = e.getElementsByTagName('img')[0];
50 img.addEventListener('error', function() {
51 img.src =
52 'chrome://physical-web/ic_link_grey600_36dp.png';
53 });
54 });
55 }
56
44 document.addEventListener('DOMContentLoaded', physicalWebPageLoaded); 57 document.addEventListener('DOMContentLoaded', physicalWebPageLoaded);
OLDNEW
« no previous file with comments | « components/physical_web/webui/physical_web_ui_constants.cc ('k') | components/resources/physical_web_ui_resources.grdp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698