2015-03-31 07:51:04 +00:00
|
|
|
(function() {
|
|
|
|
"use strict";
|
|
|
|
|
2015-04-14 07:31:41 +00:00
|
|
|
// Commonly use variables
|
2015-03-31 07:51:04 +00:00
|
|
|
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" ),
|
|
|
|
cycleNav = doc.querySelectorAll( ".cycle-nav" ),
|
|
|
|
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" );
|
|
|
|
}
|
|
|
|
}
|
2015-04-14 07:31:41 +00:00
|
|
|
|
|
|
|
} else if ( doc.querySelectorAll( ".group-post-banner-image").length === 0 && doc.querySelector( ".group-post-image-wrap" ) ) {
|
|
|
|
doc.querySelector( ".group-post-image-wrap").classList.add( "hide" );
|
2015-03-31 07:51:04 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
// Create the tool tip wrap and get the seen counts and then inject them into DOM
|
2015-04-14 07:31:41 +00:00
|
|
|
createToolTip: function( container, names, cls1, cls2, wrapEl ) {
|
|
|
|
if( doc.querySelectorAll( names ).length >= 1 ) {
|
|
|
|
var container = doc.querySelector( container ),
|
|
|
|
names = doc.querySelectorAll( names ),
|
2015-03-31 07:51:04 +00:00
|
|
|
span = doc.createElement( "span" ),
|
|
|
|
wrap = doc.createElement( "div" ),
|
|
|
|
frag = document.createDocumentFragment();
|
|
|
|
|
|
|
|
// Get the seen counts and append them
|
2015-04-14 07:31:41 +00:00
|
|
|
span.className = cls1;
|
2015-03-31 07:51:04 +00:00
|
|
|
names[ 0 ].parentNode.appendChild( span );
|
|
|
|
|
|
|
|
// Create the tool tip and save them in the document fragment
|
2015-04-14 07:31:41 +00:00
|
|
|
wrap.className = cls2 + " tool-tip";
|
2015-03-31 07:51:04 +00:00
|
|
|
Array.prototype.slice.call( names ).forEach( function( el ) {
|
|
|
|
frag.appendChild( el );
|
|
|
|
});
|
|
|
|
|
|
|
|
// Append the final result to DOM
|
|
|
|
wrap.appendChild( frag );
|
|
|
|
container.appendChild( wrap );
|
|
|
|
}
|
|
|
|
},
|
2015-04-14 07:31:41 +00:00
|
|
|
// Create scroll effect (with css)
|
2015-03-31 07:51:04 +00:00
|
|
|
scrollEffect: function() {
|
2015-04-14 07:31:41 +00:00
|
|
|
if( doc.querySelector( ".group-page") ) {
|
|
|
|
var page = doc.querySelector( ".group-page" ),
|
|
|
|
wrap = doc.querySelector( ".group-page-banner-image-wrap" ),
|
|
|
|
scrollClass = "scroll";
|
2015-03-31 07:51:04 +00:00
|
|
|
|
2015-04-14 07:31:41 +00:00
|
|
|
// Use pageYOffset to get the Y positoin and add scroll on it, the animation
|
|
|
|
// is done by css transition
|
|
|
|
window.addEventListener( "scroll", function() {
|
|
|
|
if( window.pageYOffset !== 0 ) {
|
|
|
|
page.classList.add( scrollClass );
|
|
|
|
} else {
|
|
|
|
page.classList.remove( scrollClass );
|
|
|
|
}
|
|
|
|
}, false);
|
|
|
|
}
|
2015-03-31 07:51:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-14 07:31:41 +00:00
|
|
|
// When DOM is completely loaded, execute these functions
|
2015-03-31 07:51:04 +00:00
|
|
|
document.addEventListener( "DOMContentLoaded", function( event ) {
|
|
|
|
group.cycleFix();
|
2015-04-14 07:31:41 +00:00
|
|
|
group.createToolTip( ".group-post-seen-by", ".group-post-seen-by-name", "group-post-seen-by-count", "group-post-seen-by-names" );
|
2015-03-31 07:51:04 +00:00
|
|
|
group.scrollEffect();
|
|
|
|
});
|
|
|
|
|
|
|
|
})();
|