1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
var domDistiller = {
/**
* Callback from the backend with the list of entries to display.
* This call will build the entries section of the DOM distiller page, or hide
* that section if there are none to display.
* @param {!Array.<string>} entries The entries.
*/
onReceivedEntries: function(entries) {
$('entries-list-loading').classList.add('hidden');
if (!entries.length) $('entries-list').classList.add('hidden');
var list = $('entries-list');
domDistiller.removeAllChildren(list);
for (var i = 0; i < entries.length; i++) {
var listItem = document.createElement('li');
var link = document.createElement('a');
var entry_id = entries[i].entry_id;
link.setAttribute('id', 'entry-' + entry_id);
link.setAttribute('href', '#');
link.innerText = entries[i].title;
link.addEventListener('click', function(event) {
domDistiller.onSelectArticle(event.target.id.substr("entry-".length));
}, true);
listItem.appendChild(link);
list.appendChild(listItem);
}
},
/**
* Callback from the backend when adding an article failed.
*/
onArticleAddFailed: function() {
$('add-entry-error').classList.remove('hidden');
},
removeAllChildren: function(root) {
while(root.firstChild) {
root.removeChild(root.firstChild);
}
},
onAddArticle: function() {
$('add-entry-error').classList.add('hidden');
var url = $('article_url').value;
chrome.send('addArticle', [url]);
},
onSelectArticle: function(articleId) {
chrome.send('selectArticle', [articleId]);
},
/* All the work we do on load. */
onLoadWork: function() {
$('list-section').classList.remove('hidden');
$('entries-list-loading').classList.add('hidden');
$('add-entry-error').classList.add('hidden');
$('refreshbutton').addEventListener('click', function(event) {
domDistiller.onRequestEntries();
}, false);
$('addbutton').addEventListener('click', function(event) {
domDistiller.onAddArticle();
}, false);
domDistiller.onRequestEntries();
},
onRequestEntries: function() {
$('entries-list-loading').classList.remove('hidden');
chrome.send('requestEntries');
},
}
document.addEventListener('DOMContentLoaded', domDistiller.onLoadWork);
|