Dream Portal is a portal system designed to function with Simple Machines Forum (aka SMF).

It allows you to easily manage your site and webpages in an SMF environment. Place Modules on different actions and non-actions of your SMF forum using a simple drag-and-drop approach. Users can also create and save multiple layouts by name and assign pages to any layout(s). Bundled with Dream Pages and Dream Menu helps put the power and ease of customizing your SMF forum right at your fingertips.

Dream Portal allows you the ability to easily customize your SMF forum and site with many different possibilities helping to make customization truly what dreams are made of!

DreamPortal1.0.5.zip
File size: 221KB
Download count: 1662
DreamPortal1.0.5.tar.gz
File size: 176KB
Download count: 159
Download
Hello, Guest
Please login or register.

 
 
 

Did you miss your activation email?

Re: Menübutton lassen sich nicht löschen.
Last Poster: Tony_R in German on May 14, 2012, 10:18:03 AM


hat mir auch geholfen, vielen dank !

Re: Sologhost went mad. Check this fast!
Last Poster: ThoTh in Chit Chat on May 13, 2012, 03:07:02 PM


Congrats :D

Re: Think I have Everything I need
Last Poster: SoLoGHoST in Chit Chat on May 09, 2012, 01:36:37 PM



Your Recent Image Attachments...
Last Poster: SoLoGHoST in Team Blog on May 07, 2012, 04:13:46 AM


Well, just thought I'd let you all know of the ability to see your 15 most recent image attachments

Re: Inspire Romance
Last Poster: SoLoGHoST in Website Showcase on May 03, 2012, 12:34:22 PM


Looks great!! :)

Author Topic: Expand/Collapse Anything - The Dream Portal Way!  (Read 2232 times)

0 Members and 1 Guest are viewing this topic.

SoLoGHoST

  • Lead Developer
  • Developer
  • Constant Sleeper
  • *
  • Posts: 2081
  • Wanted... DEAD or ALIVE!
    • Dream Portal
Expand/Collapse Anything - The Dream Portal Way!
« on: February 22, 2011, 05:54:50 PM »
Ok, so this is just a simple How-To for those people who want to use Dream Portal's Animated Expand/Collapse on anything!

Ok, if you don't have a layout assigned on the action/nonaction for where you want your animated divs, you'll need to add dreamportal.js into the header or in the body...

