Team:WHU-China/assets/main.js

From 2014.igem.org

(Difference between revisions)
(init)
 
(4 intermediate revisions not shown)
Line 1: Line 1:
// Transition
// Transition
-
var fadeSectionTo = function ( target ) {
+
var switchMain = function ( target ) {
     current = $( "main>section.current" );
     current = $( "main>section.current" );
-
     current.fadeOut(100, function () { target.fadeIn(200) });
+
     current.slideUp();
 +
    target.slideDown();
     current.removeClass( "current" );
     current.removeClass( "current" );
     target.addClass( "current" );
     target.addClass( "current" );
};
};
-
var switchSectionTo = function ( object, ref, state, subnav ) {
+
var switchNav = function ( target ) {
-
     fadeSectionTo( object );
+
     current = $( "nav>ul>li.current" );
 +
    current.next().slideUp();
 +
    target.next().slideDown();
 +
    current.removeClass( "current" );
 +
    target.addClass( "current" );
 +
};
-
     $( "nav>ul>li" ).each(function () { $( this ).removeClass( "current" ); });
+
var switchSection = function ( sectionName ) {
-
     $( ref ).addClass( "current" );
+
     if ( $( "#" + sectionName ).is( $( "main>section.current" ) ) ) { return; }
 +
    switchMain( $( "#" + sectionName ) );
 +
     switchNav( $( "nav>ul>li." + sectionName ) );
 +
};
-
     $( "nav>ul>ul" ).slideUp(200);
+
var changeSection = function ( sectionName ) {
-
     $( subnav ).slideDown(200);
+
     if ( $( "#" + sectionName ).is( $( "main>section.current" ) ) ) { return; }
-
 
+
     switchMain( $( "#" + sectionName ) );
-
     window.history.pushState(state, "Home | iGEM: WHU-China", state);
+
    switchNav( $( "nav>ul>li." + sectionName ) );
 +
     window.history.pushState( { section: sectionName }, '', sectionName );
};
};
-
$( "nav>ul>li:nth-of-type(1)" ).click(function () {
+
$( "nav>ul>li" ).click(function () {
-
     var target = $( "#home" );
+
     sectionName = '';
-
     switchSectionTo( target, this, "home" );
+
     Names = [
-
    return false;
+
"home", "project", "results", "modeling", "achieve",
-
});
+
"practice", "team", "safety", "notebook"
-
$( "nav>ul>li:nth-of-type(2)" ).click(function () {
+
     ];
-
    var target = $( "#project" );
+
    for (i in Names) {
-
    switchSectionTo( target, this, "project", $( "nav>ul>ul:nth-of-type(1)" ) );
+
if ( $( this ).hasClass( Names[i] ) ) {
-
    return false;
+
    sectionName = Names[i];
-
});
+
}
-
$( "nav>ul>li:nth-of-type(3)" ).click(function () {
+
     }
-
    var target = $( "#achieve" );
+
 
-
    switchSectionTo( target, this, "achieve", $( "nav>ul>ul:nth-of-type(2)" ) );
+
     changeSection( sectionName );
-
    return false;
+
-
});
+
-
$( "nav>ul>li:nth-of-type(4)" ).click(function () {
+
-
    var target = $( "#safety" );
+
-
    switchSectionTo( target, this, "safety", $( "nav>ul>ul:nth-of-type(3)" ) );
+
-
     return false;
+
-
});
+
-
$( "nav>ul>li:nth-of-type(5)" ).click(function () {
+
-
    var target = $( "#practice" );
+
-
    switchSectionTo( target, this, "practice", $( "nav>ul>ul:nth-of-type(4)" ) );
+
-
    return false;
+
-
});
+
-
$( "nav>ul>li:nth-of-type(6)" ).click(function () {
+
-
    var target = $( "#notebook" );
+
-
    switchSectionTo( target, this, "notebook", $( "nav>ul>ul:nth-of-type(5)" ) );
+
-
     return false;
+
-
});
+
-
$( "nav>ul>li:nth-of-type(7)" ).click(function () {
+
-
     var target = $( "#team" );
+
-
    switchSectionTo( target, this, "team", $( "nav>ul>ul:nth-of-type(6)" ) );
+
     return false;
     return false;
});
});
 +
 +
window.onpopstate = function (event) {
 +
  if (event && event.state) {
 +
      switchSection( event.state.section );
 +
  }
 +
};
 +
 +
window.history.pushState( { section: "home"}, '' );

Latest revision as of 03:55, 18 October 2014

// Transition var switchMain = function ( target ) {

   current = $( "main>section.current" );
   current.slideUp();
   target.slideDown();
   current.removeClass( "current" );
   target.addClass( "current" );

};

var switchNav = function ( target ) {

   current = $( "nav>ul>li.current" );
   current.next().slideUp();
   target.next().slideDown();
   current.removeClass( "current" );
   target.addClass( "current" );

};

var switchSection = function ( sectionName ) {

   if ( $( "#" + sectionName ).is( $( "main>section.current" ) ) ) { return; }
   switchMain( $( "#" + sectionName ) );
   switchNav( $( "nav>ul>li." + sectionName ) );

};

var changeSection = function ( sectionName ) {

   if ( $( "#" + sectionName ).is( $( "main>section.current" ) ) ) { return; }
   switchMain( $( "#" + sectionName ) );
   switchNav( $( "nav>ul>li." + sectionName ) );
   window.history.pushState( { section: sectionName }, , sectionName );

};

$( "nav>ul>li" ).click(function () {

   sectionName = ;
   Names = [

"home", "project", "results", "modeling", "achieve", "practice", "team", "safety", "notebook"

   ];
   for (i in Names) {

if ( $( this ).hasClass( Names[i] ) ) { sectionName = Names[i]; }

   }
   changeSection( sectionName );
   return false;

});

window.onpopstate = function (event) {

 if (event && event.state) {
     switchSection( event.state.section );
 }

};

window.history.pushState( { section: "home"}, );