Skip to content

Instantly share code, notes, and snippets.

@joshhunt
Created September 22, 2014 06:33
Show Gist options
  • Select an option

  • Save joshhunt/48e5ec9b9d8c1f35ebe1 to your computer and use it in GitHub Desktop.

Select an option

Save joshhunt/48e5ec9b9d8c1f35ebe1 to your computer and use it in GitHub Desktop.
define ['require', 'jquery', 'utils/index'], (require, $, utils) ->
decorator = ($target) ->
moduleName = $target.attr('data-module')
require [moduleName], ((module) ->
if $.isFunction module.decorate
data = $target.data()
delete data.module
module.decorate $target, data
), (err) ->
utils.log.warn "Couldn't load decorator module #{moduleName}"
decorateDom: (selector) ->
$(selector).each ->
decorator $(this)
decorateElement: ($element) ->
decorator $element
<body>
<div class='' data-module="pollDecorator">
<button data-answer-id="12-545"></button>
</div>
</body>
define [], ->
decorate: ($target, data) ->
console.log 'Cool, decorating', data.questionId
$target.find('button').on('click', (event) ->
$ele = $(this)
console.log 'Clicked on', $ele.data 'answerId'
)
define ['decorateModule'], (decorateModule) ->
decorateModule.decorateDom '[data-module]'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment