Sha256: b5f582d9edb3dafeca5c4dc9a4df9c395f989d94cc0b32cfad18b9c0ae9ac625

Contents?: true

Size: 1.71 KB

Versions: 5

Compression:

Stored size: 1.71 KB

Contents

"use strict";

var Index = (function() {
  function galleryVisible() {
    return document.body.classList.contains("gallery");
  }

  function listingVisible() {
    return document.body.classList.contains("listing");
  }

  function jumpListing() {
    document.body.classList.remove("gallery");
    document.body.classList.add("listing");
  }

  function jumpGallery() {
    document.body.classList.remove("listing");
    document.body.classList.add("gallery");
  }

  function jumpScroll() {
    if(galleryVisible()) {
      jumpListing();
      window.scrollTo(0, 0);
    }
    else {
      jumpGallery();
      window.scrollTo(0, document.body.scrollHeight);
    }
  }

  function atTop() {
    return window.scrollY == 0;
  }

  function bottomScrollDown(event) {
    return galleryVisible() && atBottom() && event.deltaY > 0;
  }

  function topScrollUp(event) {
    return listingVisible() && atTop() && event.deltaY < 0;
  }

  function initEvents() {
    var scrollSize = 0;

    window.addEventListener("wheel", function(event) {
      if(bottomScrollDown(event) || topScrollUp(event)) {
        scrollSize += Math.abs(event.deltaY);

        if(scrollSize >= 1500) {
          scrollSize = 0;
          jumpScroll();
        }
      }
      else {
        scrollSize = 0;
      }
    });
  }

  function init() {
    if((Entries.media().length / Entries.all().length) >= 0.5) jumpGallery();
    else jumpListing();

    initEvents();
  }

  return {
    init: init,
    galleryVisible: galleryVisible,
    listingVisible: listingVisible,
    jumpListing: jumpListing,
    jumpGallery: jumpGallery
  };
})();

window.addEventListener("DOMContentLoaded", Index.init);

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
servel-0.28.0 app/js/index.js
servel-0.27.0 app/js/index.js
servel-0.26.0 app/js/index.js
servel-0.25.0 app/js/index.js
servel-0.24.0 app/js/index.js