forked from saurabh/orbit4-5
79 lines
2.9 KiB
JavaScript
79 lines
2.9 KiB
JavaScript
(function() {
|
|
"use strict";
|
|
|
|
var doc = document;
|
|
|
|
var group = {
|
|
// Detect and change the top position of the cycle navs
|
|
cycleFix: function() {
|
|
if( doc.querySelectorAll( ".group-post-banner-image").length >= 1 ) {
|
|
var imgs = doc.querySelectorAll( ".group-post-banner-image" ),
|
|
imgHeight = imgs[ 0 ].clientHeight,
|
|
cycleNav = doc.querySelectorAll( ".cycle-nav" ),
|
|
cycleNavHeight = cycleNav[ 0 ].clientHeight,
|
|
len = cycleNav.length,
|
|
i = -1;
|
|
|
|
// Hide the navs when there's noly one slide
|
|
if( imgs.length <= 1 ) {
|
|
for( i = 0; i < len; i++ ) {
|
|
cycleNav[ i ].classList.add( "hide" );
|
|
}
|
|
} else {
|
|
// Change nav top positions which are calculating by JavaScript
|
|
for ( i = 0; i < len; i++ ) {
|
|
cycleNav[ i ].style.top = ( ( imgHeight / 2 ) - ( cycleNavHeight / 2 ) ) + "px";
|
|
}
|
|
}
|
|
}
|
|
},
|
|
// Create the tool tip wrap and get the seen counts and then inject them into DOM
|
|
createToolTip: function() {
|
|
if( doc.querySelectorAll( ".group-post-seen-by-name" ).length >= 1 ) {
|
|
var container = doc.querySelector( ".group-post-seen-by" ),
|
|
names = doc.querySelectorAll( ".group-post-seen-by-name" ),
|
|
namesLen = names.length,
|
|
span = doc.createElement( "span" ),
|
|
wrap = doc.createElement( "div" ),
|
|
frag = document.createDocumentFragment();
|
|
|
|
// Get the seen counts and append them
|
|
span.className = "group-post-seen-by-count";
|
|
span.textContent = namesLen;
|
|
names[ 0 ].parentNode.appendChild( span );
|
|
|
|
// Create the tool tip and save them in the document fragment
|
|
wrap.className = "group-post-seen-by-names tool-tip";
|
|
Array.prototype.slice.call( names ).forEach( function( el ) {
|
|
frag.appendChild( el );
|
|
});
|
|
|
|
// Append the final result to DOM
|
|
wrap.appendChild( frag );
|
|
container.appendChild( wrap );
|
|
}
|
|
},
|
|
scrollEffect: function() {
|
|
var page = doc.querySelector( ".group-page" ),
|
|
wrap = doc.querySelector( ".group-page-banner-image-wrap" ),
|
|
scrollClass = "scroll";
|
|
|
|
function stickyScroll( e ) {
|
|
if( window.pageYOffset > 210 ) {
|
|
page.classList.add( scrollClass );
|
|
}
|
|
}
|
|
|
|
window.addEventListener( "scroll", stickyScroll);
|
|
}
|
|
}
|
|
|
|
// When DOM is completely loaded
|
|
document.addEventListener( "DOMContentLoaded", function( event ) {
|
|
group.cycleFix();
|
|
group.createToolTip();
|
|
group.scrollEffect();
|
|
});
|
|
|
|
})();
|