Template:Tsinghua:Navigation-Script

From 2013.igem.org

(Difference between revisions)
(Created page with "<html> <script type="text/javascript"> function start(){ //Collapse all submenus $(".sub-menu").data("collapsed", true) .hide(); $("h1.firstHeading").remove(); ...")
 
(7 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");
-
//Change page title
+
}
-
$('#page-title').text(page_title);
+
//Set events
-
//Expand the sub menu
+
$(".menu-item span").click(function(){
-
subMenus = elem.getElementsByClassName('sub-menu');
+
  var submenu = $(this).next();
-
if(subMenus.length > 0){
+
  var hasSubmenu = (submenu.length > 0);
-
submenu = subMenus[0];
+
  var collapsed = true;
-
if($(submenu).data("collapsed")){
+
  if(hasSubmenu){
-
//Expand the sub menu
+
  collapsed = submenu.data("collapsed");
-
$(submenu).data("collapsed", false).slideDown();
+
  }
-
}else{
+
  //Select and expand this menu item
-
//Collapse the sub menu
+
  var parentDiv = $(this).parent();
-
$(submenu).data('collapsed', true).slideUp();
+
  //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");
 +
});
}
}
-
//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