Skip to content

Instantly share code, notes, and snippets.

@assertchris
Created August 16, 2012 13:52
Show Gist options
  • Select an option

  • Save assertchris/3370262 to your computer and use it in GitHub Desktop.

Select an option

Save assertchris/3370262 to your computer and use it in GitHub Desktop.
Example Declarative Behavior (Moo/CS)
do ->
namespace = "behaviors.tabs"
fm.behaviors.add("tabs", {
"onAdd": (scope, parameters) ->
_tab = parameters?.selector?.tab or ".tab"
_subtabs = parameters?.selector?.subtabs or ".subtabs"
_text = parameters?.selector?.text or ".text"
_hide = parameters?.class?.hide or "hide"
_on = parameters?.class?.on or "on"
parent = @getParent()
tabs = @getElements(_tab)
subtabs = @getElements(_subtabs)
texts = parent.getElements(_text)
tabs.addNamespaceEvent(namespace + ":click", (e) ->
e and e.stop()
if subtab = @getElement(_subtabs)
# subtabs
subtabs.addClass(_hide)
subtab.removeClass(_hide)
# highlights
tabs.removeClass(_on)
@addClass(_on)
# targets
if selector = @get("data-tabs-target")
if target = parent.getElement(selector)
texts.addClass(_hide)
target.removeClass(_hide)
)
if tabs.length then tabs[0].fireEvent("click")
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment