Bug 40580: Add support for uk (ukranian) locale
[torbutton.git] / chrome / content / preferences-mobile.js
blobfa79dce811a8b9be2ed4a2ec8c60b533241c1d18
1 // # Security Settings User Interface for Mobile
3 // Utilities
4 const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
5 const { getBoolPref, getIntPref, setBoolPref, setIntPref, getCharPref }
6 = Services.prefs;
8 let { getLocale, show_torbrowser_manual } =
9 ChromeUtils.import("resource://torbutton/modules/utils.js", {});
11 // Description elements have the follow names.
12 const descNames =
13 [, "desc_standard", "desc_safer", "desc_safest"];
14 // "Learn-more"-elements have the follow names.
15 const linkNames =
16 [, "link_standard", "link_safer", "link_safest"];
17 // A single `state` object that reflects the user settings in this UI.
19 let state = { slider : 0, custom : false};
21 // Utility functions to convert between the legacy 4-value pref index
22 // and the 3-valued security slider.
23 let sliderPositionToPrefSetting = pos => [, 4, 2, 1][pos];
24 let prefSettingToSliderPosition = pref => [, 3, 2, 2, 1][pref];
26 // Set the desired slider value and update UI.
27 function torbutton_set_slider(sliderValue) {
28 state.slider = sliderValue;
29 let slider = document.getElementById("torbutton_sec_slider");
30 slider.value = sliderValue.toString();
31 let descs = descNames.map(name => document.getElementById(name));
32 descs.forEach((desc, i) => {
33 if (state.slider !== i) {
34 desc.style.display = 'none';
35 } else {
36 desc.style.display = 'block';
38 });
39 torbutton_save_security_settings();
42 // Read prefs 'extensions.torbutton.security_slider' and
43 // 'extensions.torbutton.security_custom', and initialize the UI.
44 function torbutton_init_security_ui() {
45 torbutton_set_slider(prefSettingToSliderPosition(
46 getIntPref("extensions.torbutton.security_slider")));
47 torbutton_set_learn_more_links();
50 // Write the two prefs from the current settings.
51 function torbutton_save_security_settings() {
52 setIntPref("extensions.torbutton.security_slider",
53 sliderPositionToPrefSetting(state.slider));
54 setBoolPref("extensions.torbutton.security_custom", state.custom);
57 // We follow the way we treat the links to the Tor Browser User Manual on the
58 // Help Menu and on about:tor: if we have the manual available for a locale,
59 // let's show the "Learn more"-link, otherwise hide it.
60 function torbutton_set_learn_more_links() {
61 let show_manual = show_torbrowser_manual();
62 let locale = ""
63 if (show_manual) {
64 locale = getLocale();
66 let links = linkNames.map(name => document.getElementById(name));
67 links.forEach(link => {
68 if (show_manual && locale != "") {
69 link.href= "https:/tb-manual.torproject.org/" + locale +
70 "/security-slider.html";
71 link.hidden = false;
72 } else {
73 link.hidden = true;
75 });