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

Side by Side Diff: components/dom_distiller/webui/resources/about_dom_distiller.js

Issue 105623002: Debug UI for DOM distiller supports distillation and lists articles. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix strings and dependencies for ios Created 7 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 var domDistiller = {
6 * Callback from the backend with the list of entries to display. 6 /**
7 * This call will build the entries section of the DOM distiller page, or hide 7 * Callback from the backend with the list of entries to display.
8 * that section if there are none to display. 8 * This call will build the entries section of the DOM distiller page, or hide
9 * @param {!Array.<string>} entries The entries. 9 * that section if there are none to display.
10 */ 10 * @param {!Array.<string>} entries The entries.
11 function onGotEntries(entries) { 11 */
12 $('entries-section').hidden = !entries.length; 12 onReceivedEntries: function(entries) {
13 if (entries.length > 0) { 13 $('entries-list-loading').classList.add('hidden');
14 var list = document.createElement('ul'); 14 if (!entries.length) $('entries-list').classList.add('hidden');
15
16 var list = $('entries-list');
17 domDistiller.removeAllChildren(list);
15 for (var i = 0; i < entries.length; i++) { 18 for (var i = 0; i < entries.length; i++) {
16 var listItem = document.createElement('li'); 19 var listItem = document.createElement('li');
17 var link = document.createElement('a'); 20 var link = document.createElement('a');
21 var entry_id = entries[i].entry_id;
22 link.setAttribute('id', 'entry-' + entry_id);
23 link.setAttribute('href', '#');
18 link.innerText = entries[i].title; 24 link.innerText = entries[i].title;
19 link.setAttribute('href', entries[i].url); 25 link.addEventListener('click', function(event) {
26 domDistiller.onSelectArticle(event.target.id.substr("entry-".length));
27 }, true);
20 listItem.appendChild(link); 28 listItem.appendChild(link);
21 list.appendChild(listItem); 29 list.appendChild(listItem);
22 } 30 }
23 $('entries-list').appendChild(list); 31 },
24 } 32
33 /**
34 * Callback from the backend when adding an article failed.
35 */
36 onArticleAddFailed: function() {
37 $('add-entry-error').classList.remove('hidden');
38 },
39
40 removeAllChildren: function(root) {
41 while(root.firstChild) {
42 root.removeChild(root.firstChild);
43 }
44 },
45
46 onAddArticle: function() {
47 $('add-entry-error').classList.add('hidden');
48 var url = $('article_url').value;
49 chrome.send('addArticle', [url]);
50 },
51
52 onSelectArticle: function(articleId) {
53 chrome.send('selectArticle', [articleId]);
54 },
55
56 /* All the work we do on load. */
57 onLoadWork: function() {
58 $('list-section').classList.remove('hidden');
59 $('entries-list-loading').classList.add('hidden');
60 $('add-entry-error').classList.add('hidden');
61
62 $('refreshbutton').addEventListener('click', function(event) {
63 domDistiller.onRequestEntries();
64 }, false);
65 $('addbutton').addEventListener('click', function(event) {
66 domDistiller.onAddArticle();
67 }, false);
68 domDistiller.onRequestEntries();
69 },
70
71 onRequestEntries: function() {
72 $('entries-list-loading').classList.remove('hidden');
73 chrome.send('requestEntries');
74 },
25 } 75 }
26 76
27 /* All the work we do on load. */ 77 document.addEventListener('DOMContentLoaded', domDistiller.onLoadWork);
28 function onLoadWork() {
29 chrome.send('requestEntries');
30 }
31
32 document.addEventListener('DOMContentLoaded', onLoadWork);
OLDNEW
« no previous file with comments | « components/dom_distiller/webui/resources/about_dom_distiller.html ('k') | components/dom_distiller_strings.grdp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698