Sha256: 85b2d0a5efb92b0127c535401ce9eef981266aaa102b1d22ce882b4f495da2cb

Contents?: true

Size: 1.32 KB

Versions: 7

Compression:

Stored size: 1.32 KB

Contents

<script>
    function hashLocate(hashValue) {
        hashValue = hashValue.replace(/^.*#h-/, '');
        hashValue = decodeURIComponent(hashValue);
        var element = document.getElementById(hashValue);

        if (!element) {
            return;
        }

        var header = document.querySelector('header.site-header');
        var headerRect = header.getBoundingClientRect();
        var headerTop = Math.floor(headerRect.top);
        var headerHeight = Math.floor(headerRect.height);
        var scrollPos = getScrollPos();
        var offsetY = element.offsetTop - (headerTop + headerHeight + 20);

        if (offsetY == scrollPos.y) {
            return;
        }

        if (headerTop == 0  && offsetY > scrollPos.y) {
            offsetY += headerHeight + 2;
        } else if (headerTop < 0  && offsetY < scrollPos.y) {
            offsetY -= headerHeight - 2;
        }

        smoothScrollTo(offsetY);
    }

    // The first event occurred
    window.addEventListener('load', function(event) {
        if (window.location.hash) {
            hashLocate(window.location.hash);
        }
    });

    // The first event occurred
    window.addEventListener('click', function(event) {
        if (event.target.tagName.toLowerCase() == 'a') {
            hashLocate(event.target.getAttribute('href'));
        }
    });
</script>

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
redeyed-jekyll-theme-0.1.7 _includes/extensions/hashlocate.html
redeyed-jekyll-theme-0.1.6 _includes/extensions/hashlocate.html
redeyed-jekyll-theme-0.1.5 _includes/extensions/hashlocate.html
redeyed-jekyll-theme-0.1.4 _includes/extensions/hashlocate.html
redeyed-jekyll-theme-0.1.3 _includes/extensions/hashlocate.html
redeyed-jekyll-theme-0.1.2 _includes/extensions/hashlocate.html
redeyed-jekyll-theme-0.1.1 _includes/extensions/hashlocate.html