Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 05-04-2011, 12:04 PM
richy96's Avatar
richy96 richy96 is offline
 
Join Date: Apr 2008
Location: England
Posts: 93
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Set modules to be expanded to collapsed dependant on some condition

Hi
hopefully the title explains this but anyway:

What I want to do is set things so that some of the modules that make up the vb pages are either expanded or collapsed dependant on some condition in the template

I am using code based on this generic stuff for expandable sections
Code:
<tbody>
	<tr>
		<td class="thead">
			<a style="float:$stylevar[right]" href="#top" onclick="return toggle_collapse('give_a_table_id')"><img id="collapseimg_give_a_table_id" src="$stylevar[imgdir_button]/collapse_thead$vbcollapse[collapseimg_give_a_table_id].gif" alt="" border="0" /></a>
			any information this is the header
		</td>
	</tr>
</tbody>
<tbody id="collapseobj_give_a_table_id" style="$vbcollapse[collapseobj_give_a_table_id]">
	<tr>
		<td class="alt2">any information inside the module</td>
	</tr>
</tbody>
It works but I must admit I don't really understand what makes it expand and collapse (like the generated html source looks the same in my browser regardless)

Anyway what I want to do in my templates is something like

<if condition = something or other>
display module expanded when page is generated
<else>
display module collapsed when page is generated


Obviously the user can still collapse/expand manually using the little chevrons

How do I go about doing that?

cheers
Rich
Reply With Quote
  #2  
Old 05-04-2011, 01:02 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

The blocks are expanded and collapsed by setting the style to "display:none" or not. The state for each block for a user is saved in a cookie that has a list of collapsed blocks. If you look in global.php and search for "read the list of collapsed menus" (around line 57) you can see where it gets the cookie info and sets the $vbcollapse[] to "display:none". So you could probably override that in your template by not using $vbcollapse['collapseobj_whatever'] as the style, or unset()ing it before the page is generated. (same goes for collapseimg_ and collapsecel_ of course. I think collapseimg_ is for the button image, I don't know what collapsecel_ is offhand). But, since that doesn't change the cookie, it would go back to the saved state if the override condition went away (which maybe is what you want, I don't know).

After the page is loaded the blocks are toggled by javascript setting the display property. I think you maybe could set the block to open by iserting a call to toggle_collapse('tableid', 'open') like

Code:
<if condition="something">
<script type="text/javascript">toggle_collapse('tableid', 'open')</script>
</if>

somewhere in the template for that page (it might have to be in a function that gets run after the page is completely loaded, I don't know). I haven't tried this so I don't know if that will end up changing the cookie or not.

I suppose another option if you want to change the saved cookie value in the php script would be to alter the string to take out your tableid and then set a new cookie value (can't remember what that call is offhand).
Reply With Quote
  #3  
Old 05-04-2011, 08:53 PM
richy96's Avatar
richy96 richy96 is offline
 
Join Date: Apr 2008
Location: England
Posts: 93
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks for that info kh99 (or Bob isn't it if i remember right)

OK problem solved

What I did is set the $vbcollapse[] in my php like below, immediately before eval(ing) the modules template


if (whatever condition)
{
$vbcollapse['collapseobj_name_of_this_module'] = ""; // this displays the module expanded
}
else
{
$vbcollapse['collapseobj_name_of_this_module'] = "display:none;"; // this displays the module collapsed
}

and it does exactly what I wanted, automagically overriding the users preference dependant on the condition being true or not, but not changing the cookie settings either way.


Cheers m8
Rich
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 12:47 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.03534 seconds
  • Memory Usage 2,179KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (2)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (3)post_thanks_box
  • (3)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (3)post_thanks_postbit_info
  • (3)postbit
  • (3)postbit_onlinestatus
  • (3)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete