= JavaScript for Trac and plugin development = JavaScript is used in Trac to add dynamics to web interface elements on the browser side: * expanding/folding in TracBrowser * providing [TracKeys keyboard shortcuts] * ... {{{ #!comment list other uses of JS in Trac }}} == 3rd party libraries === jQuery === Trac makes heavy use of [http://en.wikipedia.org/wiki/JQuery jQuery] library to ease development. Access to this library contents is usually provided through the main function named $. $ as a name used for brevity and clarity. Unfortunately, other libraries may use it too and this may cause conflicts. $ in fact is just a shortcut for ''jQuery'' namespace and it is possible to use full name instead. But to avoid conflicts with other libraries $ shortcut should is turned off by switching jQuery into non-conflict mode with ''jQuery.noConflict()'' call. This is well explained in http://docs.jquery.com/Using_jQuery_with_Other_Libraries However, you will see many blocks in Trac that use $ for jQuery. They do it in their local scope defined by nameless function (or closure): {{{ (function($) { /* some code that uses $ */ })(jQuery) }}} There is a good description of closures and `(function(){})()` construct at http://ajaxian.com/archives/secrets-of-the-javascript-ninja-a-sneak-peak-for-ajaxians ==== $(document).ready() ==== To execute and modify DOM tree JavaScript function should usually wait until a page fully loads. With jQuery it looks like: {{{ $(document).ready(function_name); }}} In non-conflicting mode, code that executed in Trac on page startup is enveloped in closure and looks like: {{{ jQuery(document).ready(function($) { ... }); }}} === jQuery UI Since Trac version 1.0, we also bundle [http://jqueryui.com jQuery UI], a set of standard UI elements. Specific releases can be downloaded from the following URLs: `http://code.jquery.com/ui/1.x.y/jquery-ui.min.js` This correspond to the minified version of the whole of jQuery UI (i.e. we don't use a subset of what is currently used by Trac on purpose, so that plugins can assume they have access to the all the jQuery UI components). We use a custom theme for the CSS, built using the jQuery UI Theme Roller. The [source:trunk/trac/htdocs/css/jquery-ui/jquery-ui.css@11493:50#40 jquery-ui.css] file contains a link to the theme roller with preselected values ([http://jqueryui.com/themeroller/?ctl=themeroller&ffDefault=Verdana,Arial,\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'Bitstream%20Vera%20Sans\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\',Helvetica,sans-serif&fwDefault=normal&fsDefault=13px&cornerRadius=.3em&bgColorHeader=ffffdd&bgTextureHeader=03_highlight_soft.png&bgImgOpacityHeader=80&borderColorHeader=bbbbbb&fcHeader=000000&iconColorHeader=707070&bgColorContent=ffffff&bgTextureContent=01_flat.png&bgImgOpacityContent=00&borderColorContent=bbbbbb&fcContent=000000&iconColorContent=222222&bgColorDefault=ffffff&bgTextureDefault=01_flat.png&bgImgOpacityDefault=0&borderColorDefault=bbbbbb&fcDefault=b00000&iconColorDefault=b00000&bgColorHover=ffffdd&bgTextureHover=01_flat.png&bgImgOpacityHover=0&borderColorHover=505050&fcHover=505050&iconColorHover=505050&bgColorActive=303030&bgTextureActive=03_highlight_soft.png&bgImgOpacityActive=30&borderColorActive=bbbbbb&fcActive=eeeeee&iconColorActive=d7d7d7&bgColorHighlight=c0f0c0&bgTextureHighlight=03_highlight_soft.png&bgImgOpacityHighlight=75&borderColorHighlight=c0f0c0&fcHighlight=363636&iconColorHighlight=4b954f&bgColorError=ffddcc&bgTextureError=08_diagonals_thick.png&bgImgOpacityError=18&borderColorError=9b081d&fcError=500000&iconColorError=9b081d&bgColorOverlay=666666&bgTextureOverlay=08_diagonals_thick.png&bgImgOpacityOverlay=20&opacityOverlay=50&bgColorShadow=000000&bgTextureShadow=01_flat.png&bgImgOpacityShadow=10&opacityShadow=20&thicknessShadow=5px&offsetTopShadow=-5px&offsetLeftShadow=-5px&cornerRadiusShadow=5px link] at the time of this writing, for Trac 1.0.0). Our date picker is a jQuery UI add-on, the [https://github.com/trentrichardson/jQuery-Timepicker-Addon jQuery Timepicker].