Archive for September, 2006

Visual jQuery Magazine Issue 1

The first issue of Visual jQuery Magazine is now available from the Visual jQuery website. The website is an excellent reference for the jQuery API. In fact, it hooks right into the comments of the latest jQuery version, formatting everything into a highly readable, visually appealing page. The new monthly magazine extends the Visual jQuery brand to a PDF-format publication. Visual jQuery Magazine Issue 1 Issue 1 features an interview with jQuery’s developer John Resig, an analysis of what sets jQuery apart from other JavaScript frameworks, a quick look at a few plugins, an introduction to the jQuery Object, and much more.

Editor Yehuda Katz has put a lot of work into releasing a first issue that is both beautiful and informative. Visit Visual jQuery Magazine or download it here (1.7MB PDF). Congratulations, Yehuda. We look forward to many more great issues to come.

Fancy Drop Cap – Part 1

Introduction

Last spring when I implemented a new design for my weblog, I wanted to use a fancy drop cap for the first letter of the first paragraph of the first post of each page. There are all sorts of ways to make a drop cap happen, but since I was reading Jeremy Keith's excellent book DOM Scripting at the time, I thought I'd do it that way. The DOM scripting method that I put together had some important benefits for me at the time:

  • It used an image, so I didn't have to worry about installed fonts on users' machines
  • The HTML source stayed intact, so search engines wouldn't trip over a first word with a missing first letter.
  • It degraded nicely, so if users had JavaScript or images or both turned off, everything would still look fine, just a little less pretty.

Now that I'm learning jQuery, I thought I'd revisit my code and see if I could tidy it up a bit, the jQuery way.

Image Set

AI first put together a set of images, one for each letter of the alphabet, using a font from the Dieter Steffman collection at typOasis. If you don't want to go through the laborious process of converting letters into images, you can download mine (20KB zip). See the letter "A" floating to the right of this paragraph for an example.

Setting up the Code

Instead of putting all of the code in a $(document).ready() function, I created a separate function and just called it inside $(document).ready():

JavaScript:
  1. $(document).ready(function() {
  2.   swap_letter();
  3. });
  4. function swap_letter() {
  5.   //all the code goes here
  6. }

Now we can get down to business.

Insert Image Here

The easiest part of the process was inserting the image, because jQuery makes it almost effortless. Read the rest of this entry »

TextMate Bundle for jQuery

JonBob and I have been working on a TextMate bundle for jQuery over the past few weeks. If you're not familiar with TextMate and you own a Mac, you should definitely check it out. It has saved me countless hours of repetitive keystrokes with its bundles, which contain commands, code snippets, templates, and macros that are triggered by pressing special key combinations or clicking menu items.

jquery bundle for textmate

The jQuery bundle that we put together mostly consists of "tab triggers" for various functions, but it also includes context-sensitive help derived from the online documentation and some nice syntax highlighting. After selecting jQuery as your file type in TextMate, you could, for example, type ready and press the Tab key to produce this:

$(document).ready(function() {
  // Stuff to do as soon as the DOM is ready;
});

It'll then select the commented line (line 2 in this example) for you so you can start typing right away, replacing the comment with your code. Hit the Tab key once more and it drops you onto a new line below the closing brackets. If you want to learn more about a function that you've typed in, just click anywhere inside its name and press Control + H. You'll get official documentation on the function.

Get the Bundle

So, how can you get this cool jQuery bundle and speed up your coding? First, you'll need TextMate, of course. If you don't have it yet, download the 30-day trial. Then you'll need to either check out the bundles from the Subversion repository (advanced) or download and install the GetBundles bundle.

Update

I'm no longer supporting the version in the Macromates subversion repository. For the most recent version, with updates for version 1.3.x, download (or clone) the jQuery TextMate bundle at GitHub.

Slicker Show and Hide

Last time I showed you how to make something appear and disappear on a web page. This time I'll show you how to do it with style.

Like we did last time, we'll start with our $(document).ready() and put everything else inside of it.

Adjust the Speed

This time, however, we're going to adjust the speed at which our item shows and hides. To do so, we put a speed indicator — "slow" or "normal" or "fast" or a number of milliseconds (1000 = 1 second) — inside the parentheses: Read the rest of this entry »

Documentation now linked

A new feature has been implemented; all jQuery code snippets we post will now be linked to the appropriate part of the documentation. So, for example, when we post:

JavaScript:
  1. $('div.foo').find('a').hide().end();

You can click on the function names "find," "hide" and "end" for more information on the functions. These definitions are culled from the same XML file that powers the official API documentation.

Basic Show and Hide

As promised in my last entry, I'll be showing you a simple effect that you can do using jQuery: showing or hiding something, or a group of things, on the page. The two functions that let us do this are, not surprisingly, show() and hide().

jQuery also comes with another function called toggle(), which will make matching elements visible if they are hidden or hidden if they are visible.

So, let's get down to business. We're going to start with our $(document).ready() function.

Read the rest of this entry »