About Duffbert...

Duffbert's Random Musings is a blog where I talk about whatever happens to be running through my head at any given moment... I'm Thomas Duff, and you can find out more about me here...

Email Me!

Search This Site!

Custom Search

I'm published!

Co-author of the book IBM Lotus Sametime 8 Essentials: A User's Guide
SametimeBookCoverImage.jpg

Purchase on Amazon

Co-author of the book IBM Sametime 8.5.2 Administration Guide
SametimeAdminBookCoverImage.jpg

Purchase on Amazon

MiscLinks

Visitor Count...



View My Stats

« Book Review - The Traitor by Stephen Coonts | Main| Nice evening at the O'Reilly Open Source Conference (OSCON) meeting two key people... »

Expanding/Collaping all sections on a Domino web page... bwahahahaha!

Category IBM/Lotus
It's times like this that all the book reviewing pays off...  :)

In a number of the Domino web apps I maintain, the user has the opportunity to create pages with sections in the Rich Text area.  And of course, when displayed on the web, they can open and close each of the sections.  But they wanted the ability to expand and collapse ALL the sections on the page at once.  And for the life of me, I couldn't find a Notes formula command that would do that and that was supported on the web.

The prior solution (coded by a friendly runt who will remain unnamed here  (joe)) was to use a JavaScript routine that would build a Domino URL using the ExpandSection parameter followed by a number of section numbers (1, 1.1, 1.1.1, etc.).  It didn't matter if you named more sections than necessary...  everything would still expand.  Worked OK for smaller numbers of sections on a form, but it got ugly when you had sections in sections or a large number of sections.  A URL can only be so long...

So...  The user today had an example with 45 sections on the document.  That pretty much destroyed the URL hack.  I've been sticking my toe in the DOM scripting waters of late, and I wondered if I could, via JavaScript, get all the sections of a Domino web page (regardless of the number of them), and apply a CSS style to them to expand and collapse them.  It's the same concept as the code that Domino automatically adds to the page when you have sections.  I just wanted to do them all at once instead of a section at a time.

And I was able to!!!  With my DOM Scripting book open, I was able to code the following expandAll and collapseAll functions for inclusion in a JavaScript library, and then I link to them on my web page...

function expandAll () {
    sections = document.getElementsByTagName("span");
    for (var i = 0; i < sections.length; i++) {
        var idName = sections[i].getAttribute("id");
        if (idName.substr(0,4) == "xSec") {
            sections[i].style.display = "block";
        } else if (idName.substr(0,4) == "cSec") {
            sections[i].style.display = "none";
        }
    }
}

function collapseAll () {
    sections = document.getElementsByTagName("span");
    for (var i = 0; i < sections.length; i++) {
        var idName = sections[i].getAttribute("id");
        if (idName.substr(0,4) == "xSec") {
            sections[i].style.display = "none";
        } else if (idName.substr(0,4) == "cSec") {
            sections[i].style.display = "block";
        }
    }
}

Yes, I probably could have made just one function and passed parameters, but I was flat out thrilled to get *this* much working!  The collapseAll does leave a blank line between each section on the form, so I'll have to see if I can fix that.  But the functionality works, regardless of how many sections you have on the form.  I don't care *what* the user does now...  :)

Now, I'll probably receive my first "why didn't you just use this command?" email/comment minutes after posting this, but for right now I'm feeling like a coding stud...  And after all the documentation stuff I've been doing of late, I needed something like this.

Comments

Gravatar Image1 - IMHO, you are going down the right track with your JS. It looks eerily similar to what I have for my DHTML views.

Sean---

Gravatar Image2 - 45 sections? Holy moly....

Gravatar Image3 - LOL ...I started reading the post and was thinking, "Gosh, that problem sounds familiar; I think I'd had some kind of brute force hack" ...then saw the 2nd paragraph. Yup, a few years ago in the mode of bumbling / stumbling / fumbling to get things working with time crunches of course always the norm anywhere ....like you I was glad to just get it working. THIS solution is much more elegant. Wow -- Duffbert does elegant! Who knew?

Gravatar Image4 - I can't *remember* the last time I did "elegant"... In fact, this may be the first!

And in case people are reading this and don't know the background... I took over from Joe when he left to move to Tampa. We both have been the "learn to avoid drowning" types, and we've learned a lot from each other over the years (me more from him, I feel). I bear no ill-will towards the URL hack. In fact, I expanded on it shortly after I took over...

Gravatar Image5 - Gotta love it when your user base reads and comments on your blog...

Gravatar Image6 - Computer Dude you are an 'Elegant HERO' and I appreciate you figuring this out for the users. Big wheels keep on turning.

Gravatar Image7 - I can't believe that they didn't think of adding an additional URL argument to expand/collapse all...

Anyway, the workaround worked perfect for me, didn't have any subsections to worry about though, if I ever have to deal with a document that has some it might become a bit of a problem.

Thanks for the tip !Emoticon

Gravatar Image8 - Hello, thanks a lot for the tip! Still usefull. You saved me some hours...

Post A Comment

:-D:-o:-p:-x:-(:-):-\:angry::cool::cry::emb::grin::huh::laugh::lips::rolleyes:;-)

Want to support this blog or just say thanks?

When you shop Amazon, start your shopping experience here.

When you do that, all your purchases during that session earn me an affiliate commission via the Amazon Affiliate program. You don't have to buy the book I linked you to (although I wouldn't complain!). Simply use that as your starting point.

Thanks!

Thomas "Duffbert" Duff

Ads of Relevance...