/* * collapsor (1.0) // 2008.04.05 // * REQUIRES jQuery 1.2.3+ * Copyright (c) 2008 TrafficBroker * Licensed under GPL and MIT licenses */ (function($) { $.fn.collapsor = function(settings) { // override default settings settings = $.extend({}, $.fn.collapsor.defaults, settings); var triggers = this; // for each element return this.each(function() { // occult the collapsing elements $(this).find('+ ' + settings.sublevelElement).hide(); //show the opened if($(this).hasClass(settings.openClass)){ $(this).find('+ ' + settings.sublevelElement).show(); } // event handling $(this).click(function() { // remove the active class from all the elements less the clicked $(triggers).not($(this)).removeClass(settings.openClass); // if the new active have sublevels if ($(this).next().is(settings.sublevelElement)){ // blur and add the active class to the clicked $(this).blur().toggleClass(settings.openClass); // toggle the clicked $(this).next().animate({height:'toggle', opacity:'toggle'}, settings.speed, settings.easing); // hide the rest $(this).parent().parent().find(settings.sublevelElement).not($(this).next()).animate({height:'hide', opacity:'hide'}, settings.speed, settings.easing); return false; } }); }); }; // default settings $.fn.collapsor.defaults = { activeClass: 'active', openClass:'open', sublevelElement: 'ul', speed: 200, easing: 'swing' }; })(jQuery);