vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3.8 Add-ons (https://vborg.vbsupport.ru/forumdisplay.php?f=235)
-   -   Miscellaneous Hacks - Style Switcher like on vB.org (https://vborg.vbsupport.ru/showthread.php?t=249919)

MoMan 09-03-2010 10:00 PM

Style Switcher like on vB.org
 
1 Attachment(s)
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:

Code:

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:

HTML Code:

<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

Quote:

Originally Posted by Konstantinos (Post 2107172)
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

Quote:

Originally Posted by Octavius. (Post 2223693)
Hmm. Doesn't work.

I could've told you that ;)

8thos 07-22-2011 10:19 PM

Quote:

Originally Posted by HMBeaty (Post 2223696)
I could've told you that ;)

LOL Is there one like this for vb4?

HMBeaty 07-22-2011 10:22 PM

Quote:

Originally Posted by Octavius. (Post 2223702)
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

Quote:

Originally Posted by great kitten (Post 2223775)
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.


HTML Code:

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

HTML Code:

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


All times are GMT. The time now is 06:27 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.02440 seconds
  • Memory Usage 1,757KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (3)bbcode_html_printable
  • (5)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (17)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete