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
I am also interested in this subject and also how to maintain the status (collapsed or not) of the block after logout-login.
tnx
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.
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.
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!
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.
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.
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.)
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.
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.
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.
@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?
i have the same problem, did anybody can resolve it?
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?
The way that I explain here : http://moodle.org/mod/forum/discuss.php?d=170448 does work. I find it preferable to avoid information overload to begin with.
Fyi - I've added a feature improvement over at Moodle Tracker. Feel free to vote or watch the issue if setting the blocks as docked for all users is a feature that's of interest to you.
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
This forum post has been removed
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.
Onno Schuit's simple solution worked for me:
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)) {
This worked great for 2.6. Thank you, Seth!
Thanks.
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
@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.
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