Code: [Select]
$context['html_headers'] .= '
<script type="text/javascript" src="' . $settings['default_theme_url'] . '/scripts/dreamportal.js"></script>
<script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
loadInfo(\'' . ($user_info['is_guest'] ? '0' : '1') . '\', \'' . $settings['images_url'] . '\', \'' . $context['session_id'] . '\');
// ]]></script>';

It may be a better idea to set a variable to determine if the file_exists before applying it.  Because, lets say you uninstall Dream Portal, there will be errors if you don't check for file existence, So we can do this Something like so, instead:

Code: [Select]
// Is Dream Portal Installed?
if (file_exists($boarddir . '/Themes/default/scripts/dreamportal.js'))
{
$context['dp_installed'] = true;
$context['html_headers'] .= '
<script type="text/javascript" src="' . $settings['default_theme_url'] . '/scripts/dreamportal.js"></script>
<script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
loadInfo(\'' . ($user_info['is_guest'] ? '0' : '1') . '\', \'' . $settings['images_url'] . '\', \'' . $context['session_id'] . '\');
// ]]></script>';
}
else
$context['dp_installed'] = false;

Also, if we don't have any Dream Portal layout assigned to this page, we'll also need to call loadInfo in the header as well.  loadInfo is defined in dreamportal.js.  1st parameter is 0 for guest, 1 for member, URL to images directory to switch the expand/collapse images, and the members session id, if exists.

Bytheway, the above code should be placed into the Source file since you are adding headers.

Ok, now that we have that bit of stuff done, we can now begin to add the actual code into the template.  This is the FUN part, and how it all comes together.  Let's create a default template function, and place in our first bit of code for finding out if it should be expanded/collapsed (we'll call it $dp_box, but you can call it anything ofcourse):

Code: [Select]
function template_main()
{
     global $user_info,  $context, $settings, $options;

     if ($context['dp_installed'])
$dp_box['is_collapsed'] = $context['user']['is_guest'] ? !empty($_COOKIE['examplemodule_1']) : !empty($options['examplemodule_1']);

    // More code to follow here...


Ok, what is this and what does it do??

We set the cookie or the $options variable to true or false, for both guests and members.

Break down of examplemodule_1:
example - This is the first part of the key, this can be anything you want.  You'll need to use it later on for your ID values.
module_ - This MUST NOT change, it always must be module_ because dreamportal.js uses this string as the middle string for this.
1 - This is the ID for this, IT MUST BE AN INTEGER VALUE, since dreamportal.js does a parseInt() on this part of the key.  This comes in handy for loops.  For example, let's say you have a loop like so:
Code: [Select]
// Just an example of how you could implement a for loop structure for more than 1 animated box.
for($i=0;$i<count($variables) - 1; ++$i)
{
if ($context['dp_installed'])
$dp_box['is_collapsed'][$i] = $context['user']['is_guest'] ? !empty($_COOKIE['examplemodule_' . $i]) : !empty($options['examplemodule_' . $i]);

     // The rest of the code for displaying the box can be placed in here, and it should display all boxes.
}
Now you can use the value of $i and have more than 1 box, but I suppose we are getting ahead of ourselves now.  Let's take a step back and show you how to do this for only 1 box.


Ok, now back to the code itself.  Here's more code that is added to  function template_main():

Code: [Select]

    // Beginning our <div> element(s) now.
    echo '
<div id="dp_examplemodule_1" class="cat_bar', (($context['dp_installed'] && !$dp_box['is_collapsed']) || !$context['dp_installed'] ? ' block_header"' : '"'), '>

    // More code to follow here...


First <div id=dp_examplemodule_1>
We don't want to set the class to block_header unless the box is to be expanded according to the cookie (guest) or $options (member).

Code: [Select]
<h3 class="catbg">';

if ($context['dp_installed'])
{

echo '
<span class="floatright" onclick="toggleModuleAnim(\'example\', \'1\', \'3\');">
<img id="examplecollapse_1" class="dp_curveblock hand" src="' . $settings['images_url'] . '/' . ($dp_box['is_collapsed'] ? 'expand' : 'collapse') . '.gif" alt="">
</span>
Dream Portal Animation Style';
}
else
{
echo '
<span class="left" />
A box without using Dream Portals Animation effects!
</span>';
}

    // More code to follow here...


Ok, so we are inputting the header of the box in here.  "Dream Portal Animation Style" is the title that should get displayed.
We call the function toggleModuleAnim() from within dreamportal.js.
1st parameter = "example" This is what we defined the first part of the cookie/$options remember?
2nd parameter = "1" This is the 3rd part of the cookie/$options.
3rd parameter = "3" This is responsible for setting the SPEED of the animation for collapsing/expanding.  The higher the speed, the faster it goes, the lower the speed, the slower it goes.
   
Than we also set the image to display by default and define the id of the image.
id="examplecollapse_1"
"example", from the 1st part of the cookie/$options.
"collapse_", this is REQUIRED and MUST be in there for it to work!
"1", this is from the 3rd part of the cookie/$options.

Ok, for the final bit of code we close off the head </h3> and <div> and place in the body <div>

Code: [Select]
echo '
</h3>
</div>
<div id="examplemodule_1"', ($context['dp_installed'] && $dp_box['is_collapsed'] ? ' style="display: none;"' : ''), '>
<div class="roundframe blockframe">
In here lies the BODY CONTENT of your BOX!
ENJOY!
</div>
<span class="lowerframe"><span></span></span>
</div>
<br class="clear" />';

    // ALL DONE!  TADA!
}

The body <div id="examplemodule_1">
"example" = 1st part of the cookie/$options
"module_" = MUST BE DEFINED exactly as this!
"1" = 3rd part of the cookie/$options

And within the div we begin the roundframe blockframe class and input anything we want into it, input the lowerframe span after that and close the <div>.
We set a <br class="clear" /> so that if there is anything else below that box, it won't be too close to the bottom edge of the box.

THAT IS ALL THERE IS TO IT!

NOW FOR THE Complete Template function!

Code: [Select]
function template_main()
{
     global $user_info, $context, $settings, $options;

     if ($context['dp_installed'])
$dp_box['is_collapsed'] = $context['user']['is_guest'] ? !empty($_COOKIE['examplemodule_1']) : !empty($options['examplemodule_1']);

    // Beginning our <div> element(s) now.
    echo '
<div id="dp_examplemodule_1" class="cat_bar', (($context['dp_installed'] && !$dp_box['is_collapsed']) || !$context['dp_installed'] ? ' block_header"' : '"'), '>
<h3 class="catbg">';

if ($context['dp_installed'])
{

echo '
<span class="floatright" onclick="toggleModuleAnim(\'example\', \'1\', \'3\');">
<img id="examplecollapse_1" class="dp_curveblock hand" src="' . $settings['images_url'] . '/' . ($dp_box['is_collapsed'] ? 'expand' : 'collapse') . '.gif" alt="">
</span>
Dream Portal Animation Style';
}
else
{
echo '
<span class="left" />
A box without using Dream Portals Animation effects!
</span>';
}

echo '
</h3>
</div>
<div id="examplemodule_1"', ($context['dp_installed'] && $dp_box['is_collapsed'] ? ' style="display: none;"' : ''), '>
<div class="roundframe blockframe">
In here lies the BODY CONTENT of your BOX!
ENJOY!
</div>
<span class="lowerframe"><span></span></span>
</div>
<br class="clear" />';

    // ALL DONE!  TADA!
}

Ok, so this box is using examplemodule_1 to store the cookie's name or $options[] key index.  It is important for this to be a unique value, so you wouldn't want to use example again, unless you plan on changing the 1 to another number.  This stays unique, unless you actually want another box to be affected by the collapse/expand state that is set within the $_COOKIE (guest) or $options (members) variables.

Enjoy! :)
« Last Edit: March 02, 2011, 01:59:13 PM by SoLoGHoST »
#1
*
SoLoGHoST
  • Constant Sleeper
  • Posts: 2081
