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 (function() { | 5 (function() { |
6 'use strict'; | 6 'use strict'; |
7 | 7 |
8 cr.define('cr.translateInternals', function() { | 8 cr.define('cr.translateInternals', function() { |
9 | 9 |
10 var detectionLogs_ = null; | 10 var detectionLogs_ = null; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
53 if (tabpanelIds.indexOf(id) == -1) | 53 if (tabpanelIds.indexOf(id) == -1) |
54 return; | 54 return; |
55 | 55 |
56 $(id).selected = true; | 56 $(id).selected = true; |
57 }; | 57 }; |
58 | 58 |
59 window.onhashchange = activateTabByHash; | 59 window.onhashchange = activateTabByHash; |
60 activateTabByHash(); | 60 activateTabByHash(); |
61 } | 61 } |
62 | 62 |
63 /* | |
64 * Creates a button to dismiss an item. | |
65 * | |
66 * @param {Function} func Callback called when the button is clicked. | |
67 */ | |
68 function createDismissingButton(func) { | |
69 var button = document.createElement('button'); | |
70 button.textContent = 'X'; | |
71 button.classList.add('dismissing'); | |
72 button.addEventListener('click', function(e) { | |
73 e.preventDefault(); | |
74 func(); | |
75 }, false); | |
76 return button; | |
77 } | |
78 | |
63 /** | 79 /** |
64 * Creates a new LI element with a button to dismiss the item. | 80 * Creates a new LI element with a button to dismiss the item. |
65 * | 81 * |
66 * @param {string} text The lable of the LI element. | 82 * @param {string} text The lable of the LI element. |
67 * @param {Function} func Callback called when the button is clicked. | 83 * @param {Function} func Callback called when the button is clicked. |
68 */ | 84 */ |
69 function createLIWithDismissingButton(text, func) { | 85 function createLIWithDismissingButton(text, func) { |
70 var span = document.createElement('span'); | 86 var span = document.createElement('span'); |
71 span.textContent = text; | 87 span.textContent = text; |
72 | 88 |
73 var li = document.createElement('li'); | 89 var li = document.createElement('li'); |
74 li.appendChild(span); | 90 li.appendChild(span); |
75 | 91 li.appendChild(createDismissingButton(func)); |
76 var button = document.createElement('button'); | |
77 button.textContent = 'X'; | |
78 button.addEventListener('click', function(e) { | |
79 e.preventDefault(); | |
80 func(); | |
81 }, false); | |
82 | |
83 li.appendChild(button); | |
84 return li; | 92 return li; |
85 } | 93 } |
86 | 94 |
87 /** | 95 /** |
88 * Formats the language name to a human-readable text. For example, if | 96 * Formats the language name to a human-readable text. For example, if |
89 * |langCode| is 'en', this may return 'en (English)'. | 97 * |langCode| is 'en', this may return 'en (English)'. |
90 * | 98 * |
91 * @param {string} langCode ISO 639 language code. | 99 * @param {string} langCode ISO 639 language code. |
92 * @return {string} The formatted string. | 100 * @return {string} The formatted string. |
93 */ | 101 */ |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
199 formatLanguageCode(toLangCode); | 207 formatLanguageCode(toLangCode); |
200 | 208 |
201 var li = createLIWithDismissingButton(text, function() { | 209 var li = createLIWithDismissingButton(text, function() { |
202 chrome.send('removePrefItem', | 210 chrome.send('removePrefItem', |
203 ['whitelists', fromLangCode, toLangCode]); | 211 ['whitelists', fromLangCode, toLangCode]); |
204 }); | 212 }); |
205 ul.appendChild(li); | 213 ul.appendChild(li); |
206 }); | 214 }); |
207 } | 215 } |
208 | 216 |
209 var p = document.querySelector('#prefs-dump p'); | 217 var p = $('prefs-too-often-denied'); |
218 p.classList.toggle('prefs-setting-disabled', | |
219 !detail['translate_too_often_denied']); | |
220 p.appendChild(createDismissingButton(function() { | |
Evan Stade
2014/07/07 16:12:39
I think if you do:
p.appendChild(createDismissing
hajimehoshi
2014/07/08 05:33:47
Done.
| |
221 chrome.send('removePrefItem', ['too_often_denied']); | |
222 })); | |
223 | |
224 p = document.querySelector('#prefs-dump p'); | |
210 var content = JSON.stringify(detail, null, 2); | 225 var content = JSON.stringify(detail, null, 2); |
211 p.textContent = content; | 226 p.textContent = content; |
212 } | 227 } |
213 | 228 |
214 /** | 229 /** |
215 * Handles the message of 'supportedLanguagesUpdated' from the browser. | 230 * Handles the message of 'supportedLanguagesUpdated' from the browser. |
216 * | 231 * |
217 * @param {Object} details the object which represents the supported | 232 * @param {Object} details the object which represents the supported |
218 * languages by the Translate server. | 233 * languages by the Translate server. |
219 */ | 234 */ |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
431 /** | 446 /** |
432 * The entry point of the UI. | 447 * The entry point of the UI. |
433 */ | 448 */ |
434 function main() { | 449 function main() { |
435 cr.doc.addEventListener('DOMContentLoaded', | 450 cr.doc.addEventListener('DOMContentLoaded', |
436 cr.translateInternals.initialize); | 451 cr.translateInternals.initialize); |
437 } | 452 } |
438 | 453 |
439 main(); | 454 main(); |
440 })(); | 455 })(); |
OLD | NEW |