Team:Wageningen UR/JS/notebook.js

From 2013.igem.org

Revision as of 19:39, 23 April 2014 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: false
     });
   });

$('#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').eq(2).attr('id'); alert(firstDate); $('#filters .bydate .iconsweek').children('a.'+firstDate).addClass('active');

$('#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];
       if(theID != aArray[0]){
           var divPos = $('#' + theID).offset().top-95; // get the offset of the div from the top of page
       } else {
           var divPos = 0;
       }
       if( theID != 'january') {
           var divHeight = $('#container').children('.date').eq(i+1).offset().top-95;
       } else {
           var divHeight = docHeight;
       }
       var divHeight = divHeight - divPos;
       if (windowPos >= divPos && windowPos < (divPos + divHeight)) {
           
               $('.iconsweek a.' + theID ).addClass("on");
           
       } else {
           $('.iconsweek a.' + theID ).removeClass("on");
       }
   }

});

});