HowTo collapse blocks by default

HowTo collapse blocks by default

by Pep p -
Number of replies: 29
Hi

I want to have the side blocks on the courses collapsed, hidden (+ , -) as default all the time. So the user can click on the block to extend its content.

I collapse all the blocks on a course, ok, then a user who login after me, go to that course and can see the blocks collapsed, ok, but if that user expand one or more blocks the next user who enter the course will see those blocks expanded, instead of all collapsed, which is what I want.

I want every user to see the blocks collapsed as default and have the choice to expand whichever he wants.

I have been playing with the files block/moodleblock.class.php and lib/javascript javascripct-static.js (function elementToggleHide) which I think are the key file but with not success

And not, it has nothing to do with allowuserblockhiding, I think

Been lookin around for a while, so any help appreciated

Kind Regards
Average of ratings: -
In reply to Pep p

Re: HowTo collapse blocks by default

by Viral Bhatt -
Have you manage to fingur this out? I am also after same thing.
In reply to Viral Bhatt

Re: HowTo collapse blocks by default

by Viral Bhatt -
I meant figure out.
In reply to Viral Bhatt

Re: HowTo collapse blocks by default

by Itay Ophir -

I am also interested in this subject and also how to maintain the status (collapsed or not) of the block after logout-login.

tnx

In reply to Viral Bhatt

Re: HowTo collapse blocks by default

by Joe Cape -
Picture of Plugin developers

er... I'm reviving an issue which I started a topic on (http://moodle.org/mod/forum/discuss.php?d=168386) but it seems like many other people are after the same thing at least in mid-2010 and didn't find an answer. I'm using Moodle 2.0.1 and would like to be able to collapse all blocks by default since it makes it easier to immediately direct new students' attention to a help feature that will explain the purpose and usage of all the blocks before they are all displayed. Has anyone found a way to do this? Thanks.

In reply to Joe Cape

Re: HowTo collapse blocks by default

by Sue Holtz -

I am also using 2.0 (now 2.0.2) and have a professor who would like to dock the blocks by default for his course only. Any help on this would be greatly appreciated.

In reply to Pep p

Re: HowTo collapse blocks by default

by Mikey McLeod -

No one seems to have an answer to this one.  There must be a simple code line change that will make the Blocks closed by default instead of open.  It sure looks a lot better from a site design perspective to have them closed.  Someone must have an answer to this issue - surely!

 

In reply to Mikey McLeod

Re: HowTo collapse blocks by default

by Seun Ojedeji -

This is a functionality i also desire to have....the list of courses on the homepage makes it look untidied. It will be good to have an auto collapse function. looking forward to anyone who can help.

In reply to Seun Ojedeji

Re: HowTo collapse blocks by default

by Mikey McLeod -

It seems very strange to me that no one can give me the PHP coding to make the blocks by default to be closed, and then stay closed until clicked.  Come on; it cannot be that difficult a thing to do!  Currently, there must be a command keeping them open.  I would really appreciate some help here.

In reply to Mikey McLeod

Re: HowTo collapse blocks by default

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Well, you have not told us whether you are using Moodle 1.9 or 2.0. It makes a difference.

In 1.9, I think it is done with JavaScript and cookies, so use Firebug to work out how the code currently works, and then you can probably work out how to change it. (I'm afraid I don't know off the top of my head.)

In reply to Tim Hunt

Re: HowTo collapse blocks by default

by Mikey McLeod -

Thanks Tim, I appreciate your reply.  I am using Moodle 1.9.  It does seem strange that most programs come with the menu collapsed, yet the Moodle developers have decided to go with the default as the menus expanded.  I wonder about the strategy for this, for the frontpage gets rather crowded looking.

In reply to Mikey McLeod

Re: HowTo collapse blocks by default

by Itamar Tzadok -

Without affirming the strategy (a flexible strategy could allow the user to set this default in different contexts) the latest news block is one reason for setting the default to expanded, otherwise the block misses its point at least in a standard course settings. smile

In reply to Itamar Tzadok

Re: HowTo collapse blocks by default

by Mikey McLeod -
Yes, I can understand why certain blocks may be better suited for being in an open format. However, what is the issue with making it an initial Administrative choice whether the blocks are open or closed for the course Participant. It is more common to have menu selections closed rather than open. Course users can decide what they want to open or close. For younger ages it may be better not to give them a choice, but for adults surely they can make the decision. The first impression of a person coming into the site the first time is important; and all blocks open make some course content not noticed for they are displayed past the opening screen and they need scroll down to see them. I guess I am advocating for choice rather than just a collapsed or open format; maybe like a setting in the block configuration.
In reply to Mikey McLeod

Re: HowTo collapse blocks by default

by Itamar Tzadok -

As always there needs to be someone to do the work. In Moodle 2 this issue is effectively addressed by allowing users to dock blocks and thereby set their default to collapsed. smile

In reply to Itamar Tzadok

Re: HowTo dock blocks by default for 2.0?

by Chad Outten -

@Itamar: yes, a user can set their blocks to dock by default in 2.0, but the initial state of the blocks is undocked.

Does anyone know if its possible to automatically dock all blocks for all users without individual users having to set that behaviour in 2.0?

