Team:NYMU-Taipei/menu.js

From 2014.igem.org

Revision as of 16:46, 13 October 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('>span').css({'display':'block',opacity: '1'});
           $(this).find('>ul').stop(true,true).animate({width: "130px" }, 300);
       })
      .on('mouseleave',function(){
           $(this).find('>span').css({'display':'none',opacity: '1'});
           $(this).find('>ul').stop(true,true).animate({ width: "0px" }, 300);
       });
 $('#menu > ul > li > ul > li > ul > li')
      .on('mouseenter',function(){
           $(this).find('>span').css({'display':'block',opacity: '1'});
       })
      .on('mouseleave',function(){
           $(this).find('>span').css({'display':'none',opacity: '1'});
       });
 $(window).scroll(function (event){
        var y = $(window).scrollTop();
        if(y>510){
            $('#menu').css({'position':'fixed','margin-top':0});
        }
        else{
            $('#menu').css({'position':'absolute','margin-top':'510px'});
        }
 });
 $(window).bind('popstate', function() {    //override back button to get the ajax content without page reload
        var toUrl=location.pathname;
        loadPage(toUrl);
 });
 $('#menu a').add('#menu4home 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);
        }
 });
 $('#menu4home>a').hover(
       function(){
           var index=$('#menu4home>a').index(this);
           $('.teethS').eq(index).css({'display':'block'});
       },function(){
           var index=$('#menu4home>a').index(this);
           $('.teethS').eq(index).css({'display':'none'});
 });
 PageFunction(window.location.pathname);  
 //jumpup//
 $('#jumpup').on('click',function(){
   if(location.pathname.split('/').length==2){ //is home
       $('body').animate({scrollTop: 0},500);
   } else {
       $('body').animate({scrollTop: 510},500);
   }
 });
 //tooth//
 var move=0;
 $('#toothy').on('mousedown',function(){
        move=1;
 })
 .on('mouseup',function(){
        move=0;
 });
 $('#toothy').children().on('mousedown',function(e){e.stopPropagation();});
 $(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});
 });
 questionGameFunction();
 ////

/*/////////////////////// style1 stuff ///////////////////////////////////////////

 var clickcloud=0;
 $('#cloud>div').click(function(){
     clickcloud=1;
     $('#cloud').stop(true,true).animate({'top':'-200px'},700);
     $('#cloud>div').stop(true,true).animate({'top':'115px'},700);
     $('#clickthecloud').stop(true,true).animate({opacity:0},400);
 })
 .on('mouseleave',function(){
     if(clickcloud==0) return ;
     $('#cloud').stop(true,true).animate({'top':'-85px'},700);
     $('#cloud>div').stop(true,true).animate({'top':'0px'},700);
     $('#clickthecloud').stop(true,true).animate({opacity:1},1400);
 });

//////////////////////////////////////////////////////////////////////////////////*/ });

var loadPage=function(toUrl){

      $('#main-content').stop(true,true).animate({'opacity':'0'},700);
   //     $('#main-content').stop(true,true).slideUp(700);
      $.get( toUrl , function(data) {
            $('#main-content').stop(true,true).animate({'opacity':'1'},400);
     //       $('#main-content').stop(true,true).slideDown(400);
            if(toUrl.split('/').length==2){ //to home
                $('body').animate({scrollTop: 0},400);
            } else if($('body').scrollTop()>510){
                $('body').animate({scrollTop: 510},400);
            }
            $('#main-content').html($(data).find('#main-content').html());
            PageFunction(toUrl);
      });

};

var PageFunction=function(toUrl){

      $('.header').css({'background-position': '20% 40px','background-attachment': 'scroll'});
      $('#menu').css({'display':'block'});
      $('#main-content').css({'background':'rgba(255,255,255,0.95)'});
      $('#menu4home').css({'display':'none'});
      $('#menu > ul > li').each(function(){
              var des=$(this).find('a').attr('href').split('/');
              var res=toUrl.split('/');
              if(des[2]==res[2]){
                   $(this).addClass('now');
                   $(this).find('a > span').css({opacity: '1'});
              }
              else{
                   $(this).removeClass('now');
                   $(this).find('a > span').css({opacity: '0'});
              }
        });
      var scrollFunc = function(){
            var toAnchor=$(this).attr('href');
            //50 is the height of menu
            var toTop = $(toAnchor).offset().top - 50;
            if(toTop < 0) toTop = 0;
            $('body').animate({ scrollTop: toTop}, 0); 
            return false;
      };
      $('.cont-panel > div').click(scrollFunc);
      $('div.protocol-panel a').click(scrollFunc);
      if(toUrl=='/Team:NYMU-Taipei'){
            $('#main-content').addClass('no-border');
      } else {
            $('#main-content').removeClass('no-border');
      }
      var splitUrl=toUrl.split('/');
    
      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({'display':'none'});
            $('#menu4home').css({'display':'block'});
            //$('#main-content').css({'background':'rgba(255,255,255,0)'});
            HomeFunc();
      }
      else if(toUrl=='/Team:NYMU-Taipei/notebook/labnotes'){
            NbNotesFunc();
      }
      else if(splitUrl[1]=='Team:NYMU-Taipei'&&splitUrl[2]=='modeling'){
            MdlMathFunc();
      }

};

