linear

[« terragen] [Main Index] [rainbow country »]

theme picker is go for launch

06/01/2001

All right! Try out the theme picker in the left-hand floating nav bar. I'm persisting color choices between pages using cookies set in the JavaScript. I had to redo the logo, but I think I have something that will look passable against light and dark backgrounds. Plus it's a much smaller file.

Here's the JavaScript that's doing the customization. The getCookie and setCookie functions are pretty much blatant steals from the Netscape documentation, with a little customization of my own thrown in.


function colorize(pri, sec, ter) {
divs = document.getElementsByTagName('div');
document.getElementsByTagName('body')[0].style.backgroundColor = pri;
divs[0].style.color = ter;
for (var i = 1; i < divs.length; i++) {
el = divs[i];
if (el.className == 'entry' || el.id == 'navBar'){
divs[i].style.backgroundColor = sec;
}
divs[i].style.color = ter;
}
setCookie('pri', pri);
setCookie('sec', sec);
setCookie('ter', ter);
}

function checkprefs(){
var pri = getCookie('pri');
var sec = getCookie('sec');
var ter = getCookie('ter');
if (pri) {
colorize(pri, sec, ter);
}
}

// Sets cookie values. Expiration date is optional//
function setCookie(name, value, expire) {
document.cookie = name + "=" + escape(value) + "; path=/"
+ ((expire == null) ? "" : ("; expires=" + expire.toGMTString()));
}

function getCookie(Name) {
var search = Name + "="
if (document.cookie.length > 0) {
// if there are any cookies
offset = document.cookie.indexOf(search) ;
if (offset != -1) {
// if cookie exists
offset += search.length ;
// set index of beginning of value
end = document.cookie.indexOf(";", offset) ;
// set index of end of cookie value
if (end == -1) end = document.cookie.length;
return unescape(document.cookie.substring(offset, end));
}
}
}


text, scripts and images copyright © 2001-2011 . All rights reserved.