src/download.jst
author Edmund Wong <ewong@pw-wspx.org>
Tue, 14 Nov 2017 17:02:33 +0800
changeset 1288 358a27aa17a1802258a1aa8df0ba20baff2cd6bb
parent 955 1650a5e8983ff653639d5d2bce4b757372141b46
child 1307 56e8d1a32f351735a50fc76ec0ef6af07cb1cb10
permissions -rw-r--r--
Bug 1313962 - Update http://www.seamonkey-project.org/dev/get-involved to point to #seamonkey on irc. r=IanN

[%- wrap = false -%]
var gPlatform = PLATFORM_WINDOWS;

var PLATFORM_OTHER    = 0;
var PLATFORM_WINDOWS  = 1;
var PLATFORM_LINUX    = 2;
var PLATFORM_MACOSX   = 3;
var PLATFORM_MAC      = 4;

if (navigator.platform.indexOf("Win32") != -1)
  gPlatform = PLATFORM_WINDOWS;
else if (navigator.platform.indexOf("Linux") != -1)
  gPlatform = PLATFORM_LINUX;
else if (navigator.userAgent.indexOf("Mac OS X") != -1)
  gPlatform = PLATFORM_MACOSX;
else if (navigator.userAgent.indexOf("MSIE 5.2") != -1)
  gPlatform = PLATFORM_MACOSX;
else if (navigator.platform.indexOf("Mac") != -1)
  gPlatform = PLATFORM_MAC;
else
  gPlatform = PLATFORM_OTHER;

