From b4915e8f387bdc0e0fb40a67b41de8fbacb32da6 Mon Sep 17 00:00:00 2001 From: David Waern Date: Sat, 1 Oct 2011 01:41:13 +0200 Subject: Merge in darcs pach: Mon Apr 11 18:09:54 JST 2011 Liyang HU * Remember collapsed sections in index.html / haddock-util.js --- html/haddock-util.js | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'html') diff --git a/html/haddock-util.js b/html/haddock-util.js index 4a7e4255..9a6fccf7 100644 --- a/html/haddock-util.js +++ b/html/haddock-util.js @@ -50,11 +50,43 @@ toggleCollapser = makeClassToggle("collapser", "expander"); function toggleSection(id) { - var b = toggleShow(document.getElementById("section." + id)) - toggleCollapser(document.getElementById("control." + id), b) + var b = toggleShow(document.getElementById("section." + id)); + toggleCollapser(document.getElementById("control." + id), b); + rememberCollapsed(id, b); return b; } +var collapsed = {}; +function rememberCollapsed(id, b) +{ + if(b) + delete collapsed[id] + else + collapsed[id] = null; + + var sections = []; + for(var i in collapsed) + { + if(collapsed.hasOwnProperty(i)) + sections.push(i); + } + // cookie specific to this page; don't use setCookie which sets path=/ + document.cookie = "collapsed=" + escape(sections.join('+')); +} + +function restoreCollapsed() +{ + var cookie = getCookie("collapsed"); + if(!cookie) + return; + + var ids = cookie.split('+'); + for(var i in ids) + { + if(document.getElementById("section." + ids[i])) + toggleSection(ids[i]); + } +} function setCookie(name, value) { document.cookie = name + "=" + escape(value) + ";path=/;"; @@ -307,5 +339,6 @@ function pageLoad() { addStyleMenu(); adjustForFrames(); resetStyle(); + restoreCollapsed(); } -- cgit v1.2.3