TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
Stats
  • Total Posts: 196,021
  • Total Topics: 21,332
  • Online today: 582
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 140
  • Total: 140

If statement based on collapsed sidebars

Started by itsacoaster, July 20, 2007, 02:49:45 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

itsacoaster

Hello,

I'm writing a script that tells lower-resolution monitors to collapse the sidebars.  But I only want it to work if both sidebars aren't collapsed.  (That is, if one or both sidebars are collapsed, the script doesn't work.)

How would I write an if statement in index.template.php to check if the sidebars are collapsed?

TP 0.98, SMF 1.1.3, if it makes a difference.

(Just in case you were wondering, the script that checks the screen resolution and prints the message will be JavaScript.)

Zetan

It will help us if you post the script you are using.

itsacoaster

#2
All I need to know is how to check if both sidebars AREN'T collapsed.  I don't know if that would be done with PHP or Javascript.  But here's what I would put inside that if statement.

<script language="JavaScript">
<!--
if (screen.width < 1024) {
document.write("Here's the code where I will tell the user to collapse the sidebars.")
}
--></script>


In case you don't understand, here's some random pseudocode:

If LeftBarCollapsed == RightBarCollapsed == False {
If ScreenWidth < 1024 {
Display "Here's where I tell the user to collapse the sidebars."
}}

Zetan

I understand exactly what you are trying to do, so, no need for random made up words like "pseudocode"..
10 Brownie points for that one though ;)

I'm not sure how you would detect if the left / right panels are open or closed. I know you can detect the screen resolution and colour depth.
When one of the Coders on the Team come online. They may be able to help.

I suggested posting the code so people can see what it's doing, but, if it's a big secret...

IchBin

Not sure if this will work:


if ($context['TPortal']['leftbar'] == 0 && $context['TPortal']['rightbar'] == 0)
{
Your code in here
}


if this doesn't work let me know. Things have changed in TP 1.0 so I'll have to look at the arrays to see what info is being passed.

itsacoaster

#5
That got close.  This evidently checks to see if the sidebars are visible on the page.  For example, if you have in your settings that the sidebars shouldn't be shown on Admin or Profile pages, the code I entered will appear on those pages.  Here's what I use:

if ($context['TPortal']['leftbar'] == 0 && $context['TPortal']['rightbar'] == 0)
{
echo '
<script language="JavaScript"><!--
if (screen.width < 1024) {
document.write(\'<div style="width: 681px; margin-bottom: 5px; background-color: #ffff99; text-align: center; color: #000000;">If you are having trouble viewing this page, click the <img src="Themes/babylon/images/upshrink.gif" /> buttons to collapse the sidebars.</div>\')
}
--></script>
';
}

And Zetan, pseudocode is a real word.  However, I will take the brownie points and run.  Muhahaha!

IchBin

I'm not sure if leftpanel is exists in TP 0.9.8 so you can try that instead of leftbar. Same with the rightpanel. If it works then great. If not, I'll have to figure out something else. :)

bloc

You could in fact collapse them on the spot..if the resolution is less than 1024 for example. This code, I am not sure it works, but do try:

<script language="JavaScript"><!--
if (screen.width < 1024)
{
    shrinkHeaderRightbar(true);
    shrinkHeaderLeftbar(true);
}
--></script>


It doesn't check if indeed both bars are present(but not shrinked) though.

itsacoaster

Thank you both for your suggestions!

Another thing I could do is create a JavaScript cookie which disables the message at the top after it's viewed once, or after it's disabled by the user.

This website is proudly hosted on Crocweb Cloud Website Hosting.