The other day I posted the question,
http://drupal.org/node/35672
after a couple of days of work, and adding some things. I have a very elegent and workable solution. You can check out www.matthewedmunds.com/aurora for a working example. In order to get the result, I first modified my template (using xtemplate, hope to switch to phptemplate soon), adding a unique id to the content div of the block, mine being content-module-delta, to make sure that nothing had the same id tag. Once each block had its own content ID, that allowed for a div toggle of just the content of the block, leaving the title.
For the simplest solution, you can then take the nice css/javascript code provided on drupal art:
http://www.drupalart.org/togglediv
Which is what got me started. However, once realizing the power that can be had, I dreamed of an icon that could sit in the corner of the block title, and allow for the toggle, changing the image related to the state that div was in. Also needed was the ability to remember the state of a collapsed, or open block from page to page, while a user is navigating through the site. I found that after a little googling, and drupal searching to see if anyone else has ventured here before. I was told the logintobbogin module had a similar setup, but it didnt provide what I wanted from a simple, across the board implentation, not hacking every other mod I have.
I found, a dynamic drive script, Switch Content II, which provides all the necessary functionality. It remembers states.. by default, page to page (I'll get to that in a sec). It allows for an image to give a graphical representation of a state, currently plus or minus, and it allows for the toggle of divs and interesting enough, other ids. So you can really use it for other interesting concepts... e.g. toggling a whole sidebar of blocks if desired. And it played nice with other scripts I'm running.
The script was changed to remove page data from the cookie, to make it only go sitewide. Which is helpful because most of my blocks are run through the whole site. It can still however remember those that are only on certain pages, as that info will exist in the cookie, even if the block is being hidden by drupal to only appear in certain areas. Therefore allowing users customization.
All I did to call the script, is replace the div in the href, with that of the same setup for how the content id would appear, so they would be identical, therefore allowing the script to be coded to every block on the page, to only collapse/expand the block its associated with. Thus adding functionality to every block that will ever be used, or in the future added, without the task of having to modify each block individually.
If there is interest, I'd be glad to post the modified code, and style sheet.
Comments
Could this lead to a portlet-like block?
Could this lead to a portlet-like block where blocks could be minimised and maximised based on user preferences/cookies?
The concept could be taken one step further where a block that is not mandatory could have a 'remove' option - thus updating the user's preferences - not just a cookie.
I, for one, would find the script and CSS interesting.
Paddy.
http://deburca.org, and http://amadain.net
Paddy.
http://deburca.org
Lovely
Very good touch to use a cookie to keep state, it makes it an actually useful feature.
However it's a shame the content still comes down with the page-load, even when 'off'. No easy fix for that, I know.
I don't suppose anyone's done a user-configurable-custom blocks module yet, like Slash, Yahoo and Google News ...
REALLY nice theme, love the shades, although it seems to load a bit slow for me. But everything is doing that for me today, so it might be OK.
Certainly some inspiration there.
.dan.
.dan. is the New Zealand Drupal Developer working on Government Web Standards
An xtempalte theme already available
Check adc theme. It has a collapsable blocks feature.
Sunny
www.gleez.com
php
Actually, ADC is a phptemplate (and a great one I say...)
--
Tips for posting to the forums
look interesting. i'd also
look interesting. i'd also like to get those script and css files. thanks.
Working on page load...
My site does load slow, mostly my host, might move. Also running a lot of javascript so that I'm sure is probably a factor as well.
As for the code, I'm working on seeing if I can fix how the script loads, to do its work before the page is rendered to the browser, not onload. So that should solve the issue of the block staying open which is the default state, and then closing after the javascript grabs the saved state from the cookie.
If anyone has insight into that, that would be helpful, I know some scripts have been written to do that, namely sIFR, got an email into Shaun who's an old college buddy, seeing if he can lend a hand.
Also having some issues with code filter in regards to posting a more detailed walkthrough, in that it is having an issue with the img tag for the toggle states that I want to show.
If anyone has suggestions on that, let me know.
When its done I'll post it. Til then, email me if you have any thoughts or want the files.
Final Version
After a little more work, I think I finally got it, I've gotten some requests for how to implement on phptemplate, (as far as I could figure the adc theme doesn't save states from page to page) so that would be an added addition, and I'm looking into it.
If anyone can offer help with phptemplate, that would be great.
The files can be found at:
http://www.matthewedmunds.com/aurora/filestore2/download/85/sweeptoggle.rar
Included is a readme that outlines the 4 steps (I'd post it here, but code tags have never liked me on the drupal forums.)
Its pretty simple really, I know someone else is working on a block bar similar to this for 4.7.. to my knowledge it was plagued with the original div render issue. In that since the code is called after page load, after the page is rendered, the menu content would intially show, then be hidden.
I was able to fix that with a call to the function to load the script prior to the end of the page. Allowing it do its work just before the page is shown. Meaning, it just works.
I have a couple other tweaks if interested, sIFR, javascript top nav menus, and the view original image link for pics opens up another window with the original image, sized to the image so it doesn't break fixed width's designs.
All of these are simple tweaks, and I can post those as well if there is interest.
I'm a designer and an artist before a coder, so these things have all come from a usability and functionality standpoint first.