Created
May 12, 2015 20:46
-
-
Save vizvamitra/0c7003d012d2886d3eb2 to your computer and use it in GitHub Desktop.
js module loader for my blog
This file contains 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.Blog = window.Blog || do -> | |
modules = [] | |
initialized = false | |
define = (name, module) -> | |
Blog[name] = Blog[name] || do -> | |
modules.push(name) | |
new_module = module() | |
new_module.init() if (Blog._initialized) | |
return new_module | |
return Blog[name] | |
init = -> | |
Blog[name].init() for name in modules | |
Blog._initialized = true | |
return { | |
_init: init, | |
define: define, | |
_modules: modules, | |
_initialized: initialized, | |
_registered: false | |
} | |
Blog._initialized = false; | |
$ -> | |
if (!Blog._registered) | |
$(document).ready(Blog._init) | |
$(document).on('page:load', Blog._init) | |
window.Blog._registered = true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
И пример модуля к нему: