Sha256: 2a234d9138c2b145920769b67db0572dda20643fd0cb5ab64a1f6ba26204d4f1

Contents?: true

Size: 1.31 KB

Versions: 1

Compression:

Stored size: 1.31 KB

Contents

(function (window, document, undefined) {

  // Find peek element
  var peekElement = document.querySelector("#peek");

  // Check existence of peek element
  if (!peekElement)
    return false;

  // Build event
  var event = new Event('peek');

  // Listener Class
  var Listener = function (target, handler) {
    this.target = new RegExp(target, "i");
    this.queue = "";
    this.handler = handler;
    this.compare = function () {
      if (this.queue.match(this.target)) {
        this.queue = "";
        this.handler();
      }
    };
  };

  // Target
  var target = "peek";

  // Handler
  var handler = function () {
    peekElement.style.display = (localStorage.getItem("peekStatus") == "none") ? "block" : "none";
    localStorage.setItem("peekStatus", peekElement.style.display);
    window.dispatchEvent(event);
  };

  // Set peekStatus with localStorage
  if (!localStorage.getItem("peekStatus"))
    localStorage.setItem("peekStatus", "none");

  // Give born to a Listener object
  var peekListener = new Listener(target, handler);
  peekElement.style.display = localStorage.getItem("peekStatus");

  // Hook listener on window
  window.addEventListener("keydown", function (e) {
    peekListener.queue = peekListener.queue.concat(String.fromCharCode(e.keyCode));
    peekListener.compare();
  });

})(window, document);

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
peeker-0.1.5 app/assets/javascripts/peeker.js