Template:Tsinghua:Navigation-Script
From 2013.igem.org
(Difference between revisions)
Line 2: | Line 2: | ||
<script type="text/javascript"> | <script type="text/javascript"> | ||
function initialize(){ | function initialize(){ | ||
- | + | $("h1.firstHeading").remove(); | |
$("#p-logo").remove(); | $("#p-logo").remove(); | ||
$("#search-controls").remove(); | $("#search-controls").remove(); | ||
Line 9: | Line 9: | ||
} | } | ||
function setupMenu(imenuItem, isubmenuItem){ | function setupMenu(imenuItem, isubmenuItem){ | ||
- | + | //Initialize data | |
- | + | //Collapse all submenus | |
- | + | $(".sub-menu").data("collapsed", true).hide(); | |
- | + | //Show the selected menu item | |
- | + | var menuItem = $($(".menu-item").get(imenuItem)); | |
- | + | //Select the menu item | |
- | + | menuItem.addClass("menu-selected"); | |
- | + | //Select submenu item | |
- | + | 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"); | ||
+ | }); | ||
} | } | ||
function setupSectionNavs(){ | function setupSectionNavs(){ | ||
- | + | $(document).ready(function() { | |
- | + | $("div.section").hide(); | |
- | + | $("div.section1").show(); | |
- | + | $("#section-nav li").click(function() { | |
- | + | $("div.section").hide(); | |
- | + | var sectionName = $(this).attr("class"); | |
- | + | $("div." + sectionName).show(); | |
- | + | }); | |
- | + | }); | |
} | } | ||
</script> | </script> | ||
</html> | </html> |
Revision as of 11:22, 27 September 2013