SMF For Free Support Forum
Signup For Free Forum
September 06, 2008, 11:22:47 pm *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Welcome to SMF For Free. The best free SMF Host
 
   Home   Help Search Arcade Gallery Login Register  

Pages: [1] 2 3 4
  Print  
Author Topic: [Code] Stylesheet swapper for Portal Block  (Read 2723 times)
0 Members and 1 Guest are viewing this topic.
simply sibyl
not a dude
Global Moderator
*
Offline Offline

Posts: 8032


Don't PM me for Support


View Profile WWW
« on: February 09, 2008, 09:44:51 am »

Add a portal block which allows your members to choose stylesheets.

Tested for several months, in IE, Firefox, SeaMonkey, Konquerer, and Opera.


Live Demo
Note:   Although it is not on the portal on the site it - it is how it would look if you did put it in a
Portal Block.   

There are several steps.  Make sure you follow each one of them carefully.
(Suggestion:   Print this page)

Step 1: The Stylesheets

Decide which stylesheet you are going to use as your forums default style. 
Add it to your forum in Manage Styles and set it as default.  (choose it with the style picker)

Find other styles you want to use. 
Add each of them in Manage Styles. 
When adding them name them the names you want your members to see in a list when they choose them.   
(will help you to remember them when setting this up if you write the names down)

There are dozens of stylesheets, and the directions to add them to your forum here:
Stylesheet Index
Holiday Stylesheets

Step 2: The Stylesheet Code
(You are going to edit this)

The FIRST link in the code (link rel="stylesheet") = The stylesheet you chose to be the default style for your forum.
The SECOND link (link rel="alternate stylesheet") =  Additional stylesheet.

Code:

<!-- Stylesheet Swapper For Portal Block  -->
<link rel="stylesheet" type="text/css" href="http://www.smfforfree3.com/styles/sibylstestsite/enhanced.css?fin11" title="TITLE">

<link rel="alternate stylesheet" type="text/css" href="http://www.smfforfree3.com/styles/sibylstestsite/carbonfiber.css?fin11" title="TITLE">


Add more of these for each alternate stylesheet:

Code:

<link rel="alternate stylesheet" type="text/css" href="http://www.smfforfree3.com/styles/sibylstestsite/carbonfiber.css?fin11" title="TITLE">


How to edit the code:




1.  YELLOW:  Replace smfforfree3.com with YOUR forums info.
(for instance smfforfree.com, smfforfree2.com, smfforfree3.com, smfforfree4.com, mysmf.com, freesmfhosting.com)
Make certain you have this correct or it will NOT work.

2.  GREEN:  Replace sibylstestsite with the name of your forum.

3.  BLUE:    Replace enhanced with the name of your stylesheet.
 
4.  PINK:    Replace TITLE with the word you want your members to see as the choice in the portal menu  (lower case - no spaces)

Do this for all of the  stylesheets you are going to use.

After making the edits put the code at the top of your HEADER.

You are going to need all of the title names when you edit the code for the portal block.
Either write them down or keep another window open in your browser.   
It is important that the names match in both places.

Step 3:  The Script  (swaps stylesheet, sets cookie, radio selection)

Put this right underneath the stylesheet code in your HEADER.
IMPORTANT:  Do NOT change anything in the script

Code:
<!-- Script for Stylesheet Swapper DO NOT EDIT  -->
<script type='text/javascript'>
function changeStyle(title) {
var lnks = document.getElementsByTagName('link');
for (var i = lnks.length - 1; i >= 0; i--) {
if (lnks[i].getAttribute('rel').indexOf('style')> -1 && lnks[i].getAttribute('title')) {
lnks[i].disabled = true;
if (lnks[i].getAttribute('title') == title) lnks[i].disabled = false;
}}}


function switchit() {
if (readCookie('style')) { title=readCookie('style'); changeStyle(title); var radios = document.getElementById ('styleswitcher');
if (radios) {
 var inputs = radios.getElementsByTagName ('input');
 if (inputs) {
   for (var i = 0; i < inputs.length; ++i) {
     if (inputs[i].type == 'radio' && inputs[i].name == 'style')
       inputs[i].checked = inputs[i].value == (title)
   }
 }
} } }


// function topchangeStyle(title) {
// var lnks = document.getElementsByTagName('link');
// for (var i = lnks.length - 1; i >= 0; i--) {
// if (lnks[i].getAttribute('rel').indexOf('style')> -1 && lnks[i].getAttribute('title')) {
// lnks[i].disabled = true;
// if (lnks[i].getAttribute('title') == title) lnks[i].disabled = false;
// }}}




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);
</script>


Step 4: Footer Code makes radio buttons persist (FF,SM,Opera,Konquerer)

Place this code in your Footer.
 
Code:

<body onload="switchit()">




Step 5:  Set up the Portal Block

Make an html block ... name it whatever you wish.
Edit the html block.

The code below will go in the block.
Ive separated it with spaces to help you to understand it.

There is a section for each stylesheet.
 
For EACH stylesheet  do the following:
Remember to put in a choice for your default style too.

1.  change TITLE NAME to the exact same TITLE name you used in the header  (important)
     (reminder:   lowercase - no spaces)

2.  change NAME THEY SEE IN THE LIST to the word they will see in the list of choices.
    (you can name it as you wish)

Note:   I have the width of the table set to 210 as it works well on my forum that way.
You can change that to accomodate your own portal.


Code:
<style type="text/css">
fieldset { border: none !important; }
</style>

<table align=center width="210px" cellspacing="5">
<td align=left valign="top">
<form action="#" id="styleswitcher" class="styleswitcher"><small>

<input type="radio" name="style" value="TITLE NAME" onclick='changeStyle(this.value); parent.frames["top"].changeStyle(this.value)'> NAME THEY SEE IN THE LIST

<br>

<input type="radio" name="style" value="TITLE NAME" onclick='changeStyle(this.value); parent.frames["top"].changeStyle(this.value)'> NAME THEY SEE IN THE LIST


</fieldset>
</form>
</td>
</table>

Add/edit more of these for each additional stylesheet:

Code:

<input type="radio" name="style" value="TITLE NAME" onclick='changeStyle(this.value); parent.frames["top"].changeStyle(this.value)'> NAME THEY SEE IN THE LIST




thanks to:
http://www.washington.edu/webinfo/snippets/javascript/formvals.html for info on how to automagically select radio buttons
http://javascript.about.com/library/blswitch.htm for how to on using js to switch stylesheets
http://www.quirksmode.org/js/cookies.html for cookie information

« Last Edit: August 18, 2008, 10:37:28 pm by simply sibyl » Logged

LaundryLady
Global Moderator
*
Offline Offline

Posts: 3042



View Profile WWW
« Reply #1 on: February 09, 2008, 09:57:59 am »

Looks really great, Sibyl.  I can't wait to put this up after I finish my current project.
Logged

Agent Moose
Moderator
*****
Offline Offline

Posts: 628


Do not PM me for Code Support or Request


View Profile WWW
« Reply #2 on: February 09, 2008, 11:53:07 am »

Woah!  Very very nice Smiley
Logged

Eternal Flame Coming Soon

SMC Code Index - The best Code Index for all your Needs!  Includes a bunch of codes not on Support.
simply sibyl
not a dude
Global Moderator
*
Offline Offline

Posts: 8032


Don't PM me for Support


View Profile WWW
« Reply #3 on: February 09, 2008, 11:53:34 am »

1.  For each stylesheet the TITLE in both the header and portal block have to be the same.
    (lower case - no spaces)

2.  Make sure the stylesheet link address in the header code is correct.
    Easy way to find that out is to put the link in your browsers address bar and go to it.
    If it gives you the option to download the css file then you know you have the correct address.
Logged

simply sibyl
not a dude
Global Moderator
*
Offline Offline

Posts: 8032


Don't PM me for Support


View Profile WWW
« Reply #4 on: February 09, 2008, 11:54:12 am »

Woah!  Very very nice Smiley

Thanks Moose - been using it for months.  Figured it was time to share  Wink
Logged

Molly
SMF For Free Full Member
*
Offline Offline

Posts: 137



View Profile WWW
« Reply #5 on: February 26, 2008, 12:11:53 am »

I've got your denim as my default and I clicked on the space to test and well.... here ya go:


help...not supposed to be like this. what did I do wrong? Also when I click on Vista Mimic it only does part of the background lol I've got a denim pocket going down the middle  uglystupid2

Oh it will not save my link... druid.smfforfree3.com
Logged

simply sibyl
not a dude
Global Moderator
*
Offline Offline

Posts: 8032


Don't PM me for Support


View Profile WWW
« Reply #6 on: February 26, 2008, 12:23:46 am »

Sent you a reply to your pm about this   Wink
I took a look at your source code.
You have them all set to link rel="stylesheet"

You need to decide which one is going to be the forum's default stylesheet.
Set it as the default in Manage Styles using the style picker.

Leave that one, in your header code, set as link rel="stylesheet"

All of the rest of them need to be:  link rel="alternate stylesheet"

Logged

Molly
SMF For Free Full Member
*
Offline Offline

Posts: 137



View Profile WWW
« Reply #7 on: February 26, 2008, 12:26:40 am »

Sent you a reply to your pm about this   Wink
I took a look at your source code.
You have them all set to link rel="stylesheet"

Leave that one, in your header code, set as link rel="stylesheet"

All of the rest of them need to be:  link rel="alternate stylesheet"

Leave it to me to confuse a computer I resent you back the "what I think it should be" ( we see where my thinking got me the first time around  uglystupid2 ) so could you let me know?

Quote
You need to decide which one is going to be the forum's default stylesheet.
Set it as the default in Manage Styles using the style picker.
So the denim one I rename as default and edit the code and portal information where it says denim to default?

Edit: The screen as the space one still looks like the graphic above but that could be because of the "default" thing?? I will do that now.
« Last Edit: February 26, 2008, 12:28:54 am by Gwenllian » Logged

simply sibyl
not a dude
Global Moderator
*
Offline Offline

Posts: 8032


Don't PM me for Support


View Profile WWW
« Reply #8 on: February 26, 2008, 12:31:45 am »

no don't rename it.   Leave it named as denim.

In Manage styles choose "denim" with the stylepicker to set the forum to the denim style.

The other styles are alternate styles that will be chosen in the portal.
Logged

simply sibyl
not a dude
Global Moderator
*
Offline Offline

Posts: 8032


Don't PM me for Support


View Profile WWW
« Reply #9 on: February 26, 2008, 12:38:06 am »

did you resize the denim background by chance?
Its not the same size on your forum as it is on my test forum.
Looks to me that is why you are seeing it as you are there.
Logged

Molly
SMF For Free Full Member
*
Offline Offline

Posts: 137



View Profile WWW
« Reply #10 on: February 26, 2008, 12:40:21 am »

no don't rename it.   Leave it named as denim.

In Manage styles choose "denim" with the stylepicker to set the forum to the denim style.

The other styles are alternate styles that will be chosen in the portal.

Yup got that... still got that same issue around the text though with the space one. The denim in other places overides in other of the catbg and titlebg with the other stylesheets...me thinks I messed up somewhere lol 2funny
« Last Edit: February 26, 2008, 12:43:09 am by Gwenllian » Logged

Molly
SMF For Free Full Member
*
Offline Offline

Posts: 137



View Profile WWW
« Reply #11 on: February 26, 2008, 12:41:49 am »

did you resize the denim background by chance?
Its not the same size on your forum as it is on my test forum.
Looks to me that is why you are seeing it as you are there.

Only thing I did with the graphics is edit the names by adding the word denim and actually I think that one is the one that did not get changed. I never play with any of the graphics for other's stylesheets just for this reason lol


K VVV Smiley
« Last Edit: February 26, 2008, 12:45:43 am by Gwenllian » Logged

simply sibyl
not a dude
Global Moderator
*
Offline Offline

Posts: 8032


Don't PM me for Support


View Profile WWW
« Reply #12 on: February 26, 2008, 12:43:34 am »

^^ Yup got that... still got that same issue around the text though with the space one. The denim in other places overides in other of the catbg and titlebg with the other stylesheets...me thinks I messed up somewhere lol 2funny

No you didnt mess up.
I'll help you with that once we get "denim" working correctly for you.
Since you have that set as the default we need to get it correct first.
Grab the code from the stylesheet area again and use that one, not the one with your links in it.
The graphics are on my paid account..  they wont disappear  Wink

Once you've got that all set let me know and Ill tell you how to fix the others that are getting the denim "bleed thru"

Logged

simply sibyl
not a dude
Global Moderator
*
Offline Offline

Posts: 8032


Don't PM me for Support


View Profile WWW
« Reply #13 on: February 26, 2008, 12:45:54 am »

Molly..   or check your settings in Photobucket.  It is resizing the background image when you upload it.  You may need to change your PB settings so it keeps the correct size of the image.
Logged

Molly
SMF For Free Full Member
*
Offline Offline

Posts: 137



View Profile WWW
« Reply #14 on: February 26, 2008, 12:49:27 am »

I think I know what it is, it is the added part I have at the end for the .tablepad for the smileys code

Code:
.tablepad   
{
        background-image: url(http://i274.photobucket.com/albums/jj273/mollysmbon/backgrounds/gray.png);
        padding:6px;
        border: 4px solid #64604F;
}
Logged



Pages: [1] 2 3 4
  Print  
 
Jump to:  

Powered by SMF 1.1.5 | SMF © 2006-2008, Simple Machines LLC
ServerBeach Coupon
Page created in 0.279 seconds with 17 queries.