OLD | NEW |
1 // Copyright 2016 Google Inc. All rights reserved. | 1 // Copyright 2016 Google Inc. 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 // Define the customary shorthand for getElementById. |
| 6 var $ = document.getElementById.bind(document); |
| 7 |
5 // Load strings from messages.json into the HTML page. Each element that needs | 8 // Load strings from messages.json into the HTML page. Each element that needs |
6 // an internationalized string should have an 'i18n' property holding the | 9 // an internationalized string should have an 'i18n' property holding the |
7 // name of the message to be used. | 10 // name of the message to be used. If the element instead has an 'i18n-alt' |
8 function LoadInternationalizedStrings() { | 11 // property, that message will be used for the alt and title attributes of the |
| 12 // element (generally an image). |
| 13 function loadInternationalizedStrings() { |
9 var all = document.querySelectorAll('[i18n]'); | 14 var all = document.querySelectorAll('[i18n]'); |
| 15 for (var i = 0; i < all.length; ++i) |
| 16 all[i].textContent = chrome.i18n.getMessage(all[i].getAttribute('i18n')); |
| 17 |
| 18 all = document.querySelectorAll('[i18n-alt]'); |
10 for (var i = 0; i < all.length; ++i) { | 19 for (var i = 0; i < all.length; ++i) { |
11 var i18n = all[i].getAttribute('i18n'); | 20 var message = chrome.i18n.getMessage(all[i].getAttribute('i18n-alt')); |
12 if (i18n) | 21 all[i].alt = message; |
13 all[i].textContent = chrome.i18n.getMessage(i18n); | 22 all[i].title = message; |
14 } | 23 } |
15 } | 24 } |
16 | 25 |
17 // Open a pre-filled email to send feedback to the extension developers. The | 26 // Open a pre-filled email to send feedback to the extension developers. The |
18 // initial content of the email depends on whether the URL of the current page | 27 // initial content of the email depends on whether the URL of the current page |
19 // is provided. | 28 // is provided. |
20 function reportPage(url) { | 29 function sendFeedback(opt_url) { |
21 var subject = chrome.i18n.getMessage('reportSubject'); | 30 var subject = chrome.i18n.getMessage('reportSubject'); |
22 var body = ''; | 31 var body = ''; |
23 if (url) | 32 if (opt_url) |
24 body = chrome.i18n.getMessage('reportBodyWithURL', url); | 33 body = chrome.i18n.getMessage('reportBodyWithURL', opt_url); |
25 else | 34 else |
26 body = chrome.i18n.getMessage('reportBody'); | 35 body = chrome.i18n.getMessage('reportBody'); |
27 var msg = 'mailto:gobackwithbackspace@google.com' + | 36 var msg = 'mailto:gobackwithbackspace@google.com' + |
28 '?subject=' + encodeURIComponent(subject) + | 37 '?subject=' + encodeURIComponent(subject) + |
29 '&body=' + encodeURIComponent(body); | 38 '&body=' + encodeURIComponent(body); |
30 chrome.tabs.create({ | 39 chrome.tabs.create({ |
31 url: msg, | 40 url: msg, |
32 active: true}); | 41 active: true}); |
33 } | 42 } |
OLD | NEW |