Skip to content

Instantly share code, notes, and snippets.

@Comandeer
Created July 15, 2015 14:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Comandeer/f5ba1005e58a58982220 to your computer and use it in GitHub Desktop.
Save Comandeer/f5ba1005e58a58982220 to your computer and use it in GitHub Desktop.
Multiple accordion
/**
* Multiple accordion
* It extends jQuery UI Accordion 1.11.x (Copyright 2015 jQuery Foundation and other contributors)
* Shamely created by Comandeer, released under MIT license
*/
(function($)
{
var _create = $.ui.accordion.prototype._create
,_toggle = $.ui.accordion.prototype._toggle;
$.extend($.ui.accordion.prototype, {
_create: function()
{
var options = this.options;
if(options.multiple && !options.collapsible)
options.collapsible = true;
_create.call(this);
var active = this.element.find('.ui-accordion-content').eq(options.active);
this.shown = [];
if(active.is(':visible'))
this.shown.push(active[0]);
}
,_toggle: function(obj)
{
if(!this.options.multiple)
return _toggle.call(this, obj);
var active = this.element.find('.ui-accordion-content').eq(this.options.active)
,prev = this.prevShow
,toChange = obj.newPanel.length ? obj.newPanel : (prev.length ? prev : active)
,i = this.shown.indexOf(toChange[0]);
this.prevShow = this.prevHide = $([]);
if(i !== -1)
{
obj.oldHeader = obj.newHeader;
obj.oldPanel = toChange;
obj.newPanel = obj.newHeader = $([]);
this.shown.splice(i, 1);
}
else
{
obj.oldHeader = obj.oldPanel = $([]);
this.shown.push(obj.newPanel[0]);
}
_toggle.call(this, obj);
}
});
}(jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment