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

Side by Side Diff: chrome/browser/resources/snippets_internals.js

Issue 1883523002: chrome://snippets-internals page for debugging NTP snippets. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adding the chrome://snippets-internals page in the auto-suggest list. Created 4 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
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
Marc Treib 2016/04/14 15:43:44 2016
jkrcal 2016/04/14 16:41:01 Done.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 cr.define('chrome.snippets_internals', function() {
Bernhard Bauer 2016/04/14 16:50:24 I would probably call this SnippetsInternals, to m
jkrcal 2016/04/15 14:11:50 Done.
6 'use strict';
7
8 function initialize() {
9 function submitDownload(event) {
10 chrome.send('download', [$('hosts-input').value]);
11 event.preventDefault();
12 }
13
14 $('submit-download').addEventListener('click', submitDownload);
15
16 function submitClear(event) {
17 chrome.send('clear');
18 event.preventDefault();
19 }
20
21 $('submit-clear').addEventListener('click', submitClear);
22
23 function submitClearDiscarded(event) {
24 chrome.send('clearDiscarded');
25 event.preventDefault();
26 }
27
28 $('discarded-snippets-clear').addEventListener('click',
29 submitClearDiscarded);
30
31 chrome.send('loaded');
32 }
33
34 function receiveProperty(propertyId, value) {
35 if ($(propertyId)) $(propertyId).textContent = value;
Bernhard Bauer 2016/04/14 16:50:24 In contrast to C++, the Javascript style guide doe
jkrcal 2016/04/15 14:11:50 Done (removed the check).
36 }
37
38 function receiveHosts(hosts) {
39 displayList(hosts, 'hosts');
40
41 $('hosts-input').value = hosts.list.map(host => host.url).join(' ');
42 }
43
44 function receiveSnippets(snippets) {
45 displayList(snippets, 'snippets', 'snippet-title');
46 }
47
48 function receiveDiscardedSnippets(discardedSnippets) {
49 displayList(discardedSnippets, 'discarded-snippets',
50 'discarded-snippet-title');
51 }
52
53 function trigger(event) {
Bernhard Bauer 2016/04/14 16:50:24 I would move this function closer to where it is u
jkrcal 2016/04/15 14:11:50 I have moved it inside the displayList. I have not
54 // The id of the div to (un)hide is stored to 'myid' attribute of the link.
55 var id = event.currentTarget.getAttribute('myid');
56 if ($(id)) $(id).classList.toggle('snippet-hidden');
Bernhard Bauer 2016/04/14 16:50:24 This would also work nicer with a Polymer object.
jkrcal 2016/04/15 14:11:50 I am not sure about this suggestion. To me the cod
57 event.preventDefault();
58 }
59
60 function displayList(object, domId, titleClass) {
61 jstProcess(new JsEvalContext(object), $(domId));
62
63 var text;
64 var display;
65
66 if (object.list.length > 0) {
67 text = '';
68 display = 'inline';
69 } else {
70 text = 'The list is empty.';
71 display = 'none';
72 }
73
74 if ($(domId + '-empty')) $(domId + '-empty').textContent = text;
75 if ($(domId + '-clear')) $(domId + '-clear').style.display = display;
76
77 var links = document.getElementsByClassName(titleClass);
78 for (var link of links) {
79 link.addEventListener('click', trigger);
80 }
81 }
82
83 // Return an object with all of the exports.
84 return {
85 initialize: initialize,
86 receiveProperty: receiveProperty,
87 receiveHosts: receiveHosts,
88 receiveSnippets: receiveSnippets,
89 receiveDiscardedSnippets: receiveDiscardedSnippets,
90 };
91 });
92
93 document.addEventListener('DOMContentLoaded',
94 chrome.snippets_internals.initialize);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698