var contentAjax=function(){

      $('#main-content a:not([href^="#"])').click(function(e){
            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);
            }
      });

}

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=800; 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')+"') 50% 50% no-repeat",'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();

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

       thumbs.click(function(){

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

                  var duration=700;

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

                  var duration=1000;
for(var i=0;i

510){ $('#tabframe').css({'position':'fixed','top':'147px'}); } else{ $('#tabframe').css({'position':'absolute','top':'100px'}); } /* if($('#tabframe').offset().top-70>$('#labnote').height()){ $('#tabframe').css({'position':'absolute','top':$('#labnote').height()-270}); } */ }); $('.note-tab').click(function(){ $(window).scrollTop(490); var show='#'+$(this).attr('id')+'-cont'; $('.notenow').css({'display':'none'}); $('.notenow').removeClass('notenow'); $(show).css({'display':'block'}); $(show).addClass('notenow'); }); }; var MdlMathFunc=function(){ MathJax.Hub.Typeset(); contentAjax(); } var questionGameFunction=function(){ var data; var dialog=$('#dialog'); var qnaNextBt=$('#qnaNextBt'); var qnaPrevBt=$('#qnaPrevBt'); var closeBt=$('#qnaClose'); var openBt=$('#convopen'); var status=0; var qId=-3; $.getJSON('/Team:NYMU-Taipei/QnAgame.json?action=raw',function(Jdata){ data=Jdata; }); var showResponce=function(res){ var s; if(res){ //yes s='<p>yay :)

';

} else{ //no

s='

oh, not right.

';

} dialog.html(s); }

var showQuestion=function(){ var s;

s="

"+data[qId]["Q"]+"


";

for(var i=0;i<data[qId]["S"].length;i++){ s+="<input type='radio' name='op' value='"+i+"'>"; s+=data[qId]["S"][i]; s+="
"; } dialog.html(s); }

       var startConv=function(){
               if(qId==-3)
                   qnaPrevBt.css({'display':'none'});
               else
                   qnaPrevBt.css({'display':'block'});
var s=["

Hi, my name is toothy, Nice to meet you :). Welcome to the wiki page of NYMU-Taipei in iGEM 2014.Our project this year is 'TACKLE TOOTH'.

","

By visiting our wiki, you can get more information.However, I have some questions and need your help. You can find all the answers in our wiki.

","

You can drag me to anyplace in the website. If you think I am a little annoying, just put me to the corner(hope you won't do so). Anyway, just explore and have fun!!

"];

dialog.html(s[qId+3]); status=0;

       }   
       var endConv=function(){
var s="

Hope you have a good time visiting our wiki. Enjoy it!

";
               dialog.html(s);
               qnaNextBt.css({'display':'none'});
       }

qnaNextBt.click(function(){

               if(qId<0){   //start mode
                       qId++;
                       if(qId<0){
                           startConv();
                           return ;
                       }
                       else{
                           showQuestion(qId);
                       }
               }

if(status){ //question mode var p=$('input[name="op"]:checked').val(); showResponce( p==data[qId]["A"] ? 1:0 );

                       qId++;

} else{ //response mode

                       if(qId>=data.length){
                             endConv();
                       }

else{

                             showQuestion(qId);
                       }
		}

status=1-status;

               qnaPrevBt.css({'display':'block'});

}); qnaPrevBt.click(function(){

               qId--;
               if(qId<0){
                       startConv();
                       return ;
               }
               status=1;
               showQuestion(qId);
               qnaNextBt.css({'display':'block'});
       });
       closeBt.click(function(){
               dialog.css({'display':'none'});
               qnaNextBt.css({'display':'none'});
               qnaPrevBt.css({'display':'none'});
               closeBt.css({'display':'none'});
               openBt.css({'display':'block'});
       });
       openBt.click(function(){
               dialog.css({'display':'block'});
               qnaNextBt.css({'display':'block'});
               qnaPrevBt.css({'display':'block'});
               closeBt.css({'display':'block'});
               openBt.css({'display':'none'});
       });
       startConv();

};