| 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 receiveRankerDebugData(itemsList) { | 116 function receiveRankerDebugData(itemsList) { |
| 117 displayList(itemsList, 'ranker', 'no-togler'); | 117 displayList(itemsList, 'ranker', 'no-togler'); |
| 118 } | 118 } |
| 119 | 119 |
| 120 function receiveLastRemoteSuggestionsBackgroundFetchTime( | 120 function receiveLastRemoteSuggestionsBackgroundFetchTime( |
| 121 lastRemoteSuggestionsBackgroundFetchTime) { | 121 lastRemoteSuggestionsBackgroundFetchTime) { |
| 122 receiveProperty('last-background-fetch-time-label', | 122 receiveProperty( |
| 123 'last-background-fetch-time-label', |
| 123 lastRemoteSuggestionsBackgroundFetchTime); | 124 lastRemoteSuggestionsBackgroundFetchTime); |
| 124 } | 125 } |
| 125 | 126 |
| 126 function downloadJson(json) { | 127 function downloadJson(json) { |
| 127 // Redirect the browser to download data in |json| as a file "snippets.json" | 128 // Redirect the browser to download data in |json| as a file "snippets.json" |
| 128 // (Setting Content-Disposition: attachment via a data: URL is not possible; | 129 // (Setting Content-Disposition: attachment via a data: URL is not possible; |
| 129 // create a link with download attribute and simulate a click, instead.) | 130 // create a link with download attribute and simulate a click, instead.) |
| 130 var link = document.createElement('a'); | 131 var link = document.createElement('a'); |
| 131 link.download = 'snippets.json'; | 132 link.download = 'snippets.json'; |
| 132 link.href = 'data:application/json,' + encodeURI(json); | 133 link.href = 'data:application/json,' + encodeURI(json); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 149 var display; | 150 var display; |
| 150 | 151 |
| 151 if (object.list.length > 0) { | 152 if (object.list.length > 0) { |
| 152 text = ''; | 153 text = ''; |
| 153 display = 'inline'; | 154 display = 'inline'; |
| 154 } else { | 155 } else { |
| 155 text = 'The list is empty.'; | 156 text = 'The list is empty.'; |
| 156 display = 'none'; | 157 display = 'none'; |
| 157 } | 158 } |
| 158 | 159 |
| 159 if ($(domId + '-empty')) $(domId + '-empty').textContent = text; | 160 if ($(domId + '-empty')) |
| 160 if ($(domId + '-clear')) $(domId + '-clear').style.display = display; | 161 $(domId + '-empty').textContent = text; |
| 162 if ($(domId + '-clear')) |
| 163 $(domId + '-clear').style.display = display; |
| 161 | 164 |
| 162 var links = document.getElementsByClassName(toggleClass); | 165 var links = document.getElementsByClassName(toggleClass); |
| 163 for (var link of links) { | 166 for (var link of links) { |
| 164 link.addEventListener('click', toggleHidden); | 167 link.addEventListener('click', toggleHidden); |
| 165 } | 168 } |
| 166 } | 169 } |
| 167 | 170 |
| 168 // Return an object with all of the exports. | 171 // Return an object with all of the exports. |
| 169 return { | 172 return { |
| 170 initialize: initialize, | 173 initialize: initialize, |
| 171 receiveProperty: receiveProperty, | 174 receiveProperty: receiveProperty, |
| 172 receiveContentSuggestions: receiveContentSuggestions, | 175 receiveContentSuggestions: receiveContentSuggestions, |
| 173 receiveJson: receiveJson, | 176 receiveJson: receiveJson, |
| 174 receiveClassification: receiveClassification, | 177 receiveClassification: receiveClassification, |
| 175 receiveRankerDebugData: receiveRankerDebugData, | 178 receiveRankerDebugData: receiveRankerDebugData, |
| 176 receiveLastRemoteSuggestionsBackgroundFetchTime: | 179 receiveLastRemoteSuggestionsBackgroundFetchTime: |
| 177 receiveLastRemoteSuggestionsBackgroundFetchTime, | 180 receiveLastRemoteSuggestionsBackgroundFetchTime, |
| 178 }; | 181 }; |
| 179 }); | 182 }); |
| 180 | 183 |
| 181 document.addEventListener('DOMContentLoaded', | 184 document.addEventListener( |
| 182 chrome.SnippetsInternals.initialize); | 185 'DOMContentLoaded', chrome.SnippetsInternals.initialize); |
| OLD | NEW |