Skip to content

Instantly share code, notes, and snippets.

@AndreyKopylov
Created April 20, 2015 07:04
Show Gist options
  • Save AndreyKopylov/b4b574d4b315aed8a435 to your computer and use it in GitHub Desktop.
Save AndreyKopylov/b4b574d4b315aed8a435 to your computer and use it in GitHub Desktop.
function fullpageInit() {
var $subNavItems = $('.product-list_link, .sidebar_nav_link, .pagination_link'),
hash = null,
hrefAttr = null,
$firstPaginator = $('.sidebar_nav'),
$secondPaginator = $('.pagination'),
url = window.location;
$('.wrapper').fullpage({
css3: true,
sectionSelector: '.page',
anchors: ['auditorius', 'displays', 'audiences', 'platform', 'dmp', 'exchange', 'marketplace', 'audience', 'contact'],
normalScrollElements: '.audience_wrapper_inner, .gmap, .inner-page-wrapper-inner',
// onLeave Event to track nav state
onLeave: function(index, nextIndex, direction) {
hash = location.hash.slice(1);
hrefAttr = '#' + hash;
$subNavItems.removeClass('active');
$.each($subNavItems, function() {
if ($(this).attr('href') == hrefAttr) {
$(this).addClass('active');
}
});
// each end
pagination();
highlightActive(index, nextIndex, direction);
// inverse sidebar
var checkInverse = $('.page.active').attr('data-inverse-sidebar');
if (checkAttrExist(checkInverse)) {
$('.sidebar').addClass('inverse');
} else {
$('.sidebar').removeClass('inverse');
}
},
// onLeave end
afterRender: function() {
console.log(url);
if ( url.hash === undefined || url.hash === null || url.hash === '') {
url.hash = 'auditorius';
}
if ( url.hash.slice(1) === $('.page').eq(0).attr('data-anchor') ) {
var getAttr = $('.page').eq(0).attr('data-anchor');
$('.sidebar_nav_link[data-menuanchor="' + getAttr +'"]').addClass('active');
$('.sidenav_link--products').addClass('active');
$('.product-list_link[href="#audiences"]').addClass('active');
}
var currentUrl = url.hash.slice(1) || 'auditorius';
$('a.menu_full_dropdown_link[href="#' + currentUrl + '"]').addClass('active');
},
onSlideLeave: function( anchorLink, index, slideIndex, direction) {
var leavingSlide = $(this);
if (anchorLink == 'auditorius') {
alert("boom");
window.removeEventListener("load", function() {
canvasEarth();
});
}
},
afterLoad: function(anchorLink, index, slideAnchor, slideIndex) {
var loadedSection = $(this);
var checkRender = {
'0': {render:(function (lib, images, createjs) {
function canvasEarth() {
var canvas, stage, exportRoot;
canvas = document.getElementById("canvasEarth");
exportRoot = new lib.earth2();
stage = new createjs.Stage(canvas);
stage.addChild(exportRoot);
stage.update();
createjs.Ticker.setFPS(lib.properties.fps);
createjs.Ticker.addEventListener("tick", stage);
}
} (lib = lib||{}, images = images||{}, createjs = createjs||{}))
}
};
if(anchorLink == 'auditorius') {
alert("Section 1 ended loading");
var callRender = checkRender[0];
console.log('lol1');
if (callRender && !callRender.isRendered) {
callRender.isRendered = true;
console.log('lol');
callRender.render();
}
}
if(anchorLink == 'displays') {
alert("Section 2 ended loading");
}
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment