Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 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. | |
| 4 | |
| 5 cr.define('chrome.snippets_internals', function() { | |
| 6 'use strict'; | |
| 7 | |
| 8 function initialize() { | |
| 9 function submitDownload(event) { | |
| 10 chrome.send('download', [$('hosts-input').value]); | |
| 11 event.preventDefault(); | |
| 12 } | |
| 13 | |
| 14 $('submit-download').addEventListener('click', submitDownload); | |
| 15 | |
| 16 function submitClear(event) { | |
| 17 chrome.send('clear'); | |
| 18 event.preventDefault(); | |
| 19 } | |
| 20 | |
| 21 $('submit-clear').addEventListener('click', submitClear); | |
| 22 | |
| 23 function clearDiscarded(event) { | |
|
Marc Treib
2016/04/13 08:45:51
submitClearDiscarded, for consistency?
jkrcal
2016/04/14 15:27:00
Done.
| |
| 24 chrome.send('clearDiscarded'); | |
| 25 event.preventDefault(); | |
| 26 } | |
| 27 | |
| 28 $('discarded-snippets-clear').addEventListener('click', clearDiscarded); | |
| 29 | |
| 30 chrome.send('loaded'); | |
| 31 } | |
| 32 | |
| 33 function receiveProperty(propertyId, value) { | |
| 34 if ($(propertyId)) $(propertyId).textContent = value; | |
| 35 } | |
| 36 | |
| 37 function receiveHostsInput(value) { | |
| 38 $('hosts-input').value = value; | |
| 39 } | |
| 40 | |
| 41 function receiveHosts(hosts) { | |
| 42 displayList(hosts, 'hosts'); | |
| 43 } | |
| 44 | |
| 45 function receiveSnippets(snippets) { | |
| 46 displayList(snippets, 'snippets', 'snippet-title'); | |
| 47 } | |
| 48 | |
| 49 function receiveDiscardedSnippets(discardedSnippets) { | |
| 50 displayList(discardedSnippets, 'discarded-snippets', | |
| 51 'discarded-snippet-title'); | |
| 52 } | |
| 53 | |
| 54 function trigger(event) { | |
| 55 // The id of the div to (un)hide is stored to 'myid' attribute of the link. | |
| 56 var id = event.currentTarget.getAttribute('myid'); | |
| 57 if ($(id)) $(id).classList.toggle('snippet-hidden'); | |
| 58 } | |
| 59 | |
| 60 function displayList(object, domId, titleClass) { | |
| 61 if (object == null || !object.list || object.list.constructor !== Array) | |
|
Marc Treib
2016/04/13 08:45:51
Are these checks actually required in any legitima
jkrcal
2016/04/14 15:27:00
Done.
| |
| 62 return; | |
| 63 | |
| 64 jstProcess(new JsEvalContext(object), $(domId)); | |
| 65 | |
| 66 var text; | |
| 67 var display; | |
| 68 | |
| 69 if (object.list.length > 0) { | |
| 70 text = ''; | |
| 71 display = 'inline'; | |
| 72 } else { | |
| 73 text = 'The list is empty.'; | |
| 74 display = 'none'; | |
| 75 } | |
| 76 | |
| 77 if ($(domId + '-empty')) $(domId + '-empty').textContent = text; | |
| 78 if ($(domId + '-clear')) $(domId + '-clear').style.display = display; | |
| 79 | |
| 80 var links = document.getElementsByClassName(titleClass); | |
| 81 for (var link of links) { | |
| 82 link.addEventListener('click', trigger); | |
| 83 } | |
| 84 } | |
| 85 | |
| 86 // Return an object with all of the exports. | |
| 87 return { | |
| 88 initialize: initialize, | |
| 89 receiveProperty: receiveProperty, | |
| 90 receiveHostsInput: receiveHostsInput, | |
| 91 receiveHosts: receiveHosts, | |
| 92 receiveSnippets: receiveSnippets, | |
| 93 receiveDiscardedSnippets: receiveDiscardedSnippets, | |
| 94 trigger: trigger, | |
|
Marc Treib
2016/04/13 08:45:51
I think "trigger" doesn't need to be listed here.
jkrcal
2016/04/14 15:27:00
Done.
| |
| 95 }; | |
| 96 }); | |
| 97 | |
| 98 document.addEventListener('DOMContentLoaded', | |
| 99 chrome.snippets_internals.initialize); | |
| OLD | NEW |