Skip to content

Instantly share code, notes, and snippets.

@karlbright
Last active August 29, 2015 14:10
Show Gist options
  • Save karlbright/9d7f945ed37c86825fd4 to your computer and use it in GitHub Desktop.
Save karlbright/9d7f945ed37c86825fd4 to your computer and use it in GitHub Desktop.
;(function($, window) {
var defaults = {
duration: 1000,
delay: 500,
hideTree: 'hideTree',
showTree: 'showTree'
}
function accordion(el,options) {
this.$el = el;
this.options = $.extend({}, defaults, options);
this.init();
return this;
}
accordion.prototype.init = function() {
this.$el.addClassName('foobar');
}
accordion.prototype.hideTree = function() {
$(this).find("li > ul").attr("data-name", this.options.hideTree);
};
accordion.prototype.showTree = function() {
$("a").on("click", function(event) {
$(this).trigger("openTree");
})
};
accordion.prototype.bindEvents = function() {
$(this).on("openTree", function(event) {
event.preventDefault();
$(event.target).next("ul").attr("data-name", this.options.showTree);
});
};
$.fn.accordion = function(options) {
this.each(function() {
if(!$.data(this, 'accordion')) $.data(this, 'accordion', new Accordion(this, options));
});
return this;
}
})(jQuery, window);
$(".module__accordion").accordion({
duration: 5000,
delay: 1000,
hideTree: "hideTree",
showTree: "showTree"
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment