{maketoc}These guidelines are specific to contributing Javascript to bitweaver. At the time of the creation of these guidelines javascript in bitweaver was getting a little out of hand. If you look at files in bitweaver and find they do not conform to these guidelines, __please do not imitate past poor practices__, these are old lines of code that simply still need to be rewritten. Please contribute all new javascript by conforming to the following:
|
|
+!!!Start With bitweaver's Basic Coding Conventions |
+In addition to the guidelines laid out here, please follow our general ((CodingGuidelines|Coding Guidelines)), where applicable. |
+ |
!!!Where To Put Javascript
|
!!!!Location:
|
-Javascript is best placed in one of two locations. Either in a .js file or in a package's header_inc.tpl file. ALL package .js files should go in a __scripts/__ directory in their package. It is not always advantageous however to put javascript in .js files. Use of js files causes the browser to make more http requests. If there are a lot of js files required then this can slow page load time. For small amounts of javascript its better to put it into the header_inc.tpl file where it will be rendered inline in the <HEAD> tag. It is ok to also put the js in a separate template and include that in the header_inc.tpl file.
|
+Javascript is best placed in one of two locations. Either in a .js file or in a package's header_inc.tpl file. ALL package .js files should go in a __scripts/__ directory in their package. It is not always advantageous however to put javascript in .js files. Use of js files causes the browser to make more http requests. If there are a lot of js files required then this can slow page load time. For small amounts of javascript its better to put it into the header_inc.tpl file where it will be rendered inline in the HEAD tag. It is ok to also put the js in a separate template and include that in the header_inc.tpl file. |
|
Some bitweaver wide .js files will live in util/ but that will be rare, most .js files should be in their package.
|
|
-AVOID INLINE JS AS MUCH AS POSSIBLE INSIDE THE BODY TAGS. Sometimes this is hard to do, but in most cases you can. It is poor practice to litter HTML with <SCRIPT> tags. Sometime people do this to cause something to be rendered on load. If you want a function called onload you should instead you should assign the function to the body onload event. You can do this in your php by assigning your javascript function like this:
|
+AVOID INLINE JS AS MUCH AS POSSIBLE INSIDE THE BODY TAGS. Sometimes this is hard to do, but in most cases you can. It is poor practice to litter HTML with SCRIPT tags. Sometime people do this to cause something to be rendered on load. If you want a function called onload you should instead you should assign the function to the body onload event. You can do this in your php by assigning your javascript function like this: |
|
{code}$gBitSystem->mOnload[] = 'BitPackage.someFunction();';{/code}
|
|