// "" for a version means it should be "Not Yet Available" on all.html,
// null means it should not be listed
// A region code of "-" means that no region code should be used.
// Last JS-based revision on mozilla.com was
// http://viewvc.svn.mozilla.org/vc/projects/mozilla.com/trunk/js/download.js?revision=5420&view=markup
var gLanguages = {
  "af":  { "za": { version: null,      betaversion: null,     name: "Afrikaans",                localName: "Afrikaans" } },
  "ast": { "es": { version: null,      betaversion: null,     name: "Asturian",                 localName: "Asturianu" } },
  "ar":  { "-":  { version: null,      betaversion: null,     name: "Arabic",                   localName: "\u0639\u0631\u0628\u064A" } },
  "be":  { "-":  { version: "[% releaseversion %]",   betaversion: "[% betaversion %]",  name: "Belarusian",               localName: "\u0411\u0435\u043B\u0430\u0440\u0443\u0441\u043A\u0430\u044F" } },
  "bg":  { "-":  { version: null,      betaversion: null,     name: "Bulgarian",                localName: "\u0411\u044A\u043B\u0433\u0430\u0440\u0441\u043A\u0438" } },
  "br":  { "fr": { version: null,      betaversion: null,     name: "Breton",                   localName: "Brezhoneg" } },
  "ca":  { "-":  { version: "[% releaseversion %]",   betaversion: "[% betaversion %]",  name: "Catalan",                  localName: "Catal\u00E0" } },
  "cs":  { "-":  { version: "[% releaseversion %]",   betaversion: "[% betaversion %]",  name: "Czech",                    localName: "\u010Ce\u0161tina" } },
  "cy":  { "gb": { version: null,      betaversion: null,     name: "Welsh",                    localName: "Cymraeg" } },
  "da":  { "-":  { version: null,      betaversion: null,     name: "Danish",                   localName: "Dansk" } },
  "de":  { "-":  { version: "[% releaseversion %]",   betaversion: "[% betaversion %]",  name: "German",                   localName: "Deutsch" } },
  "el":  { "-":  { version: null,      betaversion: null,     name: "Greek",                    localName: "\u0395\u03BB\u03BB\u03B7\u03BD\u03B9\u03BA\u03AE" } },
  "en":  { "us": { version: "[% releaseversion %]",   betaversion: "[% betaversion %]",  name: "English",                  localName: "English" },
           "gb": { version: "[% releaseversion %]",   betaversion: "[% betaversion %]",  name: "English (British)",        localName: "English (British)" } },
  "es":  { "ar": { version: "[% releaseversion %]",   betaversion: "[% betaversion %]",  name: "Spanish (Latin American)", localName: "Espa\u00F1ol (de Am\u00E9rica)" },
           "es": { version: "[% releaseversion %]",   betaversion: "[% betaversion %]",  name: "Spanish (Spain)",          localName: "Espa\u00F1ol (de Espa\u00F1a)" } },
  "eu":  { "-":  { version: null,      betaversion: null,     name: "Basque",                   localName: "Euskara" } },
  "fi":  { "-":  { version: "[% releaseversion %]",   betaversion: "[% betaversion %]",  name: "Finnish",                  localName: "Suomi" } },
  "fr":  { "-":  { version: "[% releaseversion %]",   betaversion: "[% betaversion %]",  name: "French",                   localName: "Fran\u00e7ais" } },
  "fy":  { "nl": { version: null,      betaversion: null,     name: "Frisian",                  localName: "Frysk" } },
  "ga":  { "ie": { version: null,      betaversion: null,     name: "Irish",                    localName: "Gaeilge" } },
  "gl":  { "-":  { version: "[% releaseversion %]",   betaversion: "[% betaversion %]",  name: "Galician",                 localName: "Galego" } },
  "gu":  { "in": { version: null,      betaversion: null,     name: "Gujarati",                 localName: "\u0A97\u0AC1\u0A9C\u0AB0\u0ABE\u0AA4\u0AC0" } },
  "he":  { "-":  { version: null,      betaversion: null,     name: "Hebrew",                   localName: "\u05E2\u05D1\u05E8\u05D9\u05EA" } },
  "hu":  { "-":  { version: "[% releaseversion %]",   betaversion: "[% betaversion %]",  name: "Hungarian",                localName: "Magyar" } },
  "hy":  { "am": { version: null,      betaversion: null,     name: "Armenian",                 localName: "\u0540\u0561\u0575\u0565\u0580\u0565\u0576" } },
  "it":  { "-":  { version: "[% releaseversion %]",   betaversion: "[% betaversion %]",  name: "Italian",                  localName: "Italiano" } },
  "ja":  { "-":  { version: "[% releaseversion %]",   betaversion: "[% betaversion %]",  name: "Japanese",                 localName: "\u65e5\u672c\u8a9e" } },
  "ka":  { "-":  { version: null,      betaversion: null,     name: "Georgian",                 localName: "\u10e5\u10d0\u10e0\u10d7\u10e3\u10da\u10d8" } },
  "ko":  { "-":  { version: null,      betaversion: null,     name: "Korean",                   localName: "\uD55C\uAD6D\uC5B4" } },
  "lt":  { "-":  { version: "[% releaseversion %]",   betaversion: "[% betaversion %]",  name: "Lithuanian",               localName: "Lietuvi\u0173" } },
  "mk":  { "-":  { version: null,      betaversion: null,     name: "Macedonian",               localName: "\u041C\u0430\u043A\u0435\u0434\u043E\u043D\u0441\u043A\u0438" } },
  "mn":  { "-":  { version: null,      betaversion: null,     name: "Mongolian",                localName: "\u041C\u043E\u043D\u0433\u043E\u043B" } },
  "nb":  { "no": { version: "[% releaseversion %]",   betaversion: "[% betaversion %]",  name: "Norwegian (Bokm\u00E5l)",  localName: "Norsk bokm\u00E5l" } },
  "nn":  { "no": { version: null,      betaversion: null,     name: "Norwegian (Nynorsk)",      localName: "Norsk nynorsk" } },
  "nl":  { "-":  { version: "[% releaseversion %]",   betaversion: "[% betaversion %]",  name: "Dutch",                    localName: "Nederlands" } },
  "pa":  { "in": { version: null,      betaversion: null,     name: "Punjabi",                  localName: "\u0A2A\u0A70\u0A1C\u0A3E\u0A2C\u0A40" } },
  "pl":  { "-":  { version: "[% releaseversion %]",   betaversion: "[% betaversion %]",  name: "Polish",                   localName: "Polski" } },
  "pt":  { "br": { version: null,      betaversion: null,     name: "Portuguese (Brazilian)",   localName: "Portugu\u00EAs (do Brasil)" },
           "pt": { version: "[% releaseversion %]",   betaversion: "[% betaversion %]",  name: "Portuguese (Portugal)",    localName: "Portugu\u00EAs (Europeu)" } },
  "ro":  { "-":  { version: null,      betaversion: null,     name: "Romanian",                 localName: "Rom\u00E2n\u0103" } },
  "ru":  { "-":  { version: "[% releaseversion %]",   betaversion: "[% betaversion %]",  name: "Russian",                  localName: "\u0420\u0443\u0441\u0441\u043A\u0438\u0439" } },
  "sk":  { "-":  { version: "[% releaseversion %]",   betaversion: "[% betaversion %]",  name: "Slovak",                   localName: "Slovensk\u00FD" } },
  "sl":  { "-":  { version: null,      betaversion: null,     name: "Slovenian",                localName: "Slovensko" } },
  "sq":  { "-":  { version: null,      betaversion: null,     name: "Albanian",                 localName: "Shqipe" } },
  "sv":  { "se": { version: "[% releaseversion %]",   betaversion: "[% betaversion %]",  name: "Swedish",                  localName: "Svenska" } },
  "tr":  { "-":  { version: "[% releaseversion %]",   betaversion: "[% betaversion %]",  name: "Turkish",                  localName: "T\u00FCrk\u00E7e" } },
  "uk":  { "-":  { version: "[% releaseversion %]",   betaversion: "[% betaversion %]",  name: "Ukrainian",                localName: "\u0423\u043A\u0440\u0430\u0457\u043D\u0441\u044C\u043A\u0430" } },
  "zh":  { "cn": { version: "[% releaseversion %]",   betaversion: "[% betaversion %]",  name: "Chinese (Simplified)",     localName: "\u4E2D\u6587 (\u7B80\u4F53)" },
           "tw": { version: "[% releaseversion %]",   betaversion: "[% betaversion %]",  name: "Chinese (Traditional)",    localName: "\u6b63\u9ad4\u4e2d\u6587 (\u7E41\u9AD4)" } }
};

