aboutTor.xhtml 12.8 KB
Newer Older
1
2
<?xml version="1.0" encoding="UTF-8"?>
<!--
3
   - Copyright (c) 2015, The Tor Project, Inc.
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
   - See LICENSE for licensing information.
   - vim: set sw=2 sts=2 ts=8 et syntax=xml:
  -->

<!DOCTYPE html [
  <!ENTITY % htmlDTD
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "DTD/xhtml1-strict.dtd">
  %htmlDTD;
  <!ENTITY % globalDTD SYSTEM "chrome://global/locale/global.dtd">
  %globalDTD;
  <!ENTITY % aboutTorDTD SYSTEM "chrome://torbutton/locale/aboutTor.dtd">
  %aboutTorDTD;
]>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>&aboutTor.title;</title>
  <link rel="stylesheet" type="text/css" media="all"
        href="chrome://torbutton/skin/aboutTor.css"/>
24
<script type="text/javascript;version=1.7">
25
 <![CDATA[
26
27
28
29
let kPropertiesURL = "chrome://torbutton/locale/aboutTor.properties";
Components.utils.import("resource://gre/modules/Services.jsm");
let gStringBundle = Services.strings.createBundle(kPropertiesURL);

30
31
function onLoad()
{
32
33
  insertPropertyStrings();

34
35
  setupDonationBanner();

36
37
  document.addEventListener("AboutTorAdjustArrow", function() {
    adjustToolbarIconArrow();
38
39
40
  }, false);

  window.setTimeout( function() {
41
    adjustToolbarIconArrow();
42
43
44
  }, 0);
}

45
function adjustToolbarIconArrow()
46
{
47
48
49
50
51
52
53
54
55
56
57
58
59
60
  let textElem = document.getElementById("updatePrompt");
  let arrowHeadDiv = document.getElementById("toolbarIconArrowHead");
  let vertExtDiv = document.getElementById("toolbarIconArrowVertExtension");
  let bendDiv = document.getElementById("toolbarIconArrowBend");
  let horzExtDiv = document.getElementById("toolbarIconArrowHorzExtension");
  if (!textElem || !arrowHeadDiv || !vertExtDiv || !bendDiv || !horzExtDiv)
    return;

  let arrowTailElems = [ vertExtDiv, bendDiv, horzExtDiv ];
  let tbXpos;
  if (document.body.hasAttribute("torbutton-xpos"))
    tbXpos = parseInt(document.body.getAttribute("torbutton-xpos"), 10);

  if (!tbXpos || isNaN(tbXpos) || (tbXpos < 0))
61
  {
62
63
64
65
66
    arrowHeadDiv.style.display = "none";
    for (let elem of arrowTailElems)
      elem.style.display = "none";
    return;
  }
67

68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
  // Account for content zoom and retina displays by converting to device
  // independent units.
  if ("devicePixelRatio" in window)  // FF18+
    tbXpos /= window.devicePixelRatio;

  const kArrowMargin = 6;          // Horizontal margin between line and text.
  const kArrowHeadExtraWidth = 9;  // Horizontal margin to the line.
  const kArrowLineThickness = 11;
  const kBendWidth = 22;
  const kBendHeight = 22;

  arrowHeadDiv.style.display = "block";  // Must be visible to get offsetWidth.
  let arrowHalfWidth = Math.round(arrowHeadDiv.offsetWidth / 2);
  let leftAnchor = textElem.offsetLeft - kArrowMargin
                    - kBendWidth + Math.round(kArrowLineThickness / 2);
  let rightAnchor = textElem.offsetLeft + textElem.offsetWidth
                    + kArrowMargin + arrowHalfWidth;

  let isArrowOnLeft = (tbXpos < leftAnchor);
  let isArrowOnRight = (tbXpos > rightAnchor) &&
                       (tbXpos < (window.innerWidth - arrowHalfWidth));
  let isArrowInMiddle = (tbXpos >= leftAnchor) && (tbXpos <= rightAnchor);

  if (isArrowOnLeft || isArrowOnRight || isArrowInMiddle)
  {
    // Position the arrow head.
    let arrowHeadLeft = tbXpos - arrowHalfWidth;
    arrowHeadDiv.style.left = arrowHeadLeft + "px";
    if (isArrowOnLeft || isArrowOnRight)
97
    {
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
      let horzExtBottom = textElem.offsetTop +
               Math.round((textElem.offsetHeight + kArrowLineThickness) / 2);

      // Position the vertical (extended) line.
      let arrowHeadBottom = arrowHeadDiv.offsetTop + arrowHeadDiv.offsetHeight;
      vertExtDiv.style.top = arrowHeadBottom + "px";
      vertExtDiv.style.left = (arrowHeadLeft + kArrowHeadExtraWidth) + "px";
      let ht = horzExtBottom - kBendHeight - arrowHeadBottom;
      vertExtDiv.style.height = ht + "px";

      // Position the bend (elbow).
      bendDiv.style.top = (horzExtBottom - kBendHeight) + "px";
      let bendDivLeft;
      if (isArrowOnLeft)
      {
        bendDiv.setAttribute("pos", "left");
        bendDivLeft = arrowHeadLeft + kArrowHeadExtraWidth;
      }
      else if (isArrowOnRight)
      {
        bendDiv.setAttribute("pos", "right");
        bendDivLeft = arrowHeadLeft + kArrowHeadExtraWidth
                      + kArrowLineThickness - kBendWidth;
      }
      bendDiv.style.left = bendDivLeft + "px";

      // Position the horizontal (extended) line.
      horzExtDiv.style.top = (horzExtBottom - kArrowLineThickness) + "px";
      let horzExtLeft, w;
      if (isArrowOnLeft)
      {
        horzExtLeft = bendDivLeft + kBendWidth;
        w = (textElem.offsetLeft - horzExtLeft - kArrowMargin);
      }
      else
      {
        horzExtLeft = rightAnchor - arrowHalfWidth;
        w = tbXpos - arrowHalfWidth - horzExtLeft;
      }
      horzExtDiv.style.left = horzExtLeft + "px";
      horzExtDiv.style.width = w + "px";
139
    }
140
  }
141
142
143
144
145
146
147

  let headDisplay = (isArrowOnLeft || isArrowInMiddle || isArrowOnRight)
                      ? "block" : "none";
  arrowHeadDiv.style.display = headDisplay;
  let tailDisplay = (isArrowOnLeft || isArrowOnRight) ? "block" : "none";
  for (let elem of arrowTailElems)
    elem.style.display = tailDisplay;
148
}
149
150
151
152

function insertPropertyStrings()
{
  try {
153
154
155
    let s1 = gStringBundle.GetStringFromName("aboutTor.searchDC.privacy.link");
    let s2 = gStringBundle.GetStringFromName("aboutTor.searchDC.search.link");
    let result = gStringBundle.formatStringFromName("aboutTor.searchDC.privacy",
156
157
                  [s1, s2], 2);
    if (result) {
158
      let elem = document.getElementById("searchProviderInfo");
159
160
161
162
163
164
      if (elem)
        elem.innerHTML = result;
    }
  } catch(e) {};
}

165
166
167
168
169
window.addEventListener("pageshow", function() {
  let evt = new CustomEvent("AboutTorLoad", { bubbles: true });
  document.dispatchEvent(evt);
});

170
171
// Donation banner constants
let gBannerAlternates = ["lp", "cd", "rd"],
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
    gBannerSuffixes = ["quote", "who", "speciality"];

// Change the font size of text in element by ratio.
let scaleFontBy = function (element, ratio) {
    let style = window.getComputedStyle(element),
        originalFontSize = parseFloat(style.fontSize),
        targetFontSize = originalFontSize * ratio;
    element.style.fontSize = targetFontSize + "px";
};

// Shrink the font size if the text in the given element is overflowing.
let fitTextInElement = function(element) {
  let style = window.getComputedStyle(element);
  if (style.whiteSpace === "nowrap") {
    // Look for horizontal overflow.
    let elementWidth = element.getBoundingClientRect().width,
        paddingWidth = parseFloat(style.paddingLeft) +
                       parseFloat(style.paddingRight),
        targetWidth = elementWidth - paddingWidth,
        textWidth = element.scrollWidth;
    // Compute the appropriate font size to make the text fit.
    let ratio = targetWidth / textWidth;
    scaleFontBy(element, ratio);
  } else {
    // Look for vertical overflow.
    let elementHeight = element.getBoundingClientRect().height,
        paddingHeight = parseFloat(style.paddingTop) +
                        parseFloat(style.paddingBottom),
        targetHeight = elementHeight - paddingHeight;
    // Wrapping causes somewhat difficult-to-predict overflow.
    // So shrink slightly and repeat.
    let ratio = 0;
    for (let i = 0; i < 100 && ratio < 1; ++i) {
      let textHeight = element.scrollHeight;
      ratio = targetHeight < textHeight ? 0.99 : 1;
      if (ratio < 1) {
        scaleFontBy(element, ratio);
      }
    }
  }
};

// Put text of the appropriate locale into donation banner elements.
let populateBannerText = function (suffix, alternate) {
  let text = gStringBundle.GetStringFromName("aboutTor.donationBanner." +
                                             alternate + "." + suffix),
      div = document.getElementById("donation-banner-" + suffix);
  div.innerHTML = text;
};
221
222
223
224

// This function takes care of the donation banner.
function setupDonationBanner() {
  try {
225
    // Only show banner for locales for which we have translations.
226
    let browserLocale = Services.prefs.getCharPref("general.useragent.locale");
227
228
    if (!["en", "de", "fa", "fr", "nl", "ru", "sv", "tr", "zh"]
           .some(code => browserLocale.startsWith(code))) {
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
      return;
    }
    // Only show banner until 2016 Jan 25.
    let now = new Date();
    let expiration = new Date(2016,0,26);
    if (now > expiration) {
      return;
    }
    // Only show banner 10 times.
    let showCountPref = "extensions.torbutton.donation_banner.shown_count";
    if (Services.prefs.prefHasUserValue(showCountPref)) {
      count = Services.prefs.getIntPref(showCountPref);
    } else {
      count = 0;
    }
    if (count >= 10) {
      return;
    }
    Services.prefs.setIntPref(showCountPref, count+1);

    // Decide which champion we are using.
    let alternate = gBannerAlternates[
                      Math.floor(Math.random() * gBannerAlternates.length)];
    // Show the champion.
    document.getElementById("donation-banner-image").src =
      "chrome://torbutton/content/aboutTor/donation-banner-" + alternate + ".jpg";
    // Populate banner with associated text.
    for (let suffix of gBannerSuffixes) {
      populateBannerText(suffix, alternate);
    }
  } catch (e) {
    // Something has gone wrong! Don't show the banner, and don't propagate
    // any errors that will interfere with other code.
    return;
  }
  // Now we can show the banner.
265
  document.getElementById("donation-banner").style.display = "block";
266
267
268
269
270
271
272
  for (let id of ["donation-banner-quote",
                  "donate-button",
                  "donation-banner-who",
                  "donation-banner-speciality",
                  "donation-banner-plea"]) {
    fitTextInElement(document.getElementById(id));
  }
273
}
274
275
276
277
]]>
</script>
</head>
<body dir="&locale.dir;" onload="onLoad();">
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298

  <div id="donation-banner" class="top">
    <a href="https://www.torproject.org/donate/donate-tbb">
      <div id="donation-banner-inner">
        <img id="donation-banner-image" width="700" />
        <div id="donation-banner-text">
          <div id="donation-banner-quote"></div>
          <div id="donation-banner-credit">
            <div id="donation-banner-who"></div>
            <div id="donation-banner-speciality"></div>
          </div>
        </div>
        <div id="donation-banner-plea">&aboutTor.donate.supportTor;</div>
      </div>
    </a>
    <a href="https://www.torproject.org/donate/donate-tbb">
      <div id="donate-button">&aboutTor.donate.donate;</div>
    </a>
  </div>

  <div id="torstatus" class="top">
