We will be covering the following recipes in this chapter:
Including JavaScript files from a theme
Including a JavaScript file only for certain pages
Giving the username textfield keyboard focus
Exporting a variable from PHP to JavaScript
Adding default text to the search textfield
Displaying comments in compact form
Minimizing and maximizing blocks using JavaScript
Until a few years ago, mentioning the word JavaScript to a themer would usually result in groans about inconsistencies in browser support, lack of standards, difficulty in debugging, and a myriad of other complaints. Thankfully, however, things have changed considerably since then. Browsers have evolved and standards have improved. JavaScript is now a potent weapon in any themer's armory and this is especially true with the introduction of cross-browser libraries and frameworks which address most of the aforementioned issues with it.
JavaScript libraries take out the majority of the hassle involved...