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

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: Implementing last suggestions from Bernhard 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 2016 The Chromium Authors. All rights reserved.
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.SnippetsInternals', function() {
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 $(propertyId).textContent = value;
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 displayList(object, domId, titleClass) {
54 jstProcess(new JsEvalContext(object), $(domId));
55
56 var text;
57 var display;
58
59 if (object.list.length > 0) {
60 text = '';
61 display = 'inline';
62 } else {
63 text = 'The list is empty.';
64 display = 'none';
65 }
66
67 if ($(domId + '-empty')) $(domId + '-empty').textContent = text;
68 if ($(domId + '-clear')) $(domId + '-clear').style.display = display;
69
70 function trigger(event) {
71 // The id of the snippet is stored to 'snippet-id' attribute of the link.
72 var id = event.currentTarget.getAttribute('snippet-id');
73 $(id).classList.toggle('snippet-hidden');
74 event.preventDefault();
75 }
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.SnippetsInternals.initialize);
OLDNEW
« no previous file with comments | « chrome/browser/resources/snippets_internals.html ('k') | chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698