Subversion Repositories LCARS

Rev

Rev 227 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

1
var klingon_texts = null;

var klingon_map = {
  "A": "\uF8D0",
  "B": "\uF8D1",
  "CH": "\uF8D2",
  "D": "\uF8D3",
  "E": "\uF8D4",
  "GH": "\uF8D5",
  "H": "\uF8D6",
  "I": "\uF8D7",
  "J": "\uF8D8",
  "L": "\uF8D9",
  "M": "\uF8DA",
  "N": "\uF8DB",
  "NG": "\uF8DC",
  "O": "\uF8DD",
  "P": "\uF8DE",
  "Q": "\uF8DF",
  "QH": "\uF8E0",
  "R": "\uF8E1",
  "S": "\uF8E2",
  "T": "\uF8E3",
  "TLH": "\uF8E4",
  "U": "\uF8E5",
  "V": "\uF8E6",
  "W": "\uF8E7",
  "Y": "\uF8E8",
  "'": "\uF8E9",
  "0": "\uF8F0",
  "1": "\uF8F1",
  "2": "\uF8F2",
  "3": "\uF8F3",
  "4": "\uF8F4",
  "5": "\uF8F5",
  "6": "\uF8F6",
  "7": "\uF8F7",
  "8": "\uF8F8",
  "9": "\uF8F9",
  ",": "\uF8FD",
  ".": "\uF8FE",

  /* mummification glyph, symbol of the empire */
  "Δ": "\uF8FF"
};

var rxKlingon = jsx.object.getKeys(klingon_map);
rxKlingon.sort(function (a, b) { return b.length - a.length; });
rxKlingon = new RegExp(
  rxKlingon.filter(function (e) { return e.length > 1; }).join("|")
    + "|[" + rxKlingon.filter(function (e) { return e.length === 1; }). join("") + "]",
  "ig");

//jsx.object.flip = function (obj) {
//  var flipped = jsx.object.inheritFrom(obj);
//  var keys = jsx.object.getKeys(obj);
//
//  for (var i = 0, len = keys.length; i < len; ++i)
//  {
//    var key = keys[i];
//    var value = obj[key];
//    if (typeof value != "function")
//    {
//      flipped[value] = key;
//    }
//  }
//
//  return flipped;
//};

var media_caption;

function pIqaD (button)
{
  klingon_texts = jsx.dom.xpath.evaluate(
    './/*[@class = "text" and (@lang = "' + LANG_KLINGON
      + '" or parent::*[@lang = "' + LANG_KLINGON + '"])]',
    document.body);

  if (!klingon_texts)
  {
    return;
  }

  var previous_parent = null;

  for (var i = 0, len = klingon_texts.length; i < len; ++i)
  {
    var text = klingon_texts[i];

    text.style.fontFamily = "pIqaD, Constructium, Code2000, serif";
    text.style.fontSize = "90%";

    if (!text.hasAttribute("data-html"))
    {
      text.setAttribute("data-html", text.innerHTML);

      if (!text.title)
      {
        text.title = text.textContent;
      }
    }

    var text_nodes = jsx.dom.xpath.evaluate(
      './/text()[parent::*[not(@lang) or (@lang = "' + LANG_KLINGON + '")]]',
      text);

    for (var j = 0, len2 = text_nodes.length; j < len2; ++j)
    {
      var text_node = text_nodes[j];

      text_node.nodeValue = text_node.nodeValue.toUpperCase().replace(
        rxKlingon,
        function (s) {
          return jsx.object.getProperty(klingon_map, s.replace(/\s+/g, " "), s);
        });
    }

    text.parentNode.lang = "tlh-pIqaD";
  }

  if (button && lcars.language == LANG_KLINGON)
  {
    button.setAttribute("data-caption", button.firstChild.textContent);
    button.firstChild.textContent = "Latin";
    button.firstChild.style.fontFamily = "";
    button.firstChild.style.fontSize = "";
  }
}

function klingonLatinScript (button)
{
  for (var i = 0, len = klingon_texts.length; i < len; ++i)
  {
    var text = klingon_texts[i];

    text.style.fontFamily = "";
    text.style.fontSize = "";
    text.innerHTML = text.getAttribute('data-html');
    text.parentNode.lang = "tlh-Latn";
  }

  if (lcars.language == LANG_KLINGON)
  {
    button.firstChild.textContent = button.getAttribute("data-caption");
  }
}