// ==UserScript==
// @name           ThinnerBox
// @namespace      http://coop.deadsquid.com/userscripts
// @description    Shrinks buildbot, letting you hover instead of scrolling to see information.  If you want to click a link in a popup, click to freeze the popup in place.
// @include        http://*/waterfall*
// @author         Chris Cooper - http://coop.deadsquid.com/
// @inspiration    Jesse Ruderman - http://www.squarefree.com/
// ==/UserScript==

// Version history:
// 2008-12-02     Initial release
// 2009-05-15     Add support for newer builders

// Type-of-build key:
//
//   T    talos
//   B    build
//   N    nightly
//   U    unit
//   L    leak
//   P    perf (gone?)
//   D    debug+leak (gone?)
//   X    xulrunner
//   CC   code coverage
//   l10n l10n
//   BU   blocklist update
//   V    valgrind
//   -   other

// Activity key:
//
//   I  Idle
//   W  Waiting
//   B  Building


// Thinnerbox only modifies buildbot pages with at least 
// this many boxes reporting.
const MIN_COLUMNS = 3;

var whitespace = " \t\n\r";

var i = 0;
var contents = [];
var builderName = [];
var activityName = [];

var tables = document.getElementsByTagName("table");
var gTable = tables.length && tables[tables.length - 1];

if (gTable && gTable.rows[0] && gTable.rows[0].cells.length >= MIN_COLUMNS + 2 && gTable.rows[0].className == "LastBuild") {

  var gTableP = gTable.parentNode;
  var gTableB = gTable.previousSibling;
  gTableP.removeChild(gTable);
  
  for (rowIndex = 0; row = gTable.rows[rowIndex]; ++rowIndex) {
    for (cellIndex = 0; cell = row.cells[cellIndex]; ++cellIndex) {
      var con;

      // First column (time).
      if (cellIndex == 0 && cell.className == "Time") {
        continue;
      }

      // Second column (commits).
      // Highlight cells where there is a commit, to make them easy to see even
      // with a small font size.
      if (rowIndex > 1 && cell.className == " Change") {
        continue;
      }

      if (isWhitespace(cell.textContent)) {
        continue;
      }
       
      // Remove the contents of the cell, storing them away for on-hover viewing.
      con = spiritAway(cell);
      if (!con) {
        continue;
      }
      
      // Second row (activity names)
      if (rowIndex == 1 && cellIndex >= 1) {
        activityName[cellIndex] = con.textContent;
        addActivityInfo(cell, con.textContent);
      }
  
      // Third row (builder names)
      if (rowIndex == 2 && cellIndex >= 2) {
        builderName[cellIndex] = con.textContent;
        addBuilderInfo(cell, con.textContent);
      }
  
    }
  }


  gTable.setAttribute("border", "0");
  gTable.setAttribute("id", "waterfallTable");
  addStyle("#waterfallTable > tbody > tr > td { min-width: 18px; font-size: 80%; }");
  
  // Without this, the popup that appears when you click a commiters's name gets scrollbars.
  // I don't know why.
  addStyle("#popup.who { width: 1000px; height: 1000px;}"); 
  
  gTableP.insertBefore(gTable, gTableB);
  
  createPopup();
  
  window.addEventListener("mousemove", function (ev)
  {
    if (popupLocked)
      return;
      
    var spiritPopup = document.getElementById("spiritPopup");
  
    var t = ev.target;
    
    // Find the closest ancestor to the target that is a spirited-away table cell.
    // Go all the way up to |document| because some events are naturally fired there
    // and we don't want to call hasAttribute on it.
    while (t != document && !t.hasAttribute("ix")) {
      t = t.parentNode;
    }
  
    if (t != document && t.getAttribute("bgcolor") != "#a5a5a5" /*gray(empty)*/) {
      spiritPopup.style.display = "block";
      spiritPopup.style.left = (ev.pageX + 10) + "px";
      spiritPopup.style.top = ev.pageY + "px";
      if (currentCell != t) {
        currentCell = t;
        while (spiritPopup.firstChild)
          spiritPopup.removeChild(spiritPopup.firstChild);
        spiritPopup.appendChild(contents[currentCell.getAttribute("ix")]);
      }
    } else {
      hidePopup();
    }
  },
  false);
  
  window.addEventListener("click", function (ev)
  {
    var spiritPopup = document.getElementById("spiritPopup");

    // Ignore modified clicks.
    if (ev.shiftKey || ev.metaKey || ev.altKey || ev.ctrlKey)
      return;
  
    // Ignore clicks on links.
    var t = ev.target;
    while (t != document) {
      if (t.tagName.toUpperCase() == "A")
        return;
      t = t.parentNode;
    }
  
    if (popupLocked && window.getSelection() == "") {
      hidePopup();
    } else if (currentCell) {
      popupLocked = true;
      spiritPopup.style.opac
      ity = "1.0";
    }
  },
  false);
}




