Team:NYMU-Taipei/menu.js

From 2014.igem.org

Revision as of 06:27, 1 August 2014 by Hiwang123 (Talk | contribs)

$(window).on('beforeunload', function() {

        $(window).scrollTop(0);

}); $( document ).ready(function() {

 $('#menu > ul > li')
       .on('mouseenter', function(){
           clearTimeout($.data(this,'timer'));
           $(this).find('ul').stop(true,true).slideDown(200);  
           if($(this).hasClass('now')) return ;
           $(this).find('> a > span').stop(true,true).animate({opacity: '1'}, 300);
      
       })
       .on('mouseleave', function(){
           $.data(this,'timer', setTimeout($.proxy(function() {
           $(this).find('ul').stop(true,true).slideUp(200);
           }, this), 100));  
           if($(this).hasClass('now')) return ;
           $(this).find('> a > span').stop(true,true).animate({opacity: '0'}, 300);
     
       })
       .click( function(){
           $('#menu > ul > li').removeClass('now');
           $(this).addClass('now');
           $(this).find('> a > span').stop(true,true).animate({opacity: '1'}, 300);
           $('#menu > ul > li').not(this).find('a > span').css({opacity: '0'});
       });   
 $('#menu > ul > li > ul > li')
      .on('mouseenter',function(){
           $(this).find('a > span').css({'display':'block',opacity: '1'});
       })
      .on('mouseleave',function(){
           $(this).find('a > span').css({'display':'none',opacity: '1'});
       });
 $(window).scroll(function (event){
        var y = $(this).scrollTop();
        if(window.location.pathname=='/Team:NYMU-Taipei'){
            $('.header').css({'background-position':'0px '+(40+y)+'px' });
        } 
        else{
            $('.outlink').css({marginTop: 200-y,});
        } 
        if(y>290){
            $('#menu').css({
                marginTop:0,
            });
        }
        else{
            $('#menu').css({
               marginTop:290-y,  
            });
        }
 });
 $(window).bind('popstate', function() {    //override back button to get the ajax content without page reload
        var toUrl=location.pathname;
        loadPage(toUrl);
 });
 $('#menu a').click(function(e){      //to get the ajax content and display in div 'main-content'
        e.preventDefault();
        var toUrl=$(this).attr('href');
        loadPage(toUrl);
        
        if(toUrl!=window.location.pathname){      //to change the browser URL to the given link location
             window.history.pushState({path:toUrl},,toUrl);
        }
 });
 PageFunction(window.location.pathname);  
 
 //tooth//
 var move=0;
 $('#toothy').on('mousedown',function(){
        move=1;
 })
 .on('mouseup',function(){
        move=0;
 });
 $(window).on('mousemove',function(e){
        if(move==0) return ;
        var x=e.clientX;
        var y=e.clientY;
        var dx=$(window).scr
        $('#toothy').css({left:x-50,top:y-50});
 });
 ////

});

var loadPage=function(toUrl){

      if($(window).scrollTop()>0) $(window).scrollTop(0);
      $.get( toUrl , function(data) {
            $('#main-content').html($(data).find('#main-content').html());
            PageFunction(toUrl);
      });

};

var PageFunction=function(toUrl){

      var y=$(window).scrollTop();
    //  $('#menu').css({'margin-top':-y+290});
      $('.header').css({'background-position': '0px 40px','background-attachment': 'scroll'});
      $('#menu > ul > li').each(function(){
              if($(this).find('a').attr('href')==toUrl){
                   $(this).addClass('now');
                   $(this).find('a > span').css({opacity: '1'});
              }
              else{
                   $(this).removeClass('now');
                   $(this).find('a > span').css({opacity: '0'});
              }
        });
      
      if(toUrl=='/Team:NYMU-Taipei/team/member'){
            teamMemFunc();
      }
      else if(toUrl=='/Team:NYMU-Taipei/team/gallery'){
            teamGalFunc();
      }
      else if(toUrl=='/Team:NYMU-Taipei'){
        //    $('#menu').css({'margin-top':-y+290});
            $('.outlink').css({'margin-top':200});
            HomeFunc();
      }
      else if(toUrl=='/Team:NYMU-Taipei/notebook/journal'){
            NbJrnlFunc();
      }

};

var teamMemFunc=function(){

      console.log('xd1');
      $('.mem_pullbar').hover(function(){
            var pic2=$(this).parent().find('.mem_pic2');
            pic2.stop(true,true).animate({ bottom: 0 , opacity : 1},500);
      },function(){
            var pic2=$(this).parent().find('.mem_pic2');
            pic2.stop(true,true).animate({ bottom: -260 , opacity : 0.5},500);
      });

};

var teamGalFunc=function(){

   var thumbs=$('.g-thumb').children();

var n=thumbs.length; var mainFrame=$('.main-img'); var nextbt=$('.g-left'); var prevbt=$('.g-right'); var nImages; var frameWidth=mainFrame.width(); var currId,prevId,nextId; var initFunction=function(){ currId=0; for(var i=0;i<n;i++){

var newDiv=$("
");

newDiv.css({'background':"url('"+thumbs.eq(i).attr('src')+"')",'left':-frameWidth}); mainFrame.append(newDiv); } nImages=mainFrame.children().not(nextbt).not(prevbt); nImages.eq(0).css({'left':0}); }; var playNextFunction=function(duration){ nextId=(currId+1)%n; nImages.eq(nextId).css({'left':frameWidth}); nImages.eq(currId).stop(true,true).animate({'left':-frameWidth},duration); nImages.eq(nextId).stop(true,true).animate({'left':0},duration); currId=nextId; }; var playPrevFunction=function(duration){ prevId=(currId-1+n)%n; nImages.eq(prevId).css({'left':-frameWidth}); nImages.eq(currId).stop(true,true).animate({'left':frameWidth},duration); nImages.eq(prevId).stop(true,true).animate({'left':0},duration); currId=prevId; };

initFunction();

     //  setInterval(playNextFunction(700),5000);

nextbt.click(function(){ playNextFunction(700); }); prevbt.click(function(){ playPrevFunction(700); });

       thumbs.click(function(){

var d=thumbs.index($(this)); var start=currId; if(d>start){ var p=(d-start+n)%n;

                  var duration=700-50*(p-1);

for(var i=0;i<p;i++) playNextFunction(duration); } else{ var p=(start-d+n)%n;

                  var duration=700-50*(p-1);

for(var i=0;i<p;i++) playPrevFunction(duration); } }); };

var HomeFunc=function(){

      $('.home1').css({'width':screen.width+225-(screen.width-1104)/2-20});

};

var NbJrnlFunc=function(){ };