| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 cr.define('chrome.SnippetsInternals', function() { | 5 cr.define('chrome.SnippetsInternals', function() { |
| 6 'use strict'; | 6 'use strict'; |
| 7 | 7 |
| 8 function initialize() { | 8 function initialize() { |
| 9 $('submit-download').addEventListener('click', function(event) { | 9 $('submit-download').addEventListener('click', function(event) { |
| 10 chrome.send('download', [$('hosts-input').value]); | 10 chrome.send('download', [$('hosts-input').value]); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 }); | 31 }); |
| 32 | 32 |
| 33 $('discarded-snippets-clear').addEventListener('click', function(event) { | 33 $('discarded-snippets-clear').addEventListener('click', function(event) { |
| 34 chrome.send('clearDiscarded'); | 34 chrome.send('clearDiscarded'); |
| 35 event.preventDefault(); | 35 event.preventDefault(); |
| 36 }); | 36 }); |
| 37 | 37 |
| 38 chrome.send('loaded'); | 38 chrome.send('loaded'); |
| 39 } | 39 } |
| 40 | 40 |
| 41 function setHostRestricted(restricted) { |
| 42 receiveProperty('switch-restrict-to-hosts', restricted ? 'True' : 'False'); |
| 43 if (!restricted) { |
| 44 $('hosts-restrict').classList.add('hidden'); |
| 45 } |
| 46 } |
| 47 |
| 41 function receiveProperty(propertyId, value) { | 48 function receiveProperty(propertyId, value) { |
| 42 $(propertyId).textContent = value; | 49 $(propertyId).textContent = value; |
| 43 } | 50 } |
| 44 | 51 |
| 45 function receiveHosts(hosts) { | 52 function receiveHosts(hosts) { |
| 46 displayList(hosts, 'hosts'); | 53 displayList(hosts, 'hosts'); |
| 47 | 54 |
| 48 $('hosts-input').value = hosts.list.map( | 55 $('hosts-input').value = hosts.list.map( |
| 49 function(host) { return host.url;}).join(' '); | 56 function(host) { return host.url;}).join(' '); |
| 50 } | 57 } |
| 51 | 58 |
| 52 function receiveSnippets(snippets) { | 59 function receiveSnippets(snippets) { |
| 53 displayList(snippets, 'snippets', 'snippet-title'); | 60 displayList(snippets, 'snippets', 'snippet-title'); |
| 54 } | 61 } |
| 55 | 62 |
| 56 function receiveDiscardedSnippets(discardedSnippets) { | 63 function receiveDiscardedSnippets(discardedSnippets) { |
| 57 displayList(discardedSnippets, 'discarded-snippets', | 64 displayList(discardedSnippets, 'discarded-snippets', |
| 58 'discarded-snippet-title'); | 65 'discarded-snippet-title'); |
| 59 } | 66 } |
| 60 | 67 |
| 61 function receiveJson(json) { | 68 function receiveJson(json) { |
| 62 receiveProperty('last-json-text', json); | 69 var trimmed = json.trim(); |
| 63 if (json) { | 70 var hasContent = (trimmed && trimmed != '{}'); |
| 71 |
| 72 if (hasContent) { |
| 73 receiveProperty('last-json-text', trimmed); |
| 64 $('last-json').classList.remove('hidden'); | 74 $('last-json').classList.remove('hidden'); |
| 65 } else { | 75 } else { |
| 66 $('last-json').classList.add('hidden'); | 76 $('last-json').classList.add('hidden'); |
| 67 } | 77 } |
| 68 } | 78 } |
| 69 | 79 |
| 70 function receiveJsonToDownload(json) { | 80 function receiveJsonToDownload(json) { |
| 71 // Redirect the browser to download data in |json| as a file "snippets.json" | 81 // Redirect the browser to download data in |json| as a file "snippets.json" |
| 72 // (Setting Content-Disposition: attachment via a data: URL is not possible; | 82 // (Setting Content-Disposition: attachment via a data: URL is not possible; |
| 73 // create a link with download attribute and simulate a click, instead.) | 83 // create a link with download attribute and simulate a click, instead.) |
| (...skipping 25 matching lines...) Expand all Loading... |
| 99 link.addEventListener('click', function(event) { | 109 link.addEventListener('click', function(event) { |
| 100 var id = event.currentTarget.getAttribute('snippet-id'); | 110 var id = event.currentTarget.getAttribute('snippet-id'); |
| 101 $(id).classList.toggle('hidden'); | 111 $(id).classList.toggle('hidden'); |
| 102 }); | 112 }); |
| 103 } | 113 } |
| 104 } | 114 } |
| 105 | 115 |
| 106 // Return an object with all of the exports. | 116 // Return an object with all of the exports. |
| 107 return { | 117 return { |
| 108 initialize: initialize, | 118 initialize: initialize, |
| 119 setHostRestricted: setHostRestricted, |
| 109 receiveProperty: receiveProperty, | 120 receiveProperty: receiveProperty, |
| 110 receiveHosts: receiveHosts, | 121 receiveHosts: receiveHosts, |
| 111 receiveSnippets: receiveSnippets, | 122 receiveSnippets: receiveSnippets, |
| 112 receiveDiscardedSnippets: receiveDiscardedSnippets, | 123 receiveDiscardedSnippets: receiveDiscardedSnippets, |
| 113 receiveJson: receiveJson, | 124 receiveJson: receiveJson, |
| 114 receiveJsonToDownload: receiveJsonToDownload, | 125 receiveJsonToDownload: receiveJsonToDownload, |
| 115 }; | 126 }; |
| 116 }); | 127 }); |
| 117 | 128 |
| 118 document.addEventListener('DOMContentLoaded', | 129 document.addEventListener('DOMContentLoaded', |
| 119 chrome.SnippetsInternals.initialize); | 130 chrome.SnippetsInternals.initialize); |
| OLD | NEW |