In reply to Chad Outten

Re: HowTo dock blocks by default for 2.0?

by Joe Cape -
Picture of Plugin developers

I would still be keen on automatically docking all blocks and it seems that many people share this preference. The Moodle system must store the current preference of each user with regard to whether blocks are docked or undocked; I would have thought that this would be a value stored somewhere in the database.  If so, there must be a way of just setting the default value of this to the value that corresponds to the block being docked.

Has anybody found the answer?

In reply to Joe Cape

Re: HowTo dock blocks by default for 2.0?

by Carlos Sánchez Martín -
I agree with you in that theory, but so far I didn't find a way to dock the blocks by default. Pedagogically, it is more appealing to students to have the option of customizing their site view, but I think we should (could) start with the blocks docked and let them undock them if that is what they want. If anyone finds the way, please share it, at least to have the option and then deciding. Thank you, Carlos
In reply to Pep p

Re: HowTo collapse blocks by default

by William Mead -

Hi, I hate that the My courses list is always expanded when I open the the page for any given course. So I found a solution that works for me and might work for others trying to something similar. Essentially, one line of jQuery will make sure that any block that is expanded will be closed upon the load of the page.

I followed this guide for adding jQuery to my Moodle 2.0 installation:

http://docs.moodle.org/dev/Using_jQuery_with_Moodle_2.0

and I added this line into the bottom of my theme config file:

$THEME->javascripts = array("jquery-1.6.2.min", "myscript");

Then in the myscript.js file I added this jQuery:

$(document).ready(function(){
    
    $(".contains_branch p span:contains('My courses')").parents(".depth_2").addClass("collapsed");
    
    });

What this does is when the page loads, it finds the the span in the sidebar block with the content of "My courses", then goes up two levels to it's parent <li> and adds the class of "collapsed". That will collapse that block on page load.

A similar technique could be used for any errant block. I hope that helps someone.

-Bill

Average of ratings: Useful (6)
In reply to William Mead

This forum post has been removed

The content of this forum post has been removed and can no longer be accessed.
In reply to Deleted user

Re: HowTo collapse blocks by default

by Iroshini Ratnapala -

How to Collapse all the block by default- Moodle 2.2.*

After trying several options I could get this done using the following steps.

  • Download the latest JQuery file from http://docs.jquery.com/Downloading_jQuery
  • Go  to your theme folder
  • Create a folder called "javascript"
  • Include the downloaded JQuery file in that folder. ( I downloaded jquery-1.7.2.min.js)
  • Create your own js file inside the same "javascript" folder (I created myscrpt.js) and add the following line.

$(".block").removeClass("hidden");

  • Open the theme config.php and add the following line

$THEME->javascripts = array('jquery-1.7.2.min','yourfilename');

(you have to include the name of your JQuery file instead of jquery-1.7.2.min)

I could get all the blocks collapsed always. A block can never be hided with this code. 

Thanks Bill, for the idea.

Average of ratings: Useful (4)
In reply to Iroshini Ratnapala

Re: HowTo collapse blocks by default

by llywelyn morgan -

Onno Schuit's simple solution worked for me:

https://moodle.org/mod/forum/discuss.php?d=170448

In reply to llywelyn morgan

Easy working Solution

by Seth Mengal -

Easy working Solution

Onno said,

If you want all of your blocks docked by default, go to this file:

blocks/moodleblock.class.php

On line 402 (inside the function html_attributes), change the 0 to 1:

        if ($this->instance_can_be_docked() && get_user_preferences('docked_block_instance_'.$this->instance->id, 1)) {

 

 

Average of ratings: Useful (2)
In reply to Pep p

Re: HowTo collapse blocks by default

by Tech 8055 -

Hello,

By using the JavaScript to hide the block will hide the block every time irrespective of User preference.

The solutions would be to update the moodleblock.class.php file in blocks folder. Around line 260 change the default value to true.

if (empty($CFG->allowuserblockhiding
|| (empty($bc->content) && empty($bc->footer))
|| !$this->instance_can_be_collapsed()) {
$bc->collapsible = block_contents::NOT_HIDEABLE;
} else if (get_user_preferences('block' . $bc->blockinstanceid . 'hidden', true)) {
$bc->collapsible = block_contents::HIDDEN;
} else {
$bc->collapsible = block_contents::VISIBLE;
}

By changing this to true will hide the blocks by default and once the user expands the block the DB record is added and visibility will be managed by the user preference option from this point. 

Cheers

Kiran

Average of ratings: Useful (1)
In reply to Tech 8055

Re: HowTo collapse blocks by default

by Gary Lynch -

@Tech

I used your code but it only collapses the blocks and doesn't dock them to the side.

Im using 2.5 and Fusion theme.

In reply to Tech 8055

Re: HowTo collapse blocks by default

by Nathan Lind -
Picture of Particularly helpful Moodlers

Hi Kiran!

This code has promise! The one issue we are having is that blocks on the Moodle "Home" page, with Moodle non-admins not allowed to expand collapsed blocks, making them unusable. See this screenshot of what a non-admin sees:


Any updates that you can offer to address this?

Many thanks!

Nathan