299
  <div id="torstatus-version"/>
300
  <div id="torstatus-image"/>
301
  <div id="torstatus-on-container" class="hideIfTorOff torstatus-container">
302
    <h1>&aboutTor.success.label;</h1>
303
    <br/>
304
    <h3 class="hideIfTBBNeedsUpdate">&aboutTor.success3.label;</h3>
305
    <br/>
306
307
308
    <div style="margin-top: 20px;">
      <a id="testTorSettings" href="about:blank">&aboutTor.check.label;</a>
    </div>
309
  </div>
310
  <div id="torstatus-off-container" class="hideIfTorOn torstatus-container">
311
    <h1>&aboutTor.failure.label;</h1>
312
    <br/>
313
    <h2>&aboutTor.failure2.label;</h2>
314
    <br/>
315
316
317
318
319
320
321
322
323
    <h3>&aboutTor.failure3prefix.label;<a href="mailto:&aboutTor.failure3Link;"
>&aboutTor.failure3Link;</a>&aboutTor.failure3suffix.label;</h3>
  </div>
</div>
<div class="top">
  <div class="hideIfTorIsUpToDate">
    <h1 class="hideIfTorOff">&aboutTor.outOfDateTorOn.label;</h1>
    <h1 class="hideIfTorOn">&aboutTor.outOfDateTorOff.label;</h1>
    <h3 id="updatePrompt">&aboutTor.outOfDate2.label;</h3>
