Expand/Collapse Web Parts in WSS v2
December 20, 2008 Leave a comment
While I was working on some customizations for a client’s Business Portal v3 (for Dynamics SL) installation yesterday, I needed to save some real estate within the Timecard Entry screen. We moved and customized the tmtce30.asp file to display the timecard selection blocks horizontally, and moved the web part above the Timecard Entry screen.
Now that we had more real estate to work with on the timecard, I also was looking for a way to minimize the Timecard List web part, without using the Minimize feature of the web part.
After a bit of searching, I came across this great post at the Path to SharePoint blog: http://pathtosharepoint.wordpress.com/2008/10/25/expandcollapse-buttons-for-your-web-parts/, which was built for 2007, but, I could find a way to do this in v2, as with v2, we do not have the _spBodyOnLoadFunctionNames.push() function available to us.
What I came up with is attached at the bottom of this post. A few changes were made, and there is also some commented out code in there from my attempts to get this to work. In this time card screen, we are specifying a width of the web parts on the page, so utilizing an image is not an option, as it creates a two-line (and ugly) title header for each web part.
The functionality that I had modified in the original code, is to push this into the onload events, without overwriting any onload code (I found that code somewhere, but unfortunately did not save the URL… once I get it, I will update this posting with the proper props!). Also instead of using the built-in _layouts/images/[plus|minus].gif images, the function is incorporated into a SPAN around the title, so clicking on the tile itself will expand and collapse the web part.
As for usage, just drop this file anywhere on the web part page (via importing the web part), and you should be good to go.
Hope this helps, and let me know if you have any issues.