Chromium Code Reviews| 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 /** | 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 for (var i = 0; i < entries.length; i++) { | 15 |
| 16 var listItem = document.createElement('li'); | 16 var list = $('entries-list'); |
| 17 var link = document.createElement('a'); | 17 domDistiller.removeAllChildren(list); |
| 18 link.innerText = entries[i].title; | 18 if (entries.length > 0) { |
|
Nico
2013/12/05 00:03:58
Now that the createElement('ul') is gone, this che
nyquist
2013/12/05 00:24:02
Done.
| |
| 19 link.setAttribute('href', entries[i].url); | 19 for (var i = 0; i < entries.length; i++) { |
| 20 listItem.appendChild(link); | 20 var listItem = document.createElement('li'); |
| 21 list.appendChild(listItem); | 21 var link = document.createElement('a'); |
| 22 var entry_id = entries[i].entry_id; | |
| 23 link.setAttribute('id', 'entry-' + entry_id); | |
| 24 link.setAttribute('href', '#'); | |
| 25 link.innerText = entries[i].title; | |
| 26 link.addEventListener('click', function(event) { | |
| 27 domDistiller.onSelectArticle(event.target.id.substr("entry-".length)); | |
| 28 }, true); | |
| 29 listItem.appendChild(link); | |
| 30 list.appendChild(listItem); | |
| 31 } | |
| 22 } | 32 } |
| 23 $('entries-list').appendChild(list); | 33 }, |
| 24 } | 34 |
| 35 /** | |
| 36 * Callback from the backend when adding an article failed. | |
| 37 */ | |
| 38 onArticleAddFailed: function() { | |
| 39 $('add-entry-error').classList.remove('hidden'); | |
| 40 }, | |
| 41 | |
| 42 removeAllChildren: function(root) { | |
| 43 while(root.firstChild) { | |
| 44 root.removeChild(root.firstChild); | |
| 45 } | |
| 46 }, | |
| 47 | |
| 48 onAddArticle: function() { | |
| 49 $('add-entry-error').classList.add('hidden'); | |
| 50 var url = $('article_url').value; | |
| 51 chrome.send('addArticle', [url]); | |
| 52 }, | |
| 53 | |
| 54 onSelectArticle: function(articleId) { | |
| 55 chrome.send('selectArticle', [articleId]); | |
| 56 }, | |
| 57 | |
| 58 /* All the work we do on load. */ | |
| 59 onLoadWork: function() { | |
| 60 $('list-section').classList.remove('hidden'); | |
| 61 $('entries-list-loading').classList.add('hidden'); | |
| 62 $('add-entry-error').classList.add('hidden'); | |
| 63 | |
| 64 $('refreshbutton').addEventListener('click', function(event) { | |
| 65 domDistiller.onRequestEntries(); | |
| 66 }, false); | |
| 67 $('addbutton').addEventListener('click', function(event) { | |
| 68 domDistiller.onAddArticle(); | |
| 69 }, false); | |
| 70 domDistiller.onRequestEntries(); | |
| 71 }, | |
| 72 | |
| 73 onRequestEntries: function() { | |
| 74 $('entries-list-loading').classList.remove('hidden'); | |
| 75 chrome.send('requestEntries'); | |
| 76 }, | |
| 25 } | 77 } |
| 26 | 78 |
| 27 /* All the work we do on load. */ | 79 document.addEventListener('DOMContentLoaded', domDistiller.onLoadWork); |
| 28 function onLoadWork() { | |
| 29 chrome.send('requestEntries'); | |
| 30 } | |
| 31 | |
| 32 document.addEventListener('DOMContentLoaded', onLoadWork); | |
| OLD | NEW |