function addStyle(rules)
{
  var sheet = document.createElement("style");
  sheet.textContent = rules;
  document.body.appendChild(sheet);
  return sheet;
}



function createPopup()
{
  // spiritPopup is tracked by ID rather than by reference because the
  // Camino Tinderbox page has a habit of setting document.body.innerHTML.
  
  var spiritPopup = document.createElement("div");
  spiritPopup.style.position = "absolute";
  spiritPopup.style.border = "1px solid black";
  spiritPopup.style.padding = "5px";
  spiritPopup.style.background = "white";
  spiritPopup.style.textAlign = "center";
  spiritPopup.style.fontSize = "80%";
  spiritPopup.setAttribute("id", "spiritPopup");
  var currentCell = null;
  var popupLocked = false;
  document.body.appendChild(spiritPopup);
  hidePopup();
}

function hidePopup()
{
  var spiritPopup = document.getElementById("spiritPopup");

  spiritPopup.style.display = "none";
  spiritPopup.style.opacity = "0.8";
  currentCell = null;
  popupLocked = false;
}


function spiritAway(cell)
{
  var con = document.createElement("div");
  while(cell.firstChild)
    con.appendChild(cell.firstChild);
  cell.setAttribute("ix", "" + ++i);
  contents[i] = con; 
  return con;
}


