OLD | NEW |
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 var domDistiller = { | 5 var domDistiller = { |
6 /** | 6 /** |
7 * Callback from the backend with the list of entries to display. | 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 | 8 * This call will build the entries section of the DOM distiller page, or hide |
9 * that section if there are none to display. | 9 * that section if there are none to display. |
10 * @param {!Array.<string>} entries The entries. | 10 * @param {!Array.<string>} entries The entries. |
(...skipping 19 matching lines...) Expand all Loading... |
30 } | 30 } |
31 }, | 31 }, |
32 | 32 |
33 /** | 33 /** |
34 * Callback from the backend when adding an article failed. | 34 * Callback from the backend when adding an article failed. |
35 */ | 35 */ |
36 onArticleAddFailed: function() { | 36 onArticleAddFailed: function() { |
37 $('add-entry-error').classList.remove('hidden'); | 37 $('add-entry-error').classList.remove('hidden'); |
38 }, | 38 }, |
39 | 39 |
| 40 /** |
| 41 * Callback from the backend when viewing a URL failed. |
| 42 */ |
| 43 onViewUrlFailed: function() { |
| 44 $('view-url-error').classList.remove('hidden'); |
| 45 }, |
| 46 |
40 removeAllChildren: function(root) { | 47 removeAllChildren: function(root) { |
41 while(root.firstChild) { | 48 while(root.firstChild) { |
42 root.removeChild(root.firstChild); | 49 root.removeChild(root.firstChild); |
43 } | 50 } |
44 }, | 51 }, |
45 | 52 |
| 53 /** |
| 54 * Sends a request to the browser process to add the URL specified to the list |
| 55 * of articles. |
| 56 */ |
46 onAddArticle: function() { | 57 onAddArticle: function() { |
47 $('add-entry-error').classList.add('hidden'); | 58 $('add-entry-error').classList.add('hidden'); |
48 var url = $('article_url').value; | 59 var url = $('article_url').value; |
49 chrome.send('addArticle', [url]); | 60 chrome.send('addArticle', [url]); |
50 }, | 61 }, |
51 | 62 |
| 63 /** |
| 64 * Sends a request to the browser process to view a distilled version of the |
| 65 * URL specified. |
| 66 */ |
| 67 onViewUrl: function() { |
| 68 $('view-url-error').classList.add('hidden'); |
| 69 var url = $('article_url').value; |
| 70 chrome.send('viewUrl', [url]); |
| 71 }, |
| 72 |
| 73 /** |
| 74 * Sends a request to the browser process to view a distilled version of the |
| 75 * selected article. |
| 76 */ |
52 onSelectArticle: function(articleId) { | 77 onSelectArticle: function(articleId) { |
53 chrome.send('selectArticle', [articleId]); | 78 chrome.send('selectArticle', [articleId]); |
54 }, | 79 }, |
55 | 80 |
56 /* All the work we do on load. */ | 81 /* All the work we do on load. */ |
57 onLoadWork: function() { | 82 onLoadWork: function() { |
58 $('list-section').classList.remove('hidden'); | 83 $('list-section').classList.remove('hidden'); |
59 $('entries-list-loading').classList.add('hidden'); | 84 $('entries-list-loading').classList.add('hidden'); |
60 $('add-entry-error').classList.add('hidden'); | 85 $('add-entry-error').classList.add('hidden'); |
| 86 $('view-url-error').classList.add('hidden'); |
61 | 87 |
62 $('refreshbutton').addEventListener('click', function(event) { | 88 $('refreshbutton').addEventListener('click', function(event) { |
63 domDistiller.onRequestEntries(); | 89 domDistiller.onRequestEntries(); |
64 }, false); | 90 }, false); |
65 $('addbutton').addEventListener('click', function(event) { | 91 $('addbutton').addEventListener('click', function(event) { |
66 domDistiller.onAddArticle(); | 92 domDistiller.onAddArticle(); |
67 }, false); | 93 }, false); |
| 94 $('viewbutton').addEventListener('click', function(event) { |
| 95 domDistiller.onViewUrl(); |
| 96 }, false); |
68 domDistiller.onRequestEntries(); | 97 domDistiller.onRequestEntries(); |
69 }, | 98 }, |
70 | 99 |
71 onRequestEntries: function() { | 100 onRequestEntries: function() { |
72 $('entries-list-loading').classList.remove('hidden'); | 101 $('entries-list-loading').classList.remove('hidden'); |
73 chrome.send('requestEntries'); | 102 chrome.send('requestEntries'); |
74 }, | 103 }, |
75 } | 104 } |
76 | 105 |
77 document.addEventListener('DOMContentLoaded', domDistiller.onLoadWork); | 106 document.addEventListener('DOMContentLoaded', domDistiller.onLoadWork); |
OLD | NEW |