javascript.txt 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. ==========
  2. JavaScript
  3. ==========
  4. While most of Django core is Python, the ``admin`` and ``gis`` contrib apps
  5. contain JavaScript code.
  6. Please follow these coding standards when writing JavaScript code for inclusion
  7. in Django.
  8. Code style
  9. ----------
  10. * Please conform to the indentation style dictated in the ``.editorconfig``
  11. file. We recommend using a text editor with `EditorConfig`_ support to avoid
  12. indentation and whitespace issues. Most of the JavaScript files use 4 spaces
  13. for indentation, but there are some exceptions.
  14. * When naming variables, use ``camelCase`` instead of ``underscore_case``.
  15. Different JavaScript files sometimes use a different code style. Please try to
  16. conform to the code style of each file.
  17. * Use the `JSHint`_ code linter to check your code for bugs and style errors.
  18. JSHint will be run when you run the JavaScript tests. We also recommended
  19. installing a JSHint plugin in your text editor.
  20. .. _javascript-patches:
  21. JavaScript patches
  22. ------------------
  23. Django's admin system leverages the jQuery framework to increase the
  24. capabilities of the admin interface. In conjunction, there is an emphasis on
  25. admin JavaScript performance and minimizing overall admin media file size.
  26. Serving compressed or "minified" versions of JavaScript files is considered
  27. best practice in this regard.
  28. To that end, patches for JavaScript files should include both the original
  29. code for future development (e.g. ``foo.js``), and a compressed version for
  30. production use (e.g. ``foo.min.js``). Any links to the file in the codebase
  31. should point to the compressed version.
  32. Compressing JavaScript
  33. ~~~~~~~~~~~~~~~~~~~~~~
  34. To simplify the process of providing optimized JavaScript code, Django
  35. includes a handy Python script which should be used to create a "minified"
  36. version. To run it::
  37. python django/contrib/admin/bin/compress.py
  38. Behind the scenes, ``compress.py`` is a front-end for Google's
  39. `Closure Compiler`_ which is written in Java. However, the Closure Compiler
  40. library is not bundled with Django directly, so those wishing to contribute
  41. complete JavaScript patches will need to download and install the library
  42. independently. The Closure Compiler library requires `Java`_ 7 or higher.
  43. Please don't forget to run ``compress.py`` and include the ``diff`` of the
  44. minified scripts when submitting patches for Django's JavaScript.
  45. .. _Closure Compiler: https://developers.google.com/closure/compiler/
  46. .. _EditorConfig: http://editorconfig.org/
  47. .. _Java: https://www.java.com
  48. .. _jshint: http://jshint.com/