jQuery.fn.accordion = function(obj) {
var accordion = this;
jQuery(obj["headCSS"]).click(obj["onClick"]);
obj["speed"] = obj["speed"] || 500;
jQuery(obj["contentCSS"], this).hide();
jQuery(obj["headCSS"], this).click(function() {
var show = jQuery(this).next();
var part2 = function() {
if(show.not(":visible")) show.slideDown(obj["speed"] || 500); obj["onShow"] && obj["onShow"](show[0]);
};
jQuery(obj["contentCSS"] + ":visible", accordion).slideUp( obj["speed"] ); obj["onHide"] && obj["onHide"](this);
setTimeout(part2, obj["synch"] ? obj["speed"] : 0);
});
};
jQuery.fn.accordion takes a hash:
headCSS: the CSS selector that indicates what will be used for the clickable items ("dt", "h1", " h2.head", etc.)
contentCSS: the CSS selector that indicates what will be used for the body items
speed: The speed of the animations
synch: Whether the animation should be synchronous or aynchronous (true for synchronous)
onHide: A callback for the hiding of a node (will pass the node as a parameter)
onShow: A callback for the showing of a node (will pass the node as a parameter)
onClick: A callback for the clicking of a header (binds a regular event handler to the header, which means it will have the same "this" variable as regular event handlers)
What do you think?
-- Yehuda
On 10/27/06, Jörn Zaefferer <[EMAIL PROTECTED]> wrote:
Yehuda Katz schrieb:
> I've done a bunch of Accordion implementations for various projects,
> but never codified them into a single plugin. I suspect it could be
> done with much less code than some of the existing implementations.
> What are the requirements for a totally abstracted accordion plugin?
It should rely on a certain hierachical structure, instead of any
concrete elements. That way it could treat these just the same:
<dl class="accordion">
<dt>Title</dt>
<dd>Content</dd>
</dl>
<div class="accordion">
<h2>Title</h2>
<p>Content</p>
</div>
It should allow customization of animations, to an extend that it allows
to specify wheather show and hide animations should be run at the same
time or should be queued.
It should accept event listeners for changes in the accordion, like
click, show or hide. Best would be to use jQuery's event system for this
instead of custom callbacks. This is more of an implementation detail,
but I think it's an important one.
--
Jörn Zaefferer
http://bassistance.de
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/
--
Yehuda Katz
Web Developer | Wycats Designs
(ph) 718.877.1325
_______________________________________________ jQuery mailing list [email protected] http://jquery.com/discuss/
