Sha256: 76a326c2b05d039e981334eb814cb23fda0c584e4b0107cc88e17d69e5db3750

Contents?: true

Size: 1.06 KB

Versions: 2

Compression:

Stored size: 1.06 KB

Contents

/**
 * A tool for smooth scrolling and topbar switcher
 */
const ScrollHelper = (function () {
  const $body = $("body");
  const ATTR_TOPBAR_VISIBLE = "data-topbar-visible";
  const topbarHeight = $("#topbar-wrapper").outerHeight();

  let scrollUpCount = 0; // the number of times the scroll up was triggered by ToC or anchor
  let topbarLocked = false;
  let orientationLocked = false;

  return {
    hideTopbar: () => $body.attr(ATTR_TOPBAR_VISIBLE, false),
    showTopbar: () => $body.attr(ATTR_TOPBAR_VISIBLE, true),

    // scroll up

    addScrollUpTask: () => {
      scrollUpCount += 1;
      if (!topbarLocked) { topbarLocked = true; }
    },
    popScrollUpTask: () => scrollUpCount -= 1,
    hasScrollUpTask: () => scrollUpCount > 0,
    topbarLocked: () => topbarLocked === true,
    unlockTopbar: () => topbarLocked = false,
    getTopbarHeight: () => topbarHeight,

    // orientation change

    orientationLocked: () => orientationLocked === true,
    lockOrientation: () => orientationLocked = true,
    unLockOrientation: () => orientationLocked = false
  };

}());

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
redeyed-jekyll-theme-0.1.2 _javascript/common/scroll-helper.js
redeyed-jekyll-theme-0.1.1 _javascript/common/scroll-helper.js