Alternate Style Sheets - How to Alternate Style Sheets - How to
 

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Main Menu

Alternate Style Sheets - How to

Started by snork13, July 15, 2005, 05:07:24 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

snork13

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

<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)

<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

<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

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