Created
September 22, 2014 06:33
-
-
Save joshhunt/48e5ec9b9d8c1f35ebe1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <body> | |
| <div class='' data-module="pollDecorator"> | |
| <button data-answer-id="12-545"></button> | |
| </div> | |
| </body> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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' | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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