From a100927cdee1e214a53af8f71505d8e6c0096432 Mon Sep 17 00:00:00 2001 From: Mark Lentczner Date: Fri, 20 Aug 2010 02:13:09 +0000 Subject: made style changing and cookies storage robust --- html/haddock-util.js | 56 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 23 deletions(-) (limited to 'html') diff --git a/html/haddock-util.js b/html/haddock-util.js index 8d43b996..5978f056 100644 --- a/html/haddock-util.js +++ b/html/haddock-util.js @@ -238,18 +238,25 @@ function postReframe() { } } -function addStyleMenu() { - var i, a, c = 0, btns = ""; - for(i=0; (a = document.getElementsByTagName("link")[i]); i++) { - if(a.getAttribute("rel").indexOf("style") != -1 - && a.getAttribute("title")) { - btns += "
  • " - + a.getAttribute("title") + "
  • " - c += 1; +function styles() { + var i, a, es = document.getElementsByTagName("link"), rs = []; + for (i = 0; a = es[i]; i++) { + if(a.rel.indexOf("style") != -1 && a.title) { + rs.push(a); } } - if (c > 1) { + return rs; +} + +function addStyleMenu() { + var as = styles(); + var i, a, btns = ""; + for(i=0; a = as[i]; i++) { + btns += "
  • " + + a.title + "
  • " + } + if (as.length > 1) { var h = "
    " + "Style ▾" + "" @@ -258,21 +265,24 @@ function addStyleMenu() { } } -function setActiveStyleSheet(href) { - var i, a, found = false; - for(i=0; (a = document.getElementsByTagName("link")[i]); i++) { - if(a.getAttribute("rel").indexOf("style") != -1 - && a.getAttribute("title")) { - a.disabled = true; - // need to do this always, some browsers are edge triggered - if(a.getAttribute("href") == href) { - a.disabled = false; - found = true; - } +function setActiveStyleSheet(title) { + var as = styles(); + var i, a, found; + for(i=0; a = as[i]; i++) { + a.disabled = true; + // need to do this always, some browsers are edge triggered + if(a.title == title) { + found = a; } } - if (!found) href = ""; - setCookie("haddock-style", href); + if (found) { + found.disabled = false; + setCookie("haddock-style", title); + } + else { + as[0].disabled = false; + clearCookie("haddock-style"); + } styleMenu(false); } -- cgit v1.2.3