function addBuilderInfo(cell, box)
{
  // These are white-background images representing operating systems.
  const WINDOWS_ICON = "data:image/png,%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00%12%00%00%00%12%08%02%00%00%00%D9%AC%19%00%00%00%00%09pHYs%00%00%0B%12%00%00%0B%12%01%D2%DD~%FC%00%00%00%07tIME%07%D3%0A%12%0A%26%26%F4%9A%C0%9B%00%00%00%1DtEXtComment%00Created%20with%20The%20GIMP%EFd%25n%00%00%02%8CIDATx%DA%85%93%C9O%14Q%10%C6%AB%DE%EB~%FD%BA%9Ba%98%01d%948%10D%11Q%90%03%1E%5C%22%C6%C4Dc%8CW%FF%00o%5E%FCo%BC%7B%F3%E2%C1%8B%F1%60b%8C%26n1F%08%06%5C%06%C7%11%07%9C%8DYz%7B%EF%95%07%5B%A2q%FBn%95%D4%2F_%A5%EA%2B%24%22%F8Ud%0C%10!%E7%F0wY%3F%17%BA%B2%8Aa%C3%B4%BFR70b%80%8A%D3%CE%F0%1Ed%F8%2F%CC%C4%11%DD%BF%81%BD2%0FZ%B0Q%EF5%A09y%DC%BB%7C%D5%1D%DF%2F%85%FC%3B%B6Y%E2%ED%0F%A8%DB%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A5%CFP0%A5)%D4C%F6%E8%DCN%1B%FE%FE8%00%60%8Cn%94%97%83%F2%BD%3EYa%BE!%9E%D7b%3E7vi%C7%ED%CFX%FAG*%89z%0D%20m9%FD%C2%F1%00%F1%3Fn%FF%D57%2C%8F79%CE'%10%5D%00%00%00%00IEND%AEB%60%82"
  const LINUX_ICON = "data:image/gif,GIF89a%12%00%12%00%F7%00%00%A6%A4%A5%1C%1B%1CJIJvuvgfgdcd%98%97%98%90%8F%90%83%82%83%D7%D5%D8%19%18%1AHGI%AB%AA%AE%00%00%01%08%08%0D%05%05%07%1E%1E%22%7F%7F%88%10%10%11aaf%1A%1A%1BJJL%2F%2F0%ED%ED%F1%EA%EA%EE%E1%E1%E5%E7%E7%EA%5B%5B%5CVVW%F8%F8%F9%F7%F7%F8%EE%EE%EF%ED%ED%EE%D2%D2%D3%95%95%96%D2%D3%D8uvz%ED%EF%F6X%5Bd569%3E%3FB%F0%F3%FB%80%81%84%F7%F8%FB%F6%F8%FD%F3%F6%FD%00%01%03%1E%1F!%83%84%86%FB%FC%FE%F6%F7%F8%FC%FF%FF%FD%FF%FF%FC%FD%FD%E8%E9%E9%FF%FF%FB%FE%FE%FA%FA%FA%F6%7B%7By%F8%F8%F5CCB%D5%D5%D3wwvbba%FE%FE%FD%FD%FD%FC%A0%A0%9F%F7%F6%F0%DB%BA%20%9D%88)%FF%CA%0D%FF%CA%0E%E5%B9%0D%FA%BF%02%87h%03%F3%B8%06%E9%B3%06%C2%94%06%FF%C6%08%F4%BA%08%F8%BE%09%F9%C0%0A%FC%C2%0D%F9%C0%0E%D4%AB%2C%E4%CC~%7FrG%9D%97%83%D9%9E%00%F1%B5%01%FE%C1%0B%BD%8F%09%E4%AD%12%E0%AB%1B%C6%98%1A%9E%7B%19%D8%AF9%D8%AE%3D%D6%B5X%95%8Bo%C8%90%01%A9y%03%AB%7D%04%C6%90%07%AE%84%18%B8%8D%23%CE%A2.%DB%BAc%24%20%16%B9%A8%7D%90e%04%93i%0F%A8%86%3A%B5%92G6%2F%1F%85%5C%08%C1%AB%80%E0%D0%B0%BF%B6%A4%EE%E5%D2%ED%E9%E1%13%0E%05%C0%AA%83%0C%09%04%1A%17%12%EB%E4%D8%E7%E1%D7%80vg%A0%95%85%BF%B8%AEMJF%84%80%7B%AA%A5%9F%AD%A3%98%EB%E6%E1200%19%18%18%B8%B5%B5HGGrqqkjj%FF%FE%FE%FD%FC%FC%FC%FB%FB%EB%EA%EA%E7%E6%E6%E1%E0%E0%C7%C6%C6%FF%FF%FF%FE%FE%FE%FD%FD%FD%FC%FC%FC%FA%FA%FA%F8%F8%F8%F6%F6%F6%D4%D4%D4%D3%D3%D3%D1%D1%D1%C8%C8%C8%BF%BF%BFjjj...%2C%2C%2C%18%18%18%08%08%08%07%07%07%00%00%00%FF%FF%FF%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00!%F9%04%01%00%00%A7%00%2C%00%00%00%00%12%00%12%00%00%08%FF%00%2B%09%14H%E9%92%08%1E%058Q%A24%B0!AJ%07L%99*%25j%D2B%87%03%17r%90%E0%C0%82)F%171V%A2%84%09%C6%06A%11%20%08p%C4P%24%25K%83%BE%10)%C2%06E%A6%96%18%17%FE%D9%82%84%8A%9C%13%92p%3A%A4%04%89%84%1D%3D%86T%90B%10%B2%E1BPBh%B4%A0%B4%E9%C1(%8BBG~%A2%D0%E3F%10M%91%08%98%0A%15I%E8%C2%1F%3E(%05%01%B2%B0%13%22S%00%9AR%0A%F1%C2%13%A5%1D%8FF%82P%60jQ%C8%85%06%F8h%A04%E4%92%25J%1F%02%B8%98%10%D2%D2%9D5M%AE%AC%C8q%A9F%A3*y%F6%8Ca%C1%90R%9F.O%8C(1!%03%07%25%0Fa%DC%98%01%93%A1%B3%1F.Q%A60%B1%12c!%034Z%A4%24%11%83aa%1D%2CY%A08Q3%40G%85%06e%8E%2C%F1%D2%E6%C2B%3Ct%E2%A493%E7%D0%82%0A%8A%DE%90%81%93(EKJ3J%24%0C(D%C8%C6%C2%0E%81%00%8D%08%19%10%00%3B"
  const MAC_ICON = "data:image/png,%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00%12%00%00%00%12%08%03%00%00%00a%10~e%00%00%00%01sRGB%00%AE%CE%1C%E9%00%00%00%04gAMA%00%00%B1%8F%0B%FCa%05%00%00%00%20cHRM%00%00z%26%00%00%80%84%00%00%FA%00%00%00%80%E8%00%00u0%00%00%EA%60%00%00%3A%98%00%00%17p%9C%BAQ%3C%00%00%03%00PLTE%A4%D1%E8%CB%E5%F2%40%A0%CFk%B5%DA%88%C4%E1%F1%F8%FC%E4%F1%F8%FF%FF%FF%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%F1%AA%BAu%00%00%00vIDAT(Sm%8FQ%12%C4%20%08C1%11%B9%FF%8D%1BP%DC%9Di%FDP%7C%84%18-%5E%CBD%7Cx%2C%8F%11%A1%22%A2%90%01S%08%B0u%90%1A%C8%9A%D2%5D%E4%98%9A%CA%89%8BJ%C64%FA!%C9%EC%88%CA%BEZ%60%A7i%14_%08%FB%BD%9D%AB%CE%C1%9E%3C%C8%A9%A4G%D6Yt%25%FE%07%25%8AX%D8%FD%BD%B3%0E%A2%C2f-%E7%FC%DE%24%CB%EE%E6%EA%A0%9F%E8%01%ED%13%07w%05Qp%D5%00%00%00%00IEND%AEB%60%82";
   const ANDROID_ICON = "data:image/x-icon;base64,AAABAAEAEBAQAAEABAAoAQAAFgAAACgAAAAQAAAAIAAAAAEABAAAAAAAwAAAABMLAAATCwAAEAAAAAAAAADz+/kARcqqADnGpAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMzMyIzIjMzMzMzIjMiMzMzMzMiMyIzMzMzIiIiIiIzMzMiIiIiIjMyIyIiIiIiMiIjIiIiIiIyIiMiIiIiIjIiIyIiIiIiMiIjIiIiIiIyIzMzMzMzMzMzMyIiIiIiMzMzIiIiIiIzMzMyMiIjIzMzMzMhIiIDMzMzMjMzMyMzP5n+Ai+Z8AAPmfAADgBwAA4AfkIiAEAAAgBAAAIAQAACAEAMAgBLnI//8AAOAHAADgB+Qi9C8AAPgPAAD37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l+ThrWgZf6b8C8/UXAeIuJAAAACXBIWXMAAAsTAAALEwEAmpwYAAAB3ElEQVQ4EZ1Ty27TQBQ941cSJ5VScFOqQhaELe0C9vwGH9A/4Tf4JKIuQAIplaIEUBYOedTYbjy2p/cMGClCqpRe6XrsmXsec2esAChJT9JIHhLElcqYQ3H7GmR5BgRXQNG44NxDQUWrLuNHAfnvTyL/Q3T2Bqcv32HYn+O4e4qfvRsUcQX9XaoDAxqlW+Z8PsdyuUQcx7+FQLuedyyrd/lt/M3/kWyw6aTYBiuY3EGdGlSpEGltwa7r0p32PK8jo2tt10ahyDb+1y/X3sXFJTovQjzRA7ihB3Uk1QKuqgqz2Qzj8Rij0Qh1XZPIkMAuQjnohEcYDE5wfv7cFjiOY89GjMP3feR5jlarRcgfjIyWgGzMPEtAkFLK2uUcv5PbpNkz2u02yrJsHFgCxUJajKII0+kUq9XqXwEJttstJpOJBff7fbtGjISiA10UhbVH9vV6jcViYZVZwa7T9nA4tMok3O12IMaBo3meZ2EYfu52u0+F1UiXZQf7V4EkfxVJaIREpWn6K8uy19IlLEUhCYKAgqUUym72g3Oy1mTJWmKI9YRQ93q9jF2WsA++PBAuj1W2kBFr/wWx/EoAbyW15L7//5l4lSn0SQhuWEySR/1RbFbjgL1gHhK16Nb3HFIYnoymVOgAAAAASUVORK5CYII%3D";

  // If you want alpha-transparent images, try:
  // http://www.microsoft.com/windows/templates/favicon.ico
  // http://www.kernel.org/favicon.ico
  // But alpha-transparent images don't look great against the harsh green/yellow/red on Tinderbox.

  var icon = null;
  if (box.substr(0, 5) == "WINNT" || box.indexOf("win32") != -1)
    icon = WINDOWS_ICON;
  if (box.substr(0, 4) == "OS X" || box.indexOf("macosx") != -1 || box.substr(0, 4) == "OS X")
    icon = MAC_ICON;
  if (box.substr(0, 5) == "Linux" || box.indexOf("linux") != -1)
    icon = LINUX_ICON;
  if (box.substr(0, 7) == "Android" || box.indexOf("android") != -1)
    icon = ANDROID_ICON;
  if (box.substr(0, 5) == "Maemo" || box.indexOf("maemo") != -1)
    icon = MAEMO_ICON;    

  if (icon) {
    var img = document.createElement("img");
    img.src = icon;
    img.style.padding = "2px";
    cell.appendChild(img);
  }
  
  var type = "-";
  if (box.indexOf("l10n") != -1)
    type = "l10n";
  else if (box.indexOf("Nightly") != -1 || box.indexOf("nightly") != -1)
    type = "N";
  else if (box.indexOf("talos") != -1)
    type = "T";
  /*
  else if (box.indexOf("Debug") != -1 || box.indexOf("debug") != -1)
    type = "D";
  */
  else if (box.indexOf("leak test") != -1)
    type = "L";
  else if (box.indexOf("test") != -1)
    type = "U";
  else if (box.indexOf("perf test") != -1)
    type = "P";
  else if (box.indexOf("pgo-build") != -1)
    type = "PGO"
  else if (box.indexOf("build") != -1)
    type = "B";
  else if (box.indexOf("xulrunner") != -1)
    type = "X";
  else if (box.indexOf("shark") != -1)
    type = "shark";
  else if (box.indexOf("code coverage") != -1)
    type = "CC";
  else if (box.indexOf("valgrind") != -1)
    type = "V";
  else if (box.indexOf("blocklist update") != -1)
    type = "BU"

  cell.appendChild(document.createElement("br"));
  cell.appendChild(document.createTextNode(type));
}

function addActivityInfo(cell, activity)
{
  var type = "-";
  if (activity.indexOf("idle") != -1)
    type = "I";
  else if (activity.indexOf("waiting") != -1)
    type = "W";
  else if (activity.indexOf("building") != -1)
    type = "B";
 
  cell.appendChild(document.createElement("br"));
  cell.appendChild(document.createTextNode(type));
}

// Check whether string s is empty.                                             
function isEmpty(s)
{
    return ((s == null) || (s.length == 0));
}

// Returns true if string s is empty or                                         
// whitespace characters only.                                                  
function isWhitespace (s)
{
    var i;

    // Is s empty?                                                              
    if (isEmpty(s)) return true;

    if (s == "&nbsp;") return true;

    // Search through string's characters one by one                            
    // until we find a non-whitespace character.                                
    // When we do, return false; if we don't, return true.                      
    for (i = 0; i < s.length; i++) {
        // Check that current character isn't whitespace.                       
        var c = s.charAt(i);

        if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.                                           
    return true;
}

