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
3 // found in the LICENSE file.
7 * Callback from the backend with the list of entries to display.
8 * This call will build the entries section of the DOM distiller page, or hide
9 * that section if there are none to display.
10 * @param {!Array<string>} entries The entries.
12 onReceivedEntries: function(entries) {
13 $('entries-list-loading').classList.add('hidden');
14 if (!entries.length) $('entries-list').classList.add('hidden');
16 var list = $('entries-list');
17 domDistiller.removeAllChildren(list);
18 for (var i = 0; i < entries.length; i++) {
19 var listItem = document.createElement('li');
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', '#');
24 link.innerText = entries[i].title;
25 link.addEventListener('click', function(event) {
26 domDistiller.onSelectArticle(event.target.id.substr("entry-".length));
28 listItem.appendChild(link);
29 list.appendChild(listItem);
34 * Callback from the backend when adding an article failed.
36 onArticleAddFailed: function() {
37 $('add-entry-error').classList.remove('hidden');
41 * Callback from the backend when viewing a URL failed.
43 onViewUrlFailed: function() {
44 $('view-url-error').classList.remove('hidden');
47 removeAllChildren: function(root) {
48 while(root.firstChild) {
49 root.removeChild(root.firstChild);
54 * Sends a request to the browser process to add the URL specified to the list
57 onAddArticle: function() {
58 $('add-entry-error').classList.add('hidden');
59 var url = $('article_url').value;
60 chrome.send('addArticle', [url]);
64 * Sends a request to the browser process to view a distilled version of the
67 onViewUrl: function() {
68 $('view-url-error').classList.add('hidden');
69 var url = $('article_url').value;
70 chrome.send('viewUrl', [url]);
74 * Sends a request to the browser process to view a distilled version of the
77 onSelectArticle: function(articleId) {
78 chrome.send('selectArticle', [articleId]);
81 /* All the work we do on load. */
82 onLoadWork: function() {
83 $('list-section').classList.remove('hidden');
84 $('entries-list-loading').classList.add('hidden');
85 $('add-entry-error').classList.add('hidden');
86 $('view-url-error').classList.add('hidden');
88 $('refreshbutton').addEventListener('click', function(event) {
89 domDistiller.onRequestEntries();
91 $('addbutton').addEventListener('click', function(event) {
92 domDistiller.onAddArticle();
94 $('viewbutton').addEventListener('click', function(event) {
95 domDistiller.onViewUrl();
97 domDistiller.onRequestEntries();
100 onRequestEntries: function() {
101 $('entries-list-loading').classList.remove('hidden');
102 chrome.send('requestEntries');
106 document.addEventListener('DOMContentLoaded', domDistiller.onLoadWork);