Skip to content

Instantly share code, notes, and snippets.

@waymondo
Created February 12, 2014 22:19
Show Gist options
  • Save waymondo/8965723 to your computer and use it in GitHub Desktop.
Save waymondo/8965723 to your computer and use it in GitHub Desktop.
direct = (opts) ->
return unless $.isPlainObject opts
$el = $(opts.el or @)
_.reduce _.pairs(opts), (memo, opt) ->
fn = $.fn[opt[0]] or director[opts[0]]
return memo unless fn
fn.call(memo, opt[1])
, $el
@director =
direct: (el = "html") ->
$(el).find("[data-direct]").each ->
direct.call @, $(@).data('direct')
directives: {}
$(document).on "page:change", ->
director.direct()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment