Skip to content

Instantly share code, notes, and snippets.

@adamclaxon
Created August 30, 2017 15:18
Show Gist options
  • Save adamclaxon/8f6cba02f4f3c2c2fcd90bed9a56519e to your computer and use it in GitHub Desktop.
Save adamclaxon/8f6cba02f4f3c2c2fcd90bed9a56519e to your computer and use it in GitHub Desktop.
jQuery(function($){
if($body_id === 'people' || $body_id === 'portfolio' ) {
$('body').on('click','.panel-control a',function(e) {
var $id = $(this).attr('href');
var $target = $id.split('/'+$body_id+'/');
var $hash = $target[1].split('/');
ajaxPages($hash[0]);
e.preventDefault();
e.stopPropagation();
return false;
});
$('body').on('click','i.close_canv',function(e){
removeHash();
$(this).removeClass('full-opacity');
$('#ov_canvas_container').removeClass('slide-out');
$('#ov_canvas').fadeOut(500,function(){
$(this).remove();
});
$('body').removeClass('noscroll');
});
$('body').on('click','.ov-overlay',function(){
$('i.close_canv').trigger('click');
});
var current_poll_interval;
function startCurrentPolling() {
current_poll_interval = setInterval(currentPoll, 100);
}
function currentPoll() {
if ( $('body').hasClass('mpc-loaded') ) {
stopCurrentPolling();
}
}
function stopCurrentPolling() {
clearInterval(current_poll_interval);
if(window.location.hash) {
ajaxPages(window.location.hash.substr(1));
}
removeHash();
}
startCurrentPolling();
}
function ajaxPages($id) {
var $canvas = '<section id="ov_canvas">' +
'<div class="ov-overlay"></div>' +
'<div class="loading"><div class="load-container"><div class="loader"></div><span>One Moment</span></div></div>' +
'<div id="ov_canvas_container"></div>' +
'<i class="close_canv"></i>' +
'</section>';
$('body').addClass('noscroll').append($canvas);
$('#ov_canvas').fadeIn(500);
console.log($body_id);
$('#ov_canvas_container').load('/' + $body_id + '/' + $id + ' #ajax_container', function(){
$('.close_canv').addClass('full-opacity');
$('.loading').fadeOut(250);
$(this).addClass('slide-out');
window.location.hash = $id;
});
};
function removeHash () {
history.pushState("", document.title, window.location.pathname + window.location.search);
}
function removeAnchors(){
if($('.top-anchors a').hasClass('active')){
$('.top-anchors a').removeClass('active');
}
if($('.anchor-link-set a').hasClass('active')){
$('.anchor-link-set a').removeClass('active');
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment