PDA

View Full Version : Can Styleswitch.js be changed to always return to default style.



DMforHim
04-09-2014, 02:57 AM
Is there a way to change Styleswitch.js so that a refresh returns the user back to the default state?
Currently, the last choice selected remains when returning to the page. Even an F5 refresh does not revert back to the default.
This may be desirable for some, but for the design I am working on, I would rather have it always default back to the original style.
Would this be possible. This is what I have coded in currently:


<link rel="stylesheet" type="text/css" href="css/drs-style_default.css" />
<link rel="alternate stylesheet" type="text/css" media="screen" title="white-theme" href="css/drs-style_white-non-serif.css" />
<link rel="alternate stylesheet" type="text/css" media="screen" title="white-theme-serif" href="css/drs-style_white-serif.css" />
<link rel="alternate stylesheet" type="text/css" media="screen" title="black-theme" href="css/drs-style_black-non-serif.css"/>
<link rel="alternate stylesheet" type="text/css" media="screen" title="black-theme-serif" href="css/drs-style_black-serif.css"/>
<script src="js/styleswitch.js" type="text/javascript">

/***********************************************
* Style Sheet Switcher v1.1- Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for this script and 100s more
***********************************************/
</script>
</head>

<body>
<div class="container">
<div class="row">
<div class="col-md-12">
<form id="switchform">
<select name="switchcontrol" size="1" class="form-control" onChange="chooseStyle(this.options[this.selectedIndex].value, 60)">
<option value="none" selected="selected">Default style</option>
<option value="white-theme">White Theme</option>
<option value="white-theme-serif">White Theme - serif</option>
<option value="black-theme">Black Theme</option>
<option value="black-theme-serif">Black Theme - serif</option>
</select>
</form>
</div>
</div>

jscheuer1
04-09-2014, 04:11 AM
For (in styleswitch.js):


var manual_or_random="manual" //"manual" or "random"

leave that as is ("manual"). Also in the same file find:


function chooseStyle(styletitle, days){ //Interface function to switch style sheets plus save "title" attr of selected stylesheet to cookie
if (document.getElementById){
setStylesheet(styletitle)
setCookie("mysheet", styletitle, days)
}
}

Using a text only editor like NotePad, add the highlighted red comment tokens as shown:


function chooseStyle(styletitle, days){ //Interface function to switch style sheets plus save "title" attr of selected stylesheet to cookie
if (document.getElementById){
setStylesheet(styletitle)
//setCookie("mysheet", styletitle, days)
}
}

Save and use that version.

You will have to clear the current cookie (if any).

And the browser cache may need to be cleared and/or the page refreshed to see changes.