Created
August 4, 2012 22:29
-
-
Save vessi/3260357 to your computer and use it in GitHub Desktop.
coffeescript simple widget
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
| window.Widget = | |
| init: -> | |
| $('*[data-widget]:not(*[data-widget-initialized])').each (_, container) -> | |
| element = $(container) | |
| element.attr('data-widget-initialized', 'true') | |
| klass = window[element.data('widget')] | |
| new klass(element) | |
| $ -> | |
| Widget.init() |
Кстати, вместо (index, container) пишу обычно (_, container) если index не используется
Author
2 - если лепить jquery.data на 5 строке - у меня не модифицируется элемент.
Author
по поводу 3 - про анонимки забыл :(
Картинка здесь: http://d.pr/i/fVGh
Author
так селектор не сработает. буду за тачкой - фидл нарисую
Ааа, селектор. Да, не работает...
Author
Но огромное спасибо за правки :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

->в конце третей строки?.data, почему бы на 6 не делать тоже самое:element.data('widget-initialized', 'true')