PDA

View Full Version : ALA's Style Switcher - dynamically create lists?



takethetrain
August 17th, 2006, 01:37 PM
I'm using ALA's Alternative Style: Working With Alternate Style Sheets code to switch between my alternate stylesheets. With the JavaScript code in place, you would normally switch a stylesheet by clicking on a link, but I would like to place them dynamically so I don't have to list each one.
(Note: I am omitting the part involving cookies because I won't need them later on--this is irrelevent, though.)

Normally, to change a stylesheet, you'd just have a link on a page accessing the javascript functions, like this:


<a href="#" onclick="setActiveStyleSheet('default'); return false;">change style to default</a>


Here is the JavaScript code I'm using:


function setActiveStyleSheet(title) {
var i, a, main;
for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
a.disabled = true;
if(a.getAttribute("title") == title) a.disabled = false;
}
}
}
function getActiveStyleSheet() {
var i, a;
for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled)
return a.getAttribute("title");
}
return null;
}
function getPreferredStyleSheet() {
var i, a;
for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("rel").indexOf("alt") == -1 && a.getAttribute("title"))
return a.getAttribute("title");
}
return null;
}
window.onload = function(e) {
var title = getPreferredStyleSheet();
setActiveStyleSheet(title);
}


How do I alter this code to create my links dynamically?

takethetrain
August 17th, 2006, 01:38 PM
Oops--here's a link to ALA's tutorial: http://www.alistapart.com/articles/alternate

takethetrain
August 18th, 2006, 09:08 AM
Anyone at all? :/