Advanced search  

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Pages: [1]   Go Down

Author Topic: Alternate Style Sheets - How to  (Read 7244 times)

0 Members and 1 Guest are viewing this topic.

snork13

  • Contributor
  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 260
  • Internet! Is that thing still around?
    • Gallery
Alternate Style Sheets - How to
« 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

« Last Edit: August 21, 2005, 09:08:48 am by GauGau »
Logged
Pages: [1]   Go Up
 

Page created in 0.016 seconds with 19 queries.