Template:Dev jquery


// This is the jquery part of your template. Try not modify any of this code since it makes your menu work.

$(document).ready(function() {

$("#HQ_page").attr('id',); $("#page_name").html( wgPageName.substring ( wgPageName.lastIndexOf("/")+1 , wgPageName.length ));


load_hubmenu ("Resources");

$(".pop_up").click(function() { $(".page_cover").toggleClass("cover_visible"); $(".pop_up_box").toggleClass("box_visible"); });

$(".page_cover").click(function() { $(".page_cover").toggleClass("cover_visible"); $(".pop_up_box").toggleClass("box_visible"); });


// to use this function send the "source page" and then send the div's id to where you want to send it load_these_items ( "https://2016.igem.org/Archive #load_these_newsItems", "load_newsItems_here");


$("#switch_between_menus").click(function() {

if ( $("#switch_between_menus").hasClass( "hubmenus") ) { console.log ( " Currently showing hubmenu menu, switching to main menu"); $(this).toggleClass("hubmenus"); $(".hubmenu_list").hide(); $(".main_menu_list").show(); place_root_page ( "https://2016.igem.org/Main_Page", "Main Menu" , "main_menu" ); load_these_items ("https://2016.igem.org/HQ:Menu #MainPage_menu_demo", "main_menu_list");


}

else { console.log ( " Currently showing main menu, switching to hubmenu"); $(this).toggleClass("hubmenus"); $(".hubmenu_list").show(); $(".main_menu_list").hide(); place_root_page ( "https://2016.igem.org/"+"Resources", "Resources" , "hubmenu" ); } });


});




function load_these_items ( source_page , destination_div ) {

$("#"+destination_div ).load( source_page , function() {

$(".collapse_control").click(function() { $(this).next().toggle();

if ( $(".menu_wrapper").height() > ( $(window).height() -100 ) ) { $(".menu_wrapper").css('position', 'absolute'); }

});


}); }


function load_hubmenu (page_name) {


var page_url = "https://2016.igem.org/wiki/index.php?title=Special%3AAllPages&from="+page_name+ "&to="+page_name+"ZZZ&namespace=0";

$.get(page_url).then(function(page_html) { var $link_page = $(page_html);


$link_page.find('.mw-allpages-chunk li').each(function () { sort_pages( $(this).text(), $(this).html() ); });

});

}


function sort_pages ( page_name , page_link ) {

// if it is not a redirect if( page_link.indexOf("mw-redirect") <= 0) {

switch ( ( page_name.match( /\//g ) || []).length ) { // check number of "/"

case 0: //main root place_root_page ( page_name , (page_name.substring( page_name.lastIndexOf("/")+1 , page_name.length ) ).replace( /_/g , " ") , page_name.replace( / /g , "_") ); break;

case 1: //second tier place_nested_pages ( page_name , (page_name.substring( page_name.lastIndexOf("/")+1 , page_name.length ) ).replace( /_/g , " ") , page_name.replace( /\//g , "-").replace( / /g , "_"), "ol" ); break;

default: //other place_nested_pages ( page_name , (page_name.substring( page_name.lastIndexOf("/")+1 , page_name.length ) ).replace( /_/g , " ") , page_name.replace( /\//g , "-").replace( / /g , "_"), "ul" ); break; }

} }



function place_root_page ( page_href, clean_name, name_for_id ) {

//modify link $("#current_hub_menu").attr("href", "/"+page_href)

//modify text $("#current_hub_menu").text( clean_name );

//modify ol's id $("#hubmenu_list").attr('id', name_for_id ); }


function place_nested_pages (page_href, clean_name, name_for_id , which_list ) {

var constructed_append = "";

constructed_append ="
  • <a href='/"+page_href +" '>"+clean_name+"</a>"; if ( which_list == "ol" ) { constructed_append = constructed_append + "
    1. ";

      }

      else {

      constructed_append = constructed_append + "
        </li>";

        }

        $("#"+name_for_id.substring(0, name_for_id.lastIndexOf("-") ) ).append( constructed_append );

        }