{"size": 1600, "ext": "js", "max_stars_repo_path": "scripts/model/utils/Stopwatch.js", "max_stars_repo_name": "bethloe/Quality-Analyzer", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "scripts/model/utils/Stopwatch.js", "max_issues_repo_name": "bethloe/Quality-Analyzer", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "scripts/model/utils/Stopwatch.js", "max_forks_repo_name": "bethloe/Quality-Analyzer", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 19.2771084337, "max_line_length": 52, "alphanum_fraction": 0.576875}
var Stopwatch = function(elem, options) {

  var timer       = createTimer(),
     // startButton = createButton("start", start),
     // stopButton  = createButton("stop", stop),
     // resetButton = createButton("reset", reset),
      offset,
      clock,
      interval;

  // default options
  options = options || {};
  options.delay = options.delay || 0;

  // append elements     
  elem.appendChild(timer);
  //elem.appendChild(startButton);
 // elem.appendChild(stopButton);
 // elem.appendChild(resetButton);

  // initialize
  reset();

  // private functions
  function createTimer() {
    return document.createElement("span");
  }

  function createButton(action, handler) {
    var a = document.createElement("a");
    a.href = "#" + action;
    a.innerHTML = action;
    a.addEventListener("click", function(event) {
      handler();
      event.preventDefault();
    });
    return a;
  }

  function start() {
	////console.log("IN start");
    if (!interval) {
      offset   = Date.now();
      interval = setInterval(update, options.delay);
    }
  }

  function stop() {
  
	////console.log("IN stop() " + clock);
    if (interval) {
      clearInterval(interval);
      interval = null;
    }
  }

  function reset() {
    clock = 0;
    render();
  }

  function update() {
    clock += delta();
    render();
  }

  function render() {
    timer.innerHTML = clock/1000; 
  }

  function delta() {
    var now = Date.now(),
        d   = now - offset;

    offset = now;
    return d;
  }

  // public API
  this.start  = start;
  this.stop   = stop;
  this.reset  = reset;
};