Have just now applied this to the Forum Categories here at DP.NET!  Ofcourse, you'll have to be a registered member here at DP.net to see this in action.

Cheers and ENJOY.  Great thing about this, is that it will remember which boards are collapsed/expanded and you don't have to worry about reloading another page (as what SMF does naturally) and it slides up and down quite nicely ofcourse :)
Last Edit: February 22, 2011, 10:23:58 PM by SoLoGHoST

#2
*
willemjan
  • Constant Sleeper
  • Posts: 1453
Looks cool!! ;D

#3
*
SoLoGHoST
  • Constant Sleeper
  • Posts: 2081
Thanks, thinking on whether this would look good or not for posts within topics.  Going to try it in a few days or so and see if I like it.

#4
*
willemjan
  • Constant Sleeper
  • Posts: 1453
You forgot the info center btw ;)

#5
*
SoLoGHoST
  • Constant Sleeper
  • Posts: 2081
Yeah, wasn't a priority of mine at that time since the only different would be the animation effect.  But thanks, will apply it if you think it would look better...

#6
*
willemjan
  • Constant Sleeper
  • Posts: 1453
Yeah, I do think it would look better ;)

#7
**
Rudi
  • Day Dreamer
  • Posts: 16
This tutorial is awesome as like Dream Portal :D

