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

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

Issue 2145563002: Add ContentSuggestionsService to SnippetsInternals (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@articleprovider2
Patch Set: Created 4 years, 5 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 2016 The Chromium Authors. All rights reserved. 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 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 cr.define('chrome.SnippetsInternals', function() { 5 cr.define('chrome.SnippetsInternals', function() {
6 'use strict'; 6 'use strict';
7 7
8 // Stores the list of snippets we received in receiveSnippets. 8 // Stores the list of snippets we received in receiveSnippets.
9 var lastSnippets = []; 9 var lastSnippets = [];
10 10
(...skipping 20 matching lines...) Expand all
31 $('last-json-dump').addEventListener('click', function(event) { 31 $('last-json-dump').addEventListener('click', function(event) {
32 downloadJson($('last-json-text').innerText); 32 downloadJson($('last-json-text').innerText);
33 event.preventDefault(); 33 event.preventDefault();
34 }); 34 });
35 35
36 $('discarded-snippets-clear').addEventListener('click', function(event) { 36 $('discarded-snippets-clear').addEventListener('click', function(event) {
37 chrome.send('clearDiscarded'); 37 chrome.send('clearDiscarded');
38 event.preventDefault(); 38 event.preventDefault();
39 }); 39 });
40 40
41 $('submit-clear-cached-suggestions')
42 .addEventListener('click', function(event) {
43 chrome.send('clearCachedSuggestions');
44 event.preventDefault();
45 });
46
47 $('submit-clear-discarded-suggestions')
48 .addEventListener('click', function(event) {
49 chrome.send('clearDiscardedSuggestions');
50 event.preventDefault();
51 });
52
41 chrome.send('loaded'); 53 chrome.send('loaded');
42 } 54 }
43 55
44 function setHostRestricted(restricted) { 56 function setHostRestricted(restricted) {
45 receiveProperty('switch-restrict-to-hosts', restricted ? 'True' : 'False'); 57 receiveProperty('switch-restrict-to-hosts', restricted ? 'True' : 'False');
46 if (!restricted) { 58 if (!restricted) {
47 $('hosts-restrict').classList.add('hidden'); 59 $('hosts-restrict').classList.add('hidden');
48 } 60 }
49 } 61 }
50 62
(...skipping 11 matching lines...) Expand all
62 function receiveSnippets(snippets) { 74 function receiveSnippets(snippets) {
63 lastSnippets = snippets; 75 lastSnippets = snippets;
64 displayList(snippets, 'snippets', 'snippet-title'); 76 displayList(snippets, 'snippets', 'snippet-title');
65 } 77 }
66 78
67 function receiveDiscardedSnippets(discardedSnippets) { 79 function receiveDiscardedSnippets(discardedSnippets) {
68 displayList(discardedSnippets, 'discarded-snippets', 80 displayList(discardedSnippets, 'discarded-snippets',
69 'discarded-snippet-title'); 81 'discarded-snippet-title');
70 } 82 }
71 83
84 function receiveContentSuggestions(categoriesList) {
85 displayList(categoriesList, 'content-suggestions',
86 'content-suggestion-title');
87 }
88
72 function receiveJson(json) { 89 function receiveJson(json) {
73 var trimmed = json.trim(); 90 var trimmed = json.trim();
74 var hasContent = (trimmed && trimmed != '{}'); 91 var hasContent = (trimmed && trimmed != '{}');
75 92
76 if (hasContent) { 93 if (hasContent) {
77 receiveProperty('last-json-text', trimmed); 94 receiveProperty('last-json-text', trimmed);
78 $('last-json').classList.remove('hidden'); 95 $('last-json').classList.remove('hidden');
79 } else { 96 } else {
80 $('last-json').classList.add('hidden'); 97 $('last-json').classList.add('hidden');
81 } 98 }
(...skipping 21 matching lines...) Expand all
103 } else { 120 } else {
104 text = 'The list is empty.'; 121 text = 'The list is empty.';
105 display = 'none'; 122 display = 'none';
106 } 123 }
107 124
108 if ($(domId + '-empty')) $(domId + '-empty').textContent = text; 125 if ($(domId + '-empty')) $(domId + '-empty').textContent = text;
109 if ($(domId + '-clear')) $(domId + '-clear').style.display = display; 126 if ($(domId + '-clear')) $(domId + '-clear').style.display = display;
110 127
111 var links = document.getElementsByClassName(titleClass); 128 var links = document.getElementsByClassName(titleClass);
112 for (var link of links) { 129 for (var link of links) {
113 link.addEventListener('click', function(event) { 130 link.onclick = function(event) {
Marc Treib 2016/07/12 13:04:52 Forgive my ignorance, but is there any difference
Bernhard Bauer 2016/07/12 13:09:45 I would either use addEventListener everywhere or
Philipp Keck 2016/07/12 13:45:02 onclick allows for one, removal by ".onclick = nul
Marc Treib 2016/07/12 13:49:47 I'm moderately sure that it *was* actually an issu
jkrcal 2016/07/13 11:35:23 I can confirm that the toggle behaved weirdly some
114 var id = event.currentTarget.getAttribute('snippet-id'); 131 var id = event.currentTarget.getAttribute('hidden-id');
115 $(id).classList.toggle('hidden'); 132 $(id).classList.toggle('hidden');
116 }); 133 };
117 } 134 }
118 } 135 }
119 136
120 // Return an object with all of the exports. 137 // Return an object with all of the exports.
121 return { 138 return {
122 initialize: initialize, 139 initialize: initialize,
123 setHostRestricted: setHostRestricted, 140 setHostRestricted: setHostRestricted,
124 receiveProperty: receiveProperty, 141 receiveProperty: receiveProperty,
125 receiveHosts: receiveHosts, 142 receiveHosts: receiveHosts,
126 receiveSnippets: receiveSnippets, 143 receiveSnippets: receiveSnippets,
127 receiveDiscardedSnippets: receiveDiscardedSnippets, 144 receiveDiscardedSnippets: receiveDiscardedSnippets,
145 receiveContentSuggestions: receiveContentSuggestions,
128 receiveJson: receiveJson, 146 receiveJson: receiveJson,
129 }; 147 };
130 }); 148 });
131 149
132 document.addEventListener('DOMContentLoaded', 150 document.addEventListener('DOMContentLoaded',
133 chrome.SnippetsInternals.initialize); 151 chrome.SnippetsInternals.initialize);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698