function LanguageID(aAB, aCD, aBuild)
{
  if (aCD == "-")
    this.abCD = aAB;
  else
    this.abCD = aAB + "-" + aCD.toUpperCase();
  for (var prop in aBuild)
    this[prop] = aBuild[prop]
}

function buildValidForPlatform(aLangID, aPlatform)
{
  if ((aLangID.abCD == "gu-IN" || aLangID.abCD == "pa-IN") &&
      aPlatform == PLATFORM_MACOSX)
    return false;

  return true;
}

function getLanguageID(betaversion)
{
  var verName = "version";
  if (betaversion)
    verName = "betaversion";

  var language = "";
  if (navigator.language)
    language = navigator.language;
  else if (navigator.userLanguage)
    language = navigator.userLanguage;
  else if (navigator.systemLanguage)
    language = navigator.systemLanguage;

  // Convert "en" to "en-US" as well since en-US build is the canonical
  // translation, and thus better tested.
  if (language == "" || language == "en")
    language = "en-US";

  // Konqueror uses '_' where other browsers use '-'.
  if (language.indexOf("_") != -1)
    language = language.split("_").join("-");

  language = language.toLowerCase();
  var languageCode = language.split("-")[0];
  var regionCode = language.split("-")[1];

  // String comparison actually works for version numbers.
  var currentVersion = gLanguages["en"]["us"][verName];
  var bestVersion = "";
  var id = null;

  if (gLanguages[languageCode]) {
    var region;
    var build;
    var langid;

    for (region in gLanguages[languageCode]) {
      build = gLanguages[languageCode][region];
      if (build[verName] && regionCode == region) {
        langid = new LanguageID(languageCode, regionCode, build);
        if (buildValidForPlatform(langid, gPlatform)) {
          id = langid;
          bestVersion = build[verName];
        }
      }
    }

    // We have a localized build for this language, but not this region.
    // use the first available region with the highest version

    if (bestVersion != currentVersion) {
      var bestRegionVersion = "";
      for (region in gLanguages[languageCode]) {
        build = gLanguages[languageCode][region];
        if (build[verName] > bestVersion) {
          langid = new LanguageID(languageCode, region, build);
          if (buildValidForPlatform(langid, gPlatform) &&
              (build[verName] > bestRegionVersion)) {
            id = langid;
            bestRegionVersion = build[verName];
          }
        }
      }
      if (bestRegionVersion > bestVersion)
        bestVersion = bestRegionVersion;
    }
  }
  if (bestVersion != currentVersion) {
    id = new LanguageID("en", "us", gLanguages["en"]["us"]);
  }

  return id;
}

