Template:Tsinghua:Navigation-Script

From 2013.igem.org

(Difference between revisions)
 
(4 intermediate revisions not shown)
Line 1: Line 1:
<html>
<html>
<script type="text/javascript">
<script type="text/javascript">
-
function setupMenu(){
+
function initialize(){
 +
$("h1.firstHeading").remove();
 +
    $("#p-logo").remove();
 +
    $("#search-controls").remove();
 +
    $("#contentSub").remove();
 +
    $("#siteSub").remove();
 +
}
 +
function setupMenu(imenuItem, isubmenuItem){
 +
//Initialize data
  //Collapse all submenus
  //Collapse all submenus
-
  $(".sub-menu").data("collapsed", true)
+
  $(".sub-menu").data("collapsed", true).hide();
-
  .hide();
+
//Show the selected menu item
-
        $("h1.firstHeading").remove();
+
var menuItem = $($(".menu-item").get(imenuItem));
-
        $("#p-logo").remove();
+
//Select the menu item
-
        $("#search-controls").remove();
+
menuItem.addClass("menu-selected");
-
        $("#contentSub").remove();
+
//Select submenu item
-
        $("#siteSub").remove();
+
var submenu = menuItem.children(".sub-menu");
 +
var hasSubmenu = (submenu.length > 0);
 +
if(hasSubmenu){
 +
  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
 +
  var parentDiv = $(this).parent();
 +
  //Deselect and collapse all other menu items
 +
  $("div.menu-item").not(parentDiv)
 +
  .removeClass("menu-selected")
 +
  .children(".sub-menu")
 +
  .data("collapsed", true)
 +
  .slideUp();
 +
  parentDiv.addClass("menu-selected");
 +
  if(hasSubmenu){
 +
  if(collapsed){
 +
    submenu.data("collapsed", false).slideDown();
 +
  }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");
 +
});
}
}
Line 22: Line 67:
     });
     });
   });
   });
-
}
 
-
 
-
//elem -- the menu-item element
 
-
function selectMenu(elem, page_title){
 
-
//Deselect all menus
 
-
$('.menu-item').removeClass('menu-selected');
 
-
//Deselect all submenu items
 
-
$('.sub-menu-item').removeClass('menu-selected');
 
-
//Select menu item
 
-
$(elem).addClass('menu-selected');
 
-
//Collapse all other submenus
 
-
$('.sub-menu').each(function(){
 
-
  if(!$(this).parent().hasClass('menu-selected')){
 
-
  $(this).data("collapsed", true).slideUp();
 
-
  }
 
-
});
 
-
//Change page title
 
-
$('#page-title').text(page_title);
 
-
//Expand the sub menu
 
-
subMenus = elem.getElementsByClassName('sub-menu');
 
-
if(subMenus.length > 0){
 
-
  submenu = subMenus[0];
 
-
  if($(submenu).data("collapsed")){
 
-
  //Expand the sub menu
 
-
  $(submenu).data("collapsed", false).slideDown();
 
-
  }else{
 
-
  //Collapse the sub menu
 
-
  $(submenu).data('collapsed', true).slideUp();
 
-
  }
 
-
}
 
-
}
 
-
 
-
//When a sub-menu-item is selected
 
-
function selectSubMenu(elem, page_title){
 
-
//Deselect all submenu items
 
-
$(".sub-menu-item").removeClass("menu-selected");
 
-
//Select current submenu item
 
-
$(elem).addClass("menu-selected");
 
-
//Change page title
 
-
$("#page-title").text(page_title);
 
}
}
</script>
</script>
</html>
</html>

Latest revision as of 08:01, 16 July 2014