var indexContainer = document.querySelector('.standard-posts'), indexWindowWidth = 0, indexWindowHeight = 0, indexPostAreaHeight = 0; indexWindowScrollTop = 0, indexIframes = indexContainer.querySelectorAll('iframe'), indexStickyPostContainer = document.querySelector('.sticky-posts'), indexStickyPosts = indexStickyPostContainer.querySelectorAll('article'), indexStickyPostIndicators = indexStickyPostContainer.querySelectorAll('.indicators a'), indexCurrentStickyPostIndex = 0, indexStickyPostHeight = 0, indexStickyPostIsStuck = false, indexHeaderHeight = 140, indexStickyPostScrollOffset = 0, indexDocumentHeight = 0 ; if(document.querySelectorAll('.sticky-posts article').length == 1) document.querySelector('.sticky-posts').className += ' single'; function indexInit() { if(document.querySelectorAll('.standard-posts article').length > 0) new Packery(indexContainer); indexHandleWindowResize(); indexStickyPostHeight = indexStickyPosts[indexCurrentStickyPostIndex].clientHeight; for(var i = 0, n = indexStickyPostIndicators.length; i < n; i++) { (function(i) { indexStickyPostIndicators[i].addEventListener('click', function(event) { indexNavigateStickyPost(i); event.preventDefault(); event.stopPropagation(); return false; }); })(i); } var indexImageLinks = document.querySelectorAll('.posts a img'); for(var i = 0, n = indexImageLinks.length; i < n; i++) { if(indexImageLinks[i].parentNode.className.indexOf('iframe') > -1) { indexImageLinks[i].parentNode.addEventListener('click', function(event) { document.querySelector('#media-lightbox .media').innerHTML = '' document.getElementById('media-lightbox').className = 'visible'; event.preventDefault(); event.stopPropagation(); return false; }); }else { indexImageLinks[i].parentNode.addEventListener('click', function(event) { document.querySelector('#media-lightbox .media').innerHTML = '
' document.getElementById('media-lightbox').className = 'visible'; event.preventDefault(); event.stopPropagation(); return false; }); } } document.querySelector('#media-lightbox .close').addEventListener('click', function(event) { document.getElementById('media-lightbox').className = ''; setTimeout(function() { document.querySelector('#media-lightbox .media').innerHTML = ''; }, 500); event.preventDefault(); event.stopPropagation(); return false; }); if(document.body.className.indexOf('admin-bar') > -1) indexHeaderHeight = 172; window.addEventListener('resize', indexHandleWindowResize); indexHandleWindowResize(); window.addEventListener('scroll', indexHandleWindowScroll); indexHandleWindowScroll(); } function indexNavigateStickyPost(newStickyPostIndex) { indexStickyPosts[indexCurrentStickyPostIndex].className = ''; indexStickyPosts[newStickyPostIndex].className = 'current'; indexStickyPostIndicators[indexCurrentStickyPostIndex].className = ''; indexStickyPostIndicators[newStickyPostIndex].className = 'current'; indexCurrentStickyPostIndex = newStickyPostIndex; indexStickyPostHeight = indexStickyPosts[indexCurrentStickyPostIndex].clientHeight; indexStickyPostScrollOffset = indexWindowScrollTop; indexHandleWindowResize(); } function indexHandleWindowResize() { indexWindowWidth = Math.max(document.documentElement.clientWidth || document.body.clientWidth); indexWindowHeight = Math.max(document.documentElement.clientHeight || document.body.clientHeight); indexPostAreaHeight = indexWindowHeight - indexHeaderHeight; if(document.querySelectorAll('.sticky-posts article').length > 1) indexPostAreaHeight -= 46; indexDocumentHeight = Math.max(document.body.scrollHeight, document.body.offsetHeight, indexWindowHeight, document.documentElement.scrollHeight, document.documentElement.offsetHeight); indexStickyPostHeight = indexStickyPosts[indexCurrentStickyPostIndex].clientHeight; var tempRatio = 0; for(var i = 0, n = indexIframes.length; i < n; i++) { tempRatio = indexIframes[i].height / indexIframes[i].width; indexIframes[i].width = indexWindowWidth / 4; indexIframes[i].height = tempRatio * indexIframes[i].width; } } function indexHandleWindowScroll() { var indexNewWindowScrollTop = Math.min(Math.max(document.body.scrollTop, document.documentElement.scrollTop, 0), indexDocumentHeight - indexWindowHeight); indexDocumentHeight = Math.max(document.body.scrollHeight, document.body.offsetHeight, indexWindowHeight, document.documentElement.scrollHeight, document.documentElement.offsetHeight); if(indexWindowWidth > 700) { console.log(indexStickyPostHeight + indexHeaderHeight + ' > ' + indexDocumentHeight); if(indexStickyPostHeight + indexHeaderHeight + 1 < indexDocumentHeight) { if(indexStickyPostHeight > 0) { if(indexNewWindowScrollTop < indexStickyPostScrollOffset) { if(indexNewWindowScrollTop > indexWindowScrollTop) { if(indexStickyPostIsStuck) { indexStickyPostContainer.style.position = 'absolute'; indexStickyPostContainer.style.top = indexNewWindowScrollTop + 'px'; indexStickyPostIsStuck = false; indexStickyPostScrollOffset = indexNewWindowScrollTop; } }else { if(!indexStickyPostIsStuck) { indexStickyPostContainer.style.position = 'fixed'; indexStickyPostContainer.style.top = indexHeaderHeight + 'px'; indexStickyPostIsStuck = true; } } }else if(indexNewWindowScrollTop > indexStickyPostHeight - indexPostAreaHeight + indexStickyPostScrollOffset) { if(indexNewWindowScrollTop < indexWindowScrollTop) { if(indexStickyPostHeight > indexPostAreaHeight) { if(indexStickyPostIsStuck) { indexStickyPostContainer.style.position = 'absolute'; indexStickyPostContainer.style.top = Math.max(indexNewWindowScrollTop + indexPostAreaHeight - indexStickyPostHeight, 0) + 'px'; indexStickyPostIsStuck = false; indexStickyPostScrollOffset = Math.max(indexNewWindowScrollTop + indexPostAreaHeight - indexStickyPostHeight, 0); } } }else { if(!indexStickyPostIsStuck) { indexStickyPostContainer.style.position = 'fixed'; indexStickyPostContainer.style.top = Math.min(indexPostAreaHeight - indexStickyPostHeight + indexHeaderHeight, indexHeaderHeight) + 'px'; indexStickyPostIsStuck = true; } } }else { if(indexStickyPostIsStuck) { indexStickyPostContainer.style.position = 'absolute'; indexStickyPostContainer.style.top = indexStickyPostScrollOffset + 'px'; indexStickyPostIsStuck = false; } } } } } indexWindowScrollTop = indexNewWindowScrollTop; } imagesLoaded(indexContainer, indexInit);