JavaScript Conventions

This is a draft document not intended to follow yet.

Following are some questions came in to my mind regarding the use of js in Sahana. We can build the convention by using them as guidelines.

  1. coding and name space conventions to prevent code clashes between modules.
  2. Are we going to let module specific js libraries if so how are we going to handle it. ( Need to change the frame work for this )
  3. Need to create a list of existing libraries
  4. Conventions about ajax - are we going to use REST/JSON as the standard communication between client and server?
  5. Using document.Onload function

Accessibility policy

  • The more you use JavaScript the more it will make the system inaccessible by browsers without JavaScript So be wise when using JavaScript in a page.
  • Use JavaScript only if there is no way to make the page usable or if it can enhance the usability of the application, don't use JavaScript for cosmetic modifications.
  • If it is not possible to make the page usable without scripts, provide a text equivalent with the NOSCRIPT element, or use a server-side script instead of a client-side script, or provide an alternative accessible page.

Including 3rd party js libraries.

  • Before you include 3rd party scripts please look at the existing libraries to see whether they provide the functionality you want, if so please use the existing library without including a new one.
  • All the JavaScript libraries should come under “approot /www/res/js/” directory.
  • Special 3rd party JavaScript clients must come under “approot /www/res/” directory. ( Ex:- OpenLayers )

Coding conventions

QR Code
QR Code dev:js_convention (generated for current page)