How to set default-state of collapse-buttons?
#1
How to set default state of collapse buttons (on homepage categories) to collapsed? (instead of expanded)

   

i see general.jw contains expander.click function. One could trigger that on page load, for each category, but that seems inefficient. 

i see the saveCollapsed function stores the collapsed state in browser. Can we create that cookie on first visit to force collapsed view? Where's best place for that? Does that function make a separate cookie for every category?

i see global.php contains the setup code, which checks the collapse cookie:
should be a way to mod or just remove this code. 
But, if i'm making a plugin, i should not alter the global.php.
Update: i deleted this code from global.php-- the page did not load in collapsed mode.

More analysis: the comment says "to automatically show them us expanded", but i believe that comment might not be accurate. Rather, what happens here is the code loops through the array of category collapse-states, and applies the user's state from previous visit.

I don't see where a default state is applied, for categories not found, or if the cookie isn't found.

Code:
// set up collapsable items (to automatically show them us expanded)
$collapsed = array('boardstats' => '', 'boardstats_e' => '', 'quickreply' => '', 'quickreply_e' => '');
$collapsedimg = $collapsed;
if($colcookie)
{
    $col = explode("|", $colcookie);
    if(!is_array($col))
    {
        $col[0] = $colcookie; // only one item
    }
    unset($collapsed);
    foreach($col as $key => $val)
    {
        $ex = $val."_e";
        $co = $val."_c";
        $collapsed[$co] = "display: show;";
        $collapsed[$ex] = "display: none;";
        $collapsedimg[$val] = "_collapsed";
        $collapsedthead[$val] = " thead_collapsed";
    }
}
Reply
#2
I've had to deal with this before. It's kind of surprising that something like this isn't standard. I wrote a plugin to deal with it, but it isn't finished yet. Basically you can use the following code:


Code:
   $plugins->add_hook('global_start', 'setCollapsedCookie');   
   $mybb->cookies['collapsed'] = trim(implode('|', $userCollapsed));
   my_setcookie("collapsed", $mybb->cookies['collapsed'];


Where $userCollapsed is an array of the categories you want to collapse. It is all done through the "collapsed" cookie. Hope that helps. If I get around to finishing my plugin that lets you set default states in the AdminCP I will post on Github for all to use.
Reply
#3
here is a jQuery based method - add in index template before </body>
PHP Code:
<script type="text/javascript">
 
jQuery(document).ready(function(){
var 
document.getElementsByClassName("expander");
 for (var 
0x.length i++) {
 
x[i].click();
}
});
</
script
Note: categories expand/collapse status toggles on refreshing the page
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)