forum.coppermine-gallery.net

Support => cpg1.3 Themes/Skins/Templates => cpg1.3.x Support => Older/other versions => cpg1.3 theme contributions => Topic started by: snork13 on July 15, 2005, 05:07:24 pm

Title: Alternate Style Sheets - How to
Post by: snork13 on July 15, 2005, 05:07:24 pm
You will need to copy your "default (style.css)" style sheet located in your theme/your_theme_name/ folder, make the changes you wish to make and rename it to "style2.css" and upload to your theme/your_theme_name folder.

add something like this to your template.html, where "your_theme_name" reflect the name of your theme

Code: [Select]
<link rel="stylesheet" href="themes/your_theme_name/style.css" / title="default">
<link rel="alternate stylesheet" type="text/css" href="themes/your_theme_name/style2.css" title="style2" />

Next in your template.html, add right before the </head> tag (very important that your links to the style sheets are above)

Code: [Select]
<script type="text/javascript" src="styleswitcher.js"></script>
</head>

Then place this code in your template.html, remember to place where you want the style choices to appear

Code: [Select]
<a href="#"
onclick="setActiveStyleSheet('default');
return false;">default</a>

<a href="#"
onclick="setActiveStyleSheet('style2');
return false;">style2</a>


last copy the code below and save as styleswitcher.js the and upload to the root gallery directory (/YOUR_GALLERY

Code: [Select]
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;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);

I found this interesting and thought I share, learn more here->http://www.alistapart.com/articles/alternate/

--snork13