Team:Wageningen UR/JS/notebook.js
From 2013.igem.org
Revision as of 20:48, 2 August 2013 by Karrenbelt (Talk | contribs)
$(document).ready(function() {
$('#container h2:first-of-type .editsection a').html('edit entries');
var $container = $('#container'); $container.imagesLoaded(function(){ $container.masonry({ itemSelector: '.item', columnWidth: 320, isFitWidth: true }); });
$('#filters .bysubject a').click(function () {
var ourClass = $(this).attr('class');
if (ourClass.indexOf("active") >= 1) {
ourClass = ourClass.substring(0, ourClass.indexOf("active")); $(this).removeClass('active'); $('#container').children('div.' + ourClass).show().css({opacity: 0}).addClass('item'); setTimeout(function() { $container.masonry('reload'); setTimeout(function() {$('#container').children('div.' + ourClass).css({opacity: 1});},100); }, 350);
} else {
$(this).addClass('active'); $('#container').children('div.' + ourClass).hide('fast').removeClass('item'); $container.masonry('reload');
}
});
var firstDate = $('#container .date:first').attr('id'); $('#filters .bydate .iconsweek').children('a.' + firstDate).addClass('on');
$('#filters .bydate .iconsweek a').click(function(e){
e.preventDefault(); $('html, body').stop().animate({ scrollTop: $($(this).attr('href')).offset().top - 95}, 800);
});
var aChildren = $("#container").children('.date'); // find the a children of the list items var aArray = []; // create the empty aArray for (var i=0; i < aChildren.length; i++) { var aChild = aChildren[i]; var ahref = $(aChild).attr('id'); aArray.push(ahref); }
$(window).scroll(function(){
var windowPos = $(window).scrollTop(); // get the offset of the window from the top of page var windowHeight = $(window).height(); // get the height of the window var docHeight = $(document).height();
for (var i=0; i < aArray.length; i++) { var theID = aArray[i]; var divPos = $('#' + theID).offset().top - 95; // get the offset of the div from the top of page if(i < 17) { var divHeight = $('#' + theID).parent().children('.date').eq(i+1).offset().top - 95; } else { alert(theID); var divHeight = docHeight - ($('#' + theID).offset().top - 95); } var divHeight = divHeight - divPos; if (windowPos >= divPos && windowPos < (divPos + divHeight)) { $('.iconsweek a.' + theID ).addClass("on"); } else { $('.iconsweek a.' + theID ).removeClass("on"); } }
if(windowPos + windowHeight == docHeight) { if (!$('.iconsweek a.januari').hasClass('on')) { var navActiveCurrent = $('.iconsweek .on').attr('href'); $("a[href='" + navActiveCurrent + "']").removeClass('on'); $('.iconsweek a.januari').addClass('on'); } }
});
});