Thank you, Solomon :)
There's a line beetwen genius and crazyness. I deleted this line.

#8
*
SoLoGHoST
  • Constant Sleeper
  • Posts: 2081
Cheers, and glad you like it.  Was a lot of fun writing :)

#9
*
Xarcell
  • Constant Sleeper
  • Posts: 1081
I don't know if something changed in DP or what since you wrote this. I tried following your tutorial to start with, but kept having problems with the whole thing disappearing after collapse, plus cookies didn't seem to be working. So then I just tried coping your code exactly, and the images don't show for some reason.

Just to test, try putting the code into a custom module and you'll see what I mean.

#10
*
SoLoGHoST
  • Constant Sleeper
  • Posts: 2081
That's because I did not code this in mind for pages that already have layouts assigned to them.  This was coded for pages that don't have any layouts assigned to them.  What you are most likely facing is an undefined $context['dp_installed'] variable, which won't exist unless you add it.  I'll take a look for you and see if I can give you a working example of a way to do this within a module right now...

#11
*
SoLoGHoST
  • Constant Sleeper
  • Posts: 2081
Ohh, I see what the problem is, you are using the Custom Module to do this right?  And I have transferred certain functions over to Subs-DreamModules.php for recycling purposes.  Will fix this tomorrow, cause I'm with my daughter today, so tomorrow it will be.

Cheers :)

#12
*
Xarcell
  • Constant Sleeper
  • Posts: 1081
Ohh, I see what the problem is, you are using the Custom Module to do this right?  And I have transferred certain functions over to Subs-DreamModules.php for recycling purposes.  Will fix this tomorrow, cause I'm with my daughter today, so tomorrow it will be.

Cheers :)


Yes, I tried using this in a module I'm making and tried testing it in a custom module.

#13
*
SoLoGHoST
  • Constant Sleeper
  • Posts: 2081
Ok, so getting back to this topic now.

In Dream Portal 1.1, if there is an error in your PHP Syntax for the Custom Module, Dream Pages, etc., etc., it will be left EMPTY, and nothing will show so as to prevent your page from causing undesirable results.  So you must be sure there is NO error in your PHP Syntax.

So, now to give you working code of how to do this within a Custom Module, or any other module for that matter.  Example Code, just copy and paste into the Custom Module (make sure to select PHP for the syntax, ofcourse):

Code: [Select]
global $context, $settings, $options;

$dp_box['is_collapsed'] = $context['user']['is_guest'] ? !empty($_COOKIE['examplemodule_1']) : !empty($options['examplemodule_1']);

// Beginning our <div> element(s) now.
echo '
<div id="dp_examplemodule_1" class="cat_bar', (!$dp_box['is_collapsed'] ? ' block_header"' : '"'), '>
<h3 class="catbg">
<span class="floatright" onclick="toggleModuleAnim(\'example\', \'1\', \'3\');">
<img id="examplecollapse_1" class="dp_curveblock hand" src="' . $settings['images_url'] . '/' . ($dp_box['is_collapsed'] ? 'expand' : 'collapse') . '.gif" alt="">
</span>
Dream Portal Animation Style
</h3>
</div>
<div id="examplemodule_1"', ($dp_box['is_collapsed'] ? ' style="display: none;"' : ''), '>
<div class="roundframe blockframe">
In here lies the BODY CONTENT of your BOX!
ENJOY!
</div>
<span class="lowerframe"><span></span></span>
</div>';

Cheers :)

Example of this working can be found here:  http://smf201.dream-portal.net/index.php
Last Edit: January 12, 2012, 10:13:41 AM by SoLoGHoST

#14
*
Xarcell
  • Constant Sleeper
  • Posts: 1081
Thanks SoLo. It works, except that the cookie isn't working? If I collapse, then refresh, it is expanded again.
Last Edit: January 12, 2012, 11:37:17 AM by Xarcell


 

SHOUTBOX NOT FOR SUPPORT!

 Forum Staff