vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=251)
-   -   Custom Style Chooser (https://vborg.vbsupport.ru/showthread.php?t=270942)

Bestrafung 09-26-2011 05:04 PM

Custom Style Chooser
 
I'm trying to setup a custom style chooser and following some advice found on these forums (I forget where) I was able to move the Style Changer from the footer to the top links. We are only using two styles, one narrow and one wide, and we want a radio button selector instead of a drop down. The original code is:
Code:

<form action="{vb:link forumhome|nosession}" method="get" id="footer_select">
<vb:if condition="$show['quickchooser']">
<select name="styleid" onchange="switch_id(this, 'style')">
<optgroup label="{vb:rawphrase quick_style_chooser}">
{vb:raw quickchooserbits}
</optgroup>
</select>
</vb:if>
</form>

and the radio button code I tried is:
Code:

<form action="{vb:link forumhome|nosession}" method="get" id="footer_select">
<vb:if condition="$show['quickchooser']">
<input type="radio" name="styleid" value="5" onChange="switch_id(this, 'style')"/>
Narrow (Default)
<input type="radio" name="styleid" value="4" onChange="switch_id(this, 'style')"/>
Wide
</vb:if>
</form>

If anyone has any ideas I'd greatly appreciate it. I'm still trying to figure it out but I'm not very good with code like this.

BirdOPrey5 09-26-2011 07:21 PM

Unfortunately the JavaScript function switch_id is hard coded to use a <select> input and just won't work with any other type of input. You'd need to rewrite the function or make a new one to work with radio buttons.

FYI - this is the javascript function in question:

PHP Code:

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



BirdOPrey5 09-26-2011 07:38 PM

OK so if you add this javascript to your template:

PHP Code:

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

And then change the calls in your code from switch_id to switch_id2 it will work.


All times are GMT. The time now is 06:25 AM.

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.01013 seconds
  • Memory Usage 1,746KB
  • 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
  • (2)bbcode_code_printable
  • (2)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (3)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