Last active
August 29, 2015 14:19
-
-
Save eric-miller2129/daf2e4ca6df4f1ac5b19 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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