PDA

View Full Version : Miscellaneous Hacks - Style Switcher like on vB.org


MoMan
09-03-2010, 10:00 PM
I've written a simple JS function that can be used if you want to implement a style selector like on vB.org (using colored icons instead of a dropdown).

Simply add this to vbulletin_global.js, or include it in your footer template:

function switch_style(F)
{
E = "style";
if(F == "")
{
return;
}
var B=new String(window.location);
var A=new String("");
B=B.split("#");
if(B[1])
{
A="#"+B[1]
}
B=B[0];
if(B.indexOf(E+"id=")!=-1&&is_regexp)
{
var D=new RegExp(E+"id=\\d+&?");
B=B.replace(D,"")
}
if(B.indexOf("?")==-1)
{
B+="?"
}
else
{
lastchar=B.substr(B.length-1);
if(lastchar!="&"&&lastchar!="?")
{
B+="&"
}
}
window.location=B+E+"id="+F+A
}

Then, you'd use something like this in your footer template:

<a onclick="switch_style('9');return false;" href="$vboptions[bburl]/index.php?styleid=9" rel="nofollow"><img src="$vboptions[bburl]/images/redstyle.gif" alt="" title="Red Layout" border="0" width="13" height="13" class="inlineimg" /></a>

This will then switch your style to an ID of your choice (9 in the example above). You will have to have separate styles for each color you want to switch between.

Hope someone will find this useful! Enjoy!

Silencer Groans
09-10-2010, 07:51 AM
thank

Konstantinos
10-05-2010, 07:31 PM
and what happens with styles that are only viewable by admins ?

Eduardo Leon
10-05-2010, 10:56 PM
you can give some screenshots ?

MoMan
10-19-2010, 05:35 AM
and what happens with styles that are only viewable by admins ?
Nothing would happen- the style wouldn't be selected. You obviously don't want to be creating icons for styles that aren't public.

You can view a demo here on vB.org - just try the style switcher. My implementation is the same, except that it's JS-powered.

8thos
07-22-2011, 10:00 PM
Gonna try this in vb4.1.4

8thos
07-22-2011, 10:04 PM
Hmm. Doesn't work.

HMBeaty
07-22-2011, 10:09 PM
Hmm. Doesn't work.
I could've told you that ;)

8thos
07-22-2011, 10:19 PM
I could've told you that ;)

LOL Is there one like this for vb4?

HMBeaty
07-22-2011, 10:22 PM
LOL Is there one like this for vb4?
I don't believe so.....not at the moment anyway.....

8thos
07-22-2011, 10:23 PM
I'll PM MoMan then.

great kitten
07-23-2011, 02:47 AM
screenshots please

8thos
07-23-2011, 02:57 AM
screenshots please
Scroll down to the bottom of the page. Do you see the style switcher? That's what it looks like.

8thos
07-23-2011, 11:20 AM
It works in vb4. He just gave bad directions, that's all.

Put this javascript in your headinclude or footer.

<script type="text/javascript" src="clientscript/vbulletin_global.js">
function switch_style(F)
{
E = "style";
if(F == "")
{
return;
}
var B=new String(window.location);
var A=new String("");
B=B.split("#");
if(B[1])
{
A="#"+B[1]
}
B=B[0];
if(B.indexOf(E+"id=")!=-1&&is_regexp)
{
var D=new RegExp(E+"id=\\d+&?");
B=B.replace(D,"")
}

if(B.indexOf("?")==-1)
{
B+="?"
}
else
{
lastchar=B.substr(B.length-1);
if(lastchar!="&"&&lastchar!="?")
{
B+="&"
}
}

window.location=B+E+"id="+F+A
}</script>

8thos
07-23-2011, 05:46 PM
Same code but compressed to reduce page load time.

<script type="text/javascript"src="clientscript/vbulletin_global.js">function switch_style(F)
{E="style";if(F=="")
{return;}
var B=new String(window.location);var A=new String("");B=B.split("#");if(B[1])
{A="#"+B[1]}
B=B[0];if(B.indexOf(E+"id=")!=-1&&is_regexp)
{var D=new RegExp(E+"id=\\d+&?");B=B.replace(D,"")}
if(B.indexOf("?")==-1)
{B+="?"}
else
{lastchar=B.substr(B.length-1);if(lastchar!="&"&&lastchar!="?")
{B+="&"}}
window.location=B+E+"id="+F+A}</script>

MoMan
07-26-2011, 10:04 AM
Of course it works- all this function does is it redirects your browser ;)

BTW, in your above code, you should get rid of the src="clientscript/vbulletin_global.js" attribute.

Does vb4 not use vbulletin_global.js?

dany_danay
02-18-2012, 12:31 PM
Work in vb4?How can i get this on the header?