324
325
326
327
328

    <div id="toolbarIconArrowHead" class="arrow"/>
    <div id="toolbarIconArrowVertExtension" class="arrow"/>
    <div id="toolbarIconArrowBend" class="arrow"/>
    <div id="toolbarIconArrowHorzExtension" class="arrow"/>
329
330
331
332
  </div>
</div>

<div class="searchbox hideIfTorOff"> <!-- begin form based search -->
333
  <form action="&aboutTor.searchDCPost.link;" method="post">
334
335
336
337
338
339
340
  <div id="sxw">
    <div id="sbutton">
      <input name="b" id="sb" value="" title="&aboutTor.search.label;"
             alt="&aboutTor.search.label;" type="submit"/>
    </div>
    <input name="q" autocomplete="off" id="sx" type="text"/>
  </div>
341
  <h4 id="searchProviderInfo" />
342
343
344
345
346
347
  </form>
</div>

<div class="hideIfTorOn" style="height:100px"/>

<div id="middle" class="hideIfTorOff">
348
349
350
351
352
353
  <div class="bubbleRow">
    <div class="bubble">
      <h1>&aboutTor.whatnextQuestion.label;</h1>
      <p>&aboutTor.whatnextAnswer.label;</p>
      <a class="tips" href="&aboutTor.whatnext.link;">&aboutTor.whatnext.label;</a>
    </div>
354

355
356
357
358
359
360
361
362
363
    <div class="bubble">
      <h1>&aboutTor.helpInfo1.label;</h1>
      <p>&aboutTor.helpInfo2.label;</p>
      <ul>
        <li><a href="&aboutTor.helpInfo3.link;">&aboutTor.helpInfo3.label;</a></li>
        <li><a href="&aboutTor.helpInfo4.link;">&aboutTor.helpInfo4.label;</a></li>
        <li><a href="&aboutTor.helpInfo5.link;">&aboutTor.helpInfo5.label;</a></li>
      </ul>
    </div>
364
365
366
367
368
369
370
371
372
373
  </div>
</div> <!-- middle -->

<div id="bottom">
  <p>&aboutTor.footer.label;
<a href="&aboutTor.learnMore.link;">&aboutTor.learnMore.label;</a></p>
</div>

</body>
</html>