Update: As a result of some great feedback I got from a new mootools forum, I added two more features and even ended up shortening the code in the process. Now, the “_toggle” element automatically gets a cursor pointer, and toggle-o-matic supports multiple toggles from one slide control. Read on to learn more.
Often, I have found myself in the middle of a web design project, needing to add the slide effect to multiple elements. For a project I did a while ago (back in the dark ages when I was still using jquery), I created a simple function that would create multiple slide elements by adding the class “anything_toggle” to the toggle control and “anything_slide” to the element I wanted to slide.
Here is that same function for mootools 1.2:
Imagine your web design has a single set of instructions that you want to toggle:
Or you want to have a single control open and toggle multiple elements:
With the Toggle-o-matic code in your website, that is all you have to do.
Check out a live demo of the toggle-o-matic v0.2 here.
Install mootools 1.2, then copy and paste the code before the </head> tag in your html file, or save it as a .js and pull it in.
To integrate this code into your web design, all you have to do is call in the function as a file or in the head tag.
var toggleOmatic = function() { var toggleAll = $(document.body).getElements('[class$=_toggle]'); toggleAll.each(function(item){ item.setStyle('cursor', 'pointer'); var toggleAllClass = item.getProperty('class'); toggleAllClass = toggleAllClass.replace("_toggle", ""); var slideAllClass = toggleAllClass + "_slide"; var slideAll = $(document.body).getElements('.' + slideAllClass); slideAll.slide('hide'); $(item).addEvent('click', function(){ slideAll.slide(); }); }); } window.addEvent('domready', function() { toggleOmatic(); });
You can put the toggle class “*_toggle” in any element, and you can add the “*_slide” FX to one or more web design elements that you want to slide. See an example below.
<a class="this_toggle" href="#">Toggle</a> <div class="this_slide">Toggle this element</div> <a class="abunch_toggle" href="#">Toggle</a> <div class="abunch_slide">Toggle many elements</div> <div class="abunch_slide">Toggle multiple elements</div> <div class="abunch_slide">Multiple element toggle</div>
*Including the mootools 1.2 core, the mootools 1.2 “more” library, the ‘Toggle-o-matic’ javascript file, and a simple html file.
Download mootools toggle-o-matic v0.1 here
You can use this however you like, and please drop me a comment letting me know if you use it in your web development project and what you think.
Thanks and I hope you find it as useful as I have.

This work is dedicated to the Public Domain.