blob: 61d179fed855fd501b73cb3fb7856c6db4c15d2d [file]
#summary Proposal about Javascript refactoring
#labels Importance-Useful,Phase-Implementation,Contents-Draft
With more Javascript code being written and deployed, global namespace pollution is going to be a risk. So, we have two options: handle Java-like packages and dependencies between modules with projects like [http://code.google.com/p/jingo/ Jingo] or keep Python to handle all this stuff, just giving it the potential to handle dependencies.
In any way, we need:
1. to separate Javascript code in *modules*, and use Javascript language features to _namespace correctly_ those modules.
2. to keep as much Javascript code as possible *outside* Django templates
3. To put HTML strings *outside* Javascript code, eventually developing a little function to load those templates and then, for templating, something that emulates {{{ sprintf() }}} or begin to use [http://plugins.jquery.com/project/jquerytemplate jQuery Template plugin].
4. Use {{{ jQuery.noConflict() }}} (after loading any library/plugin) and giving jQuery a different namespace like {{{ $j }}} to avoid conflicts if we ever want to integrate other libraries ({{{ $ }}} namespace is very well overused)
The proposal is to create a {{{ melange }}} namespace and begin adding sub-namespace to it for every feature we need. We might want to add {{{ models }}}, {{{ logic }}} and {{{ templates }}} subdirectories to the {{{ content/js }}} as well, to keep an homogeneous structure with the python code.