File: D:/HostingSpaces/SBogers60/vandeurzenheftrucks.nl/wwwroot/js/vandeurzen/aside.js
/**
* Toggle auto navigation
*/
function toggleAutoNav()
{
var $w = $(window);
var $b = $('body');
var ww = $w.width();
if(ww < 1240)
{
$b.addClass('auto_nav');
}
else
{
$b.removeClass('auto_nav');
$b.removeClass('open_nav');
}
}
/**
* Check if menu should auto close
*/
function addAsideListener()
{
// On window resize
toggleAutoNav();
$(window).resize(function()
{
toggleAutoNav();
});
// On Hover
if( ! isTouch)
{
// Handle by hover
$('aside.nav').hover(function(){ openNav(); },function(){ closeNav(); });
}
else
{
// Handle by mobile click
$('#mob_nav').click(function(){ if($('body').hasClass('open_nav')){ closeNav(); }else{ openNav(); } });
}
// Close by content click
$('#content').click(function() { if($('body').hasClass('open_nav')){ closeNav(); } })
}
/**
* Handle menu by horizontal slide
*/
function initAsideSlider()
{
/*$(document).swipe({
allowPageScroll : "vertical",
swipeStatus:function(event, phase, direction, distance)
{
switch(phase)
{
case 'end':
if(direction == 'left' || direction == 'right')
{
if($('body').hasClass('open_nav'))
{
closeNav();
}
else
{
openNav();
}
}
break;
}
}
});*/
}
function openNav()
{
var $c = $('#content');
var $b = $('body');
if( $b.hasClass('auto_nav') && ! $b.hasClass('open_nav') && ! $c.hasClass('no_transitions')){
$b.addClass('open_nav hovered')
$c.addClass('no_transitions');
$c.css({ transform: 'translateY(-' + $c.attr('data-y') + 'px)',
webkitTransform: 'translateY(-' + $c.attr('data-y') + 'px)'});
}
}
function closeNav()
{
var $c = $('#content');
var $b = $('body');
if( $b.hasClass('auto_nav') && $b.hasClass('hovered')){
$b.removeClass('open_nav hovered')
var top = $c.attr('data-y');
$(document).scrollTop(top);
$c.css({ transform: '', webkitTransform: ''});
setTimeout(function(){ $c.removeClass('no_transitions'); },120);
}
}
/**
* Update content offset on scroll
* So we can change the offset when position is fixed
*/
function updateOffset()
{
var st = $(this).scrollTop();
if( ! $('#content').hasClass('no_transitions'))
{
$('#content').attr('data-y',st);
}
}
/*
function initAsideSlide()
{
var $aside = $('#nav');
var $content = $('#content,#header');
var startTouchPos = 0, endTouchPos = 0;
var $b = $('body');
var dir = 0;
var count = 0;
var lastX = 0;
document.addEventListener('touchstart', function(e){
startTouchPos = parseInt(e.touches[0].clientX,10);
$aside.css({ transition: 'none', webkitTransition: 'none' });
$content.css({ transition: 'none', webkitTransition: 'none'});
});
document.addEventListener('touchmove', function(e){
e.preventDefault();
var fingerX = endTouchPos = parseInt(e.touches[0].clientX, 10);
if(count == 10)
{
count = 0;
lastX = fingerX;
console.log(fingerX);
}
count++;
// Get direction
if(fingerX < lastX)
{
dir = 'left';
}
else if(fingerX > lastX )
{
dir = 'right';
}
var asideW, x;
if( ! $aside.hasClass('opened'))
{
asideW = (e.touches[0].clientX-startTouchPos) + 40;
x =(e.touches[0].clientX-startTouchPos) / 2;
}
else
{
asideW = 280 + (e.touches[0].clientX-startTouchPos);
x = (280 + (e.touches[0].clientX-startTouchPos) -40) /2;
}
if(asideW <= 280)
{
console.log(asideW + ' ' + x);
$aside.css({ width: asideW+'px' });
$content.css({ webkitTransform: 'translate(' + x +'px,0)', transform: 'translate(' + x +'px,0)' });
}
});
document.addEventListener('touchend', function(e){
if(dir == 'left')
{
//$b.removeClass('open_nav');
$aside.removeClass('opened')
$aside.css({ transition: 'width 300ms', webkitTransition: 'width 300ms', width: '40px' });
$content.css({ transition: 'all 300ms', webkitTransition: 'all 300ms', webkitTransform: '', transform: '0'});
}
else
{
//$b.addClass('open_nav');
$aside.addClass('opened')
$aside.css({ transition: 'width 300ms', webkitTransition: 'width 300ms', width: '280px' });
$content.css({ transition: 'all 300ms', webkitTransition: 'all 300ms', webkitTransform: 'translate(120px,0)', transform: 'translate(120px,0)'});
}
startTouchPos = endTouchPos = 0;
});
}
*/
function initAsideSlide()
{
var $aside = $('#nav');
var $content = $('#content,#header');
var $b = $('body');
/*
$(document).swipe({
allowPageScroll : "vertical",
swipeStatus:function(event, phase, direction, distance)
{
switch(phase)
{
case 'start':
$aside.addClass('no_transitions');
$content.addClass('no_transitions');
break;
case 'move':
var asideW, x, dist;
if(direction == 'left')
{
dist = -distance;
}
else if(direction == 'right')
{
dist = distance;
}
if( ! $aside.hasClass('opened'))
//if( ! $b.hasClass('open_nav'))
{
asideW = dist + 60;
x =dist / 2;
}
else
{
asideW = 280 + dist;
x = (280 + dist -60) /2;
}
if(asideW <= 280)
{
$aside.css({ width: asideW+'px' });
$content.css({ webkitTransform: 'translate(' + x +'px,0)', transform: 'translate(' + x +'px,0)' });
}
break;
case 'end':
//$aside.css({ transition: 'width 300ms', webkitTransition: 'width 300ms',width: '' });
//$content.css({ transition: 'all 300ms', webkitTransition: 'all 300ms', webkitTransform: '', transform: ''});
if(direction == 'left')
{
$aside.removeClass('opened');
$aside.removeClass('no_transitions');
$content.removeClass('no_transitions')
$aside.css({ width: '60px' });
$content.css({ webkitTransform: '0', transform: '0'});
setTimeout(function(){ $b.removeClass('open_nav');},300);
}
else if(direction == 'right')
{
$aside.addClass('opened');
$aside.removeClass('no_transitions');
$content.removeClass('no_transitions')
$aside.css({ width: '280px' });
$content.css({ webkitTransform: 'translate(120px,0)', transform: 'translate(120px,0)'});
setTimeout(function(){ $b.addClass('open_nav');},300);
}
break;
}
}
});
*/
}