Template:Tsinghua:Navigation-Script

From 2013.igem.org

(Difference between revisions)
 
(6 intermediate revisions not shown)
Line 1: Line 1:
<html>
<html>
<script type="text/javascript">
<script type="text/javascript">
-
function start(){
+
function initialize(){
-
  //Collapse all submenus
+
  $("h1.firstHeading").remove();
-
$(".sub-menu").data("collapsed", true)
+
    $("#p-logo").remove();
-
  .hide();
+
    $("#search-controls").remove();
-
        $("h1.firstHeading").remove();
+
    $("#contentSub").remove();
-
        $("#p-logo").remove();
+
    $("#siteSub").remove();
-
        $("#search-controls").remove();
+
-
        $("#contentSub").remove();
+
-
        $("#siteSub").remove();
+
}
}
-
 
+
function setupMenu(imenuItem, isubmenuItem){
-
//elem -- the menu-item element
+
  //Initialize data
-
function selectMenu(elem, page_title){
+
//Collapse all submenus
-
  //Deselect all menus
+
  $(".sub-menu").data("collapsed", true).hide();
-
  $('.menu-item').removeClass('menu-selected');
+
  //Show the selected menu item
-
  //Deselect all submenu items
+
  var menuItem = $($(".menu-item").get(imenuItem));
-
  $('.sub-menu-item').removeClass('menu-selected');
+
  //Select the menu item
-
  //Select menu item
+
  menuItem.addClass("menu-selected");
-
  $(elem).addClass('menu-selected');
+
  //Select submenu item
-
  //Collapse all other submenus
+
  var submenu = menuItem.children(".sub-menu");
-
  $('.sub-menu').each(function(){
+
var hasSubmenu = (submenu.length > 0);
-
   if(!$(this).parent().hasClass('menu-selected')){
+
if(hasSubmenu){
-
  $(this).data("collapsed", true).slideUp();
+
   submenu.data("collapsed", false).show();
 +
  var submenuItem = $(submenu.children(".sub-menu-item").get(isubmenuItem));
 +
  submenuItem.addClass("menu-selected");
 +
}
 +
//Set events
 +
$(".menu-item span").click(function(){
 +
  var submenu = $(this).next();
 +
  var hasSubmenu = (submenu.length > 0);
 +
  var collapsed = true;
 +
  if(hasSubmenu){
 +
  collapsed = submenu.data("collapsed");
   }
   }
-
});
+
  //Select and expand this menu item
-
//Change page title
+
  var parentDiv = $(this).parent();
-
$('#page-title').text(page_title);
+
  //Deselect and collapse all other menu items
-
//Expand the sub menu
+
  $("div.menu-item").not(parentDiv)
-
subMenus = elem.getElementsByClassName('sub-menu');
+
  .removeClass("menu-selected")
-
if(subMenus.length > 0){
+
  .children(".sub-menu")
-
  submenu = subMenus[0];
+
  .data("collapsed", true)
-
   if($(submenu).data("collapsed")){
+
  .slideUp();
-
   //Expand the sub menu
+
   parentDiv.addClass("menu-selected");
-
  $(submenu).data("collapsed", false).slideDown();
+
  if(hasSubmenu){
-
  }else{
+
   if(collapsed){
-
  //Collapse the sub menu
+
    submenu.data("collapsed", false).slideDown();
-
  $(submenu).data('collapsed', true).slideUp();
+
  }else{
 +
    submenu.data("collapsed", true).slideUp();
 +
  }
   }
   }
-
  }
+
  });
 +
$("div.sub-menu-item").click(function(){
 +
  //Deselect other submenu items
 +
  $("div.sub-menu-item").removeClass("menu-selected");
 +
  //Select this submenu item
 +
  $(this).addClass("menu-selected");
 +
});
}
}
-
//When a sub-menu-item is selected
+
function setupSectionNavs(){
-
function selectSubMenu(elem, page_title){
+
  $(document).ready(function() {
-
  //Deselect all submenu items
+
    $("div.section").hide();
-
$(".sub-menu-item").removeClass("menu-selected");
+
    $("div.section1").show();
-
//Select current submenu item
+
    $("#section-nav li").click(function() {
-
$(elem).addClass("menu-selected");
+
    $("div.section").hide();
-
//Change page title
+
    var sectionName = $(this).attr("class");
-
$("#page-title").text(page_title);
+
    $("div." + sectionName).show();
 +
    });
 +
  });
}
}
</script>
</script>
</html>
</html>

Latest revision as of 08:01, 16 July 2014