$(document).ready(function() { var inClick = false; var height = 0; $('.timeline').each(function() { if (timelinepages < 1) { timelinepages = 1; } if (timelinepages == 1) { $('.next').addClass('inactive'); } } ); $('.events-content li').each(function() { if($(this).height() > height ) { height =$(this).height(); $('.events-content').height(height); } } ); $('.events ol').each(function() { $width = $(this).parent().width()*timelinepages; $(this).width($width); $licount = $('.events li').length; $years = $(this).find('li:last-child a').attr('data-date') -$(this).find('li:first-child a').attr('data-date'); $lispacing = $width / $years; $('.events ol li').each(function() { $(this).css('left', $lispacing * ($(this).find('a').attr('data-date') - $(this).parent().find('li:first-child a').attr('data-date'))); } ); } ); $clicked = 1; $('.next').click(function() { if (inClick) return; inClick = true; if($clicked < timelinepages ) { $clicked ++; $('.cd-timeline-navigation .inactive').removeClass('inactive'); if($clicked == timelinepages ) { $(this).addClass('inactive'); } $left = parseInt($('.events ol').css('left')); $('.events ol').css('left', $left -($('.events ol').width()/timelinepages) ); $('.line').css('left', $left -($('.events ol').width()/timelinepages) ); } setTimeout(function() { inClick = false; } , 300); } ); $('.prev').click(function() { if (inClick) return; inClick = true; if($clicked > 1) { $clicked --; $('.cd-timeline-navigation .inactive').removeClass('inactive'); if($clicked == 1 ) { $(this).addClass('inactive'); } $left = parseInt($('.events ol').css('left')); $('.events ol').css('left', $left +($('.events ol').width()/timelinepages) ); $('.line').css('left', $left +($('.events ol').width()/timelinepages) ); } setTimeout(function() { inClick = false; } , 300); } ); $('.events a').click(function() { $('.events a').removeClass('selected'); $(this).addClass('selected'); $('.line').width($(this).parent().css('left')); $yearclicked = $(this).attr('data-date'); $selected = $('.events-content .selected').attr('data-date'); $('.events-content li').removeClass('previouslyselected'); $('.events a').removeClass('previousyear'); $('.events a').each(function() { if($yearclicked > $(this).attr('data-date')) { $(this).addClass('previousyear'); } } ); $('.events-content li').each(function() { if($yearclicked > $(this).attr('data-date')) { $(this).addClass('previouslyselected'); } } ); $('.events-content .selected').removeClass('selected'); $('.events-content li').each(function() { if($(this).attr('data-date') == $yearclicked) { $(this).addClass('selected'); } } ); } ); } );