# Easy handling of accordion elements # The structure should be as follows: # #
#
#
Title
#
... your content ...
#
# # // repeat accordion-items ... #
# window.SC ||= {} class window.SC.Accordion extends Backbone.View events: "click .title" : "handleClick" initialize: -> @items = @$("> .accordion-item") @open = null @initiallyOpenItem() initiallyOpenItem: -> if window.location.hash elem = $(window.location.hash) @openItem(elem.parent()) if elem.hasClass("title") openItem: (elem) -> @closeItem(@open) if @open @open = elem.addClass("open") closeItem: (elem) -> elem.removeClass("open") @open = null toggleItem: (elem) -> if elem.hasClass("open") @closeItem(elem) else @openItem(elem) handleClick: (event) => item = $(event.currentTarget).parent() @toggleItem(item)