function highlightDownload(aIdBase, betaversion)
{
  if (gPlatform == PLATFORM_WINDOWS) {
    document.getElementById(aIdBase + "-win").className = "main";
    document.getElementById(aIdBase + "-linux").style.display = "none";
    document.getElementById(aIdBase + "-mac").style.display = "none";
  }
  else if (gPlatform == PLATFORM_LINUX) {
    document.getElementById(aIdBase + "-win").style.display = "none";
    document.getElementById(aIdBase + "-linux").className = "main";
    document.getElementById(aIdBase + "-mac").style.display = "none";
  }
  else if (gPlatform == PLATFORM_MACOSX) {
    document.getElementById(aIdBase + "-win").style.display = "none";
    document.getElementById(aIdBase + "-linux").style.display = "none";
    document.getElementById(aIdBase + "-mac").className = "main";
  }
  else {
    document.getElementById(aIdBase + "-win").style.display = "none";
    document.getElementById(aIdBase + "-linux").style.display = "none";
    document.getElementById(aIdBase + "-mac").style.display = "none";
    document.getElementById(aIdBase + "-other").className = "main";
  }

  // see if we need to change download box for localized version
  var languageID = getLanguageID(betaversion);
  if (languageID.abCD != "en-US") {
    // Japanese for Mac needs special rules
    var mac_abCD = languageID.abCD;
    if (mac_abCD == "ja-JP")
        mac_abCD = "ja-JPM";
    if (mac_abCD == "ja")
        mac_abCD = "ja-JP-mac";

    // download URLs - we only support bouncer URLs here!
    document.getElementById(aIdBase + "-win-link").href =
      document.getElementById(aIdBase + "-win-link").href.replace(/lang=en-US/, "lang=" + languageID.abCD);
    document.getElementById(aIdBase + "-linux-link").href =
      document.getElementById(aIdBase + "-linux-link").href.replace(/lang=en-US/, "lang=" + languageID.abCD);
    document.getElementById(aIdBase + "-mac-link").href =
      document.getElementById(aIdBase + "-mac-link").href.replace(/lang=en-US/, "lang=" + languageID.abCD);

    // download language name
    document.getElementById(aIdBase + "-win-lang").firstChild.data = languageID.name;
    document.getElementById(aIdBase + "-linux-lang").firstChild.data = languageID.name;
    document.getElementById(aIdBase + "-mac-lang").firstChild.data = languageID.name;
  }
}

function isSupportedOS(ua) {
  var winVer = ua.match(/Windows( NT)? ([0-9.]+);/);
  if (!winVer) {
   return true; // not Windows, assume supported
  }
  if (winVer[1] == " NT") {
   return winVer[2] >= 5.1; // require WinXP (assume SP2 or better)
  }
  return false; // Win9x and WinCE are not supported
}

function displayElement(el, show) {
  document.getElementById(el).style.display = show ? "block" : "none";
}