Edgewall Software

Changes between Version 2 and Version 3 of TracDev/JavaScript


Ignore:
Timestamp:
Dec 8, 2008, 3:29:18 PM (15 years ago)
Author:
techtonik <techtonik@…>
Comment:

comments about jQuery

Legend:

Unmodified
Added
Removed
Modified
  • TracDev/JavaScript

    v2 v3  
    1 Trac uses JavaScript code to add dynamics on the browser side to web interface elements:
     1= JavaScript for Trac and plugin development =
     2
     3JavaScript is used in Trac to add dynamics to web interface elements on the browser side:
    24 * expanding/folding in TracBrowser
    35 * providing [TracKeys keyboard shortcuts]
     
    911}}}
    1012
    11 Trac uses [http://en.wikipedia.org/wiki/JQuery jQuery] library to ease development. jQuery uses $ as a name of its function for brevity and this may cause conflicts with other libraries. To avoid this jQuery library is used in non-conflicting state (really?) and code that uses $() function as jQuery definition is wrapped into javascript closures.
     13=== jQuery ===
     14
     15Trac 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
     16
     17However, you will see many blocks in Trac that use $ for jQuery. They do it in their local scope defined by nameless function (or closure):
     18{{{
     19(function($) { /* some code that uses $ */ })(jQuery)
     20}}}
     21There is a good description of closures and `(function(){})()` construct at http://ajaxian.com/archives/secrets-of-the-javascript-ninja-a-sneak-peak-for-ajaxians
    1222
    1323{{{
    1424#!comment
    15 post a links to ajaxian javascript ninja to illustrate closures and (function($){  ...  })(jQuery); syntax
    16 
    1725add comments from the http://groups.google.com/group/trac-dev/browse_thread/thread/bd2ad5f23b6a988?hl=en
    1826}}}