orbit4-5/app/assets/javascripts/group.js

54 lines
1.9 KiB
JavaScript
Raw Normal View History

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
}
},
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();
group.scrollEffect();
});
})();