Team:TU Delft/menu test
From 2010.igem.org
(Difference between revisions)
Line 80: | Line 80: | ||
var activePage = "</html>{{{contentpage|home}}}<html>"; | var activePage = "</html>{{{contentpage|home}}}<html>"; | ||
+ | |||
+ | var pageCache = {}; | ||
+ | |||
+ | function getPageURL(page) { | ||
+ | return "https://2010.igem.org/Team:TU_Delft/pages/" + page + "?action=render"; | ||
+ | } | ||
function setupPage(page) { | function setupPage(page) { | ||
var btn= $(".menu_button_" + page); | var btn= $(".menu_button_" + page); | ||
- | var pageURL = | + | var pageURL = getPageURL(page); |
btn.click(function(event) { | btn.click(function(event) { | ||
var cpw = $("#content_page_wrap"); | var cpw = $("#content_page_wrap"); | ||
cpw.fadeOut(200); | cpw.fadeOut(200); | ||
event.preventDefault(); | event.preventDefault(); | ||
+ | |||
+ | if (isUndefined(pageCache[page])) { | ||
$.get(pageURL, function(data) { | $.get(pageURL, function(data) { | ||
+ | pageCache[page]=data; | ||
cpw.html(data); | cpw.html(data); | ||
cpw.fadeIn(200); | cpw.fadeIn(200); | ||
}); | }); | ||
+ | } | ||
+ | else { | ||
+ | cpw.html(pageCache[page]); | ||
+ | cpw.fadeIn(200); | ||
+ | } | ||
$(".menu_button_" + activePage).removeClass("menu_button_"+activePage+"_sel"); | $(".menu_button_" + activePage).removeClass("menu_button_"+activePage+"_sel"); | ||
Line 119: | Line 133: | ||
var pages = [ "home", "blog", "competition", "background", "project", "education", "sponsors", "press" ]; | var pages = [ "home", "blog", "competition", "background", "project", "education", "sponsors", "press" ]; | ||
for(var i in pages) { | for(var i in pages) { | ||
+ | var page = pages[i]; | ||
setupPage(pages[i]); | setupPage(pages[i]); | ||
+ | $.get(getPageURL(page), function(data) { | ||
+ | pageCache[page] = data; | ||
+ | }); | ||
} | } | ||
}); | }); |
Revision as of 13:52, 5 June 2010