To use zebedee simply add the required combination of libraries to your page
- Scriptaculous - Prototype 1.7,Scriptaculous 1.8,scriptaculous/zebedee
- Scripty2 - Prototype 1.7, Scripty2, scripty2/zebedee
- zepto - zepto,zepto/zebedee
- emile - emile,emile/zebedee,(emile/zeb-transitions, if you want the extra transition functions)
Set up your accordion as follows:
<div id="container"> <h1 class="zebedee-handle">Block 1</h1> <div class="zebedee-content"> <div> Content 1 </div> </div> <h1 class="zebedee-handle">Block 2</h1> <div class="zebedee-content"> <div> Content 2 </div> </div> <h1 class="zebedee-handle">Block 3</h1> <div class="zebedee-content"> <div> Content 3 </div> </div> </div>
var zbd = new zebedee('container');
You will need to add the following styles to your css
zebedee-content. These can be overridden in
the options. The extra nested helps smooth the animations in scriptaculous.
Zebedee has the following configurable options:
- handle -
- handleActive -
- content -
- handle -
- duration -
- transition -
'sinoidal'(The defaults and valid options depend on which library version you are using. See the version notes below for more details)
- trigger -
The scriptaculuos version is using Prototype 1.7 and Scriptaculous 1.9. I've kept the code much the same as the zepto version, but replaced the anim() calls with Effect.Scale. I've also used some of Prototype's built in utility functions to keep my code base down and avoid repeating things. However I have kept my _merge function rather than using Object.extend as my version only overwrites the final variables, rather than whole branches.
The transition option takes any valid Effect.Transitions type from Scriptaculous. Just use the last part eg. sinoidal, linear.
The scripty2 version is using the latest version from the repository as of 18/02/2011, although should work fine with the latest beta release. For the most part it is the same as the scriptaculous version, with the exception of the animation functions. I've added an internal function to get the transition type, so that it will use Css transitions where available.
The zepto version of zebedee uses Thomas Fuchs' lightweight, mobile targeting, zepto library. I'm primarily taking advantage of the dom functions and the chaining to keep my code down. The event functions also came in handy for dealing with the toggling of the accordion blocks.
Because this is using zepto and I'm intending it for the Mobile, Webkit based browsers, I was able to take advantage of the
in zepto and use css3 animations for the opening and closing of the content blocks.
The transition option takes valid CSS3 transition types.
The emile version uses Thomas Fuchs' basic animation framework emile. Because emile is purely an animation framework there are no helper functions, so I had to go back to basics for a lot of the code, and add a few css helper functions, which were borrowed from zepto.
Included with the main file are 2 basic transition types, sinusoidal and linear. If you want the full range to match scripty2 include the zeb-transitions.js file. These functions are taken from Scripty2's UI Class, which in turn is based on Robert Penner's original AS2 easing equations.
Transition options are the same as for the Scripty2 version.
In case anybody's wondering why these are all using Thomas Fuchs' frameworks, the answer is very simple. I started off using scriptaculous, with prototype, and through keeping an eye on it's development, heard about the other frameworks, which is why they were first on my list to develop for. Now that they are completed I'll be starting to look into doing versions for other frameworks, including jQuery and MooTools. If anybody has any frameworks they'd like to see a version for, either drop me a line, or feel free to fork the repo and add it yourself.
I'm using a custom attribute to store the original height of the content blocks before they're shrunk to use the animation. I've called this data-zebheight so it should be allowed by the HTML5 spec when that gets implemented. Until then, unless a better solution presents itself, it's something I'm going to have to live with.
Zebedee is still very much in the beta stage so any tips/suggestions/constructive criticism would be greatly received.