Skip to content

Instantly share code, notes, and snippets.

@eric-miller2129
Last active August 29, 2015 14:19
Show Gist options
  • Save eric-miller2129/daf2e4ca6df4f1ac5b19 to your computer and use it in GitHub Desktop.
Save eric-miller2129/daf2e4ca6df4f1ac5b19 to your computer and use it in GitHub Desktop.
(function($){
'use strict';
var Accordion = function(elem){
var _this = this;
_this.elems = {
title: elem.find('.title'),
content: elem.find('.content')
};
_this.init = function(){
_this.elems.title.on('click', _this.toggle);
if(elem.hasClass('active')){
_this.toggle(null);
}
};
_this.toggle = function(e){
if(e !== null){
e.preventDefault();
if(elem.hasClass('active')){
elem.removeClass('active');
}else{
elem.addClass('active');
}
}
_this.elems.content.slideToggle('fast');
};
_this.init();
};
$.fn.accordion = function(){
var instances = [];
return this.each(function(){
var accordion = $(this);
instances.push(new Accordion(accordion));
});
};
}($));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment