| 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 // Stores the list of suggestions we received in receiveContentSuggestions. | 8 // Stores the list of suggestions we received in receiveContentSuggestions. |
| 9 var lastSuggestions = []; | 9 var lastSuggestions = []; |
| 10 | 10 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 | 43 |
| 44 refreshContent(); | 44 refreshContent(); |
| 45 } | 45 } |
| 46 | 46 |
| 47 function receiveProperty(propertyId, value) { | 47 function receiveProperty(propertyId, value) { |
| 48 $(propertyId).textContent = value; | 48 $(propertyId).textContent = value; |
| 49 } | 49 } |
| 50 | 50 |
| 51 function receiveContentSuggestions(categoriesList) { | 51 function receiveContentSuggestions(categoriesList) { |
| 52 lastSuggestions = categoriesList; | 52 lastSuggestions = categoriesList; |
| 53 displayList(categoriesList, 'content-suggestions', | 53 displayList(categoriesList, 'content-suggestions', 'hidden-toggler'); |
| 54 'hidden-toggler'); | |
| 55 | 54 |
| 56 var clearCachedButtons = | 55 var clearCachedButtons = |
| 57 document.getElementsByClassName('submit-clear-cached-suggestions'); | 56 document.getElementsByClassName('submit-clear-cached-suggestions'); |
| 58 for (var button of clearCachedButtons) { | 57 for (var button of clearCachedButtons) { |
| 59 button.addEventListener('click', onClearCachedButtonClicked); | 58 button.addEventListener('click', onClearCachedButtonClicked); |
| 60 } | 59 } |
| 61 | 60 |
| 62 var clearDismissedButtons = | 61 var clearDismissedButtons = |
| 63 document.getElementsByClassName('submit-clear-dismissed-suggestions'); | 62 document.getElementsByClassName('submit-clear-dismissed-suggestions'); |
| 64 for (var button of clearDismissedButtons) { | 63 for (var button of clearDismissedButtons) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 82 event.preventDefault(); | 81 event.preventDefault(); |
| 83 var id = parseInt(event.currentTarget.getAttribute('category-id'), 10); | 82 var id = parseInt(event.currentTarget.getAttribute('category-id'), 10); |
| 84 chrome.send('clearDismissedSuggestions', [id]); | 83 chrome.send('clearDismissedSuggestions', [id]); |
| 85 } | 84 } |
| 86 | 85 |
| 87 function onToggleDismissedButtonClicked(event) { | 86 function onToggleDismissedButtonClicked(event) { |
| 88 event.preventDefault(); | 87 event.preventDefault(); |
| 89 var id = parseInt(event.currentTarget.getAttribute('category-id'), 10); | 88 var id = parseInt(event.currentTarget.getAttribute('category-id'), 10); |
| 90 var table = $('dismissed-suggestions-' + id); | 89 var table = $('dismissed-suggestions-' + id); |
| 91 table.classList.toggle('hidden'); | 90 table.classList.toggle('hidden'); |
| 92 chrome.send('toggleDismissedSuggestions', | 91 chrome.send( |
| 92 'toggleDismissedSuggestions', |
| 93 [id, !table.classList.contains('hidden')]); | 93 [id, !table.classList.contains('hidden')]); |
| 94 } | 94 } |
| 95 | 95 |
| 96 function receiveJson(json) { | 96 function receiveJson(json) { |
| 97 var trimmed = json.trim(); | 97 var trimmed = json.trim(); |
| 98 var hasContent = (trimmed && trimmed != '{}'); | 98 var hasContent = (trimmed && trimmed != '{}'); |
| 99 | 99 |
| 100 if (hasContent) { | 100 if (hasContent) { |
| 101 receiveProperty('last-json-text', trimmed); | 101 receiveProperty('last-json-text', trimmed); |
| 102 $('last-json').classList.remove('hidden'); | 102 $('last-json').classList.remove('hidden'); |
| 103 } else { | 103 } else { |
| 104 $('last-json').classList.add('hidden'); | 104 $('last-json').classList.add('hidden'); |
| 105 } | 105 } |
| 106 } | 106 } |
| 107 | 107 |
| 108 function receiveClassification( | 108 function receiveClassification( |
| 109 userClass, timeToOpenNTP, timeToShow, timeToUse) { | 109 userClass, timeToOpenNTP, timeToShow, timeToUse) { |
| 110 receiveProperty('user-class', userClass); | 110 receiveProperty('user-class', userClass); |
| 111 receiveProperty('avg-time-to-open-ntp', timeToOpenNTP); | 111 receiveProperty('avg-time-to-open-ntp', timeToOpenNTP); |
| 112 receiveProperty('avg-time-to-show', timeToShow); | 112 receiveProperty('avg-time-to-show', timeToShow); |
| 113 receiveProperty('avg-time-to-use', timeToUse); | 113 receiveProperty('avg-time-to-use', timeToUse); |
| 114 } | 114 } |
| 115 | 115 |
| 116 function receiveLastRemoteSuggestionsBackgroundFetchTime( | 116 function receiveLastRemoteSuggestionsBackgroundFetchTime( |
| 117 lastRemoteSuggestionsBackgroundFetchTime) { | 117 lastRemoteSuggestionsBackgroundFetchTime) { |
| 118 receiveProperty('last-background-fetch-time-label', | 118 receiveProperty( |
| 119 'last-background-fetch-time-label', |
| 119 lastRemoteSuggestionsBackgroundFetchTime); | 120 lastRemoteSuggestionsBackgroundFetchTime); |
| 120 } | 121 } |
| 121 | 122 |
| 122 function downloadJson(json) { | 123 function downloadJson(json) { |
| 123 // Redirect the browser to download data in |json| as a file "snippets.json" | 124 // Redirect the browser to download data in |json| as a file "snippets.json" |
| 124 // (Setting Content-Disposition: attachment via a data: URL is not possible; | 125 // (Setting Content-Disposition: attachment via a data: URL is not possible; |
| 125 // create a link with download attribute and simulate a click, instead.) | 126 // create a link with download attribute and simulate a click, instead.) |
| 126 var link = document.createElement('a'); | 127 var link = document.createElement('a'); |
| 127 link.download = 'snippets.json'; | 128 link.download = 'snippets.json'; |
| 128 link.href = 'data:,' + json; | 129 link.href = 'data:,' + json; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 145 var display; | 146 var display; |
| 146 | 147 |
| 147 if (object.list.length > 0) { | 148 if (object.list.length > 0) { |
| 148 text = ''; | 149 text = ''; |
| 149 display = 'inline'; | 150 display = 'inline'; |
| 150 } else { | 151 } else { |
| 151 text = 'The list is empty.'; | 152 text = 'The list is empty.'; |
| 152 display = 'none'; | 153 display = 'none'; |
| 153 } | 154 } |
| 154 | 155 |
| 155 if ($(domId + '-empty')) $(domId + '-empty').textContent = text; | 156 if ($(domId + '-empty')) |
| 156 if ($(domId + '-clear')) $(domId + '-clear').style.display = display; | 157 $(domId + '-empty').textContent = text; |
| 158 if ($(domId + '-clear')) |
| 159 $(domId + '-clear').style.display = display; |
| 157 | 160 |
| 158 var links = document.getElementsByClassName(toggleClass); | 161 var links = document.getElementsByClassName(toggleClass); |
| 159 for (var link of links) { | 162 for (var link of links) { |
| 160 link.addEventListener('click', toggleHidden); | 163 link.addEventListener('click', toggleHidden); |
| 161 } | 164 } |
| 162 } | 165 } |
| 163 | 166 |
| 164 // Return an object with all of the exports. | 167 // Return an object with all of the exports. |
| 165 return { | 168 return { |
| 166 initialize: initialize, | 169 initialize: initialize, |
| 167 receiveProperty: receiveProperty, | 170 receiveProperty: receiveProperty, |
| 168 receiveContentSuggestions: receiveContentSuggestions, | 171 receiveContentSuggestions: receiveContentSuggestions, |
| 169 receiveJson: receiveJson, | 172 receiveJson: receiveJson, |
| 170 receiveClassification: receiveClassification, | 173 receiveClassification: receiveClassification, |
| 171 receiveLastRemoteSuggestionsBackgroundFetchTime: | 174 receiveLastRemoteSuggestionsBackgroundFetchTime: |
| 172 receiveLastRemoteSuggestionsBackgroundFetchTime, | 175 receiveLastRemoteSuggestionsBackgroundFetchTime, |
| 173 }; | 176 }; |
| 174 }); | 177 }); |
| 175 | 178 |
| 176 document.addEventListener('DOMContentLoaded', | 179 document.addEventListener( |
| 177 chrome.SnippetsInternals.initialize); | 180 'DOMContentLoaded', chrome.SnippetsInternals.initialize); |
| OLD | NEW |