Backpack’s Pages tab has been completely rewritten in the new version. We moved nearly all of the application’s UI logic out of hand-written JavaScript files and into Ruby using RJS templates. This resulted in approximately 1600 fewer lines of application JS, and let us deliver pages with substantially less markup, since the edit states are now loaded on-demand instead of included in bulk with each page load.

Keep reading for more details on how we’ve improved Backpack’s internals, and for a look at several JavaScript libraries we’ve developed in the process.

We’re running Backpack on the latest versions of Rails, Prototype, and script.aculo.us from SVN. This lets us use Edge Rails’ support for asset hosts to circumvent the 2-connection HTTP limit for delivering assets. We’re also now using Rails’ asset concatenation for CSS and JavaScript files, which, when combined with gzip compression, results in extremely speedy page loads.

Most of the custom JavaScript in the new Backpack is used for wiring the interface in reusable ways. We’ve built a handful of mini-libraries that sit on top of Prototype and script.aculo.us, and we’re using them in several of our other applications in addition to Backpack.

One of these libraries adds support for specifying a CSS selector for script.aculo.us Sortable containment. It uses Prototype 1.6’s new Function#wrap to add the behavior in an aspect-oriented way without modifying the original Sortable source code. This is the library that powers Backpack’s widget reordering. It’s currently being used in Backpack and Basecamp.

Another library, internally called Hover Observer, uses an unobtrusive technique (monitoring the entire page for mouse movement) to add and remove a “hover” class on element hierarchies with certain class names. Combined with CSS, this allows us to easily show the edit/delete/move “nubbins” when you mouse over widgets on the page, or show drop-down menus when you mouse over applications in Open Bar. The library also lets us specify enter and exit delays, so if you accidentally mouse outside of a target area, the hover class isn’t removed immediately. Think of it as a cross-browser implementation of the :hover CSS pseudo-class, on steroids. Hover Observer was developed for Backpack and is now being used in Basecamp and Highrise.

The last library is tentatively known as Transitions, and provides an extremely simple API for animating transitions between DOM states. The animation resizes and fades an element’s content from one state to another, much like the effect you see when switching preference panes in OS X System Preferences. You’ll see the effect when you edit any item in Backpack. Because the API is simple, RJS-compatible, and easy to integrate into existing applications, we were able to develop it and drop it into Backpack in a single weekend. I’ll post more on this library when it’s ready for public consumption.

I’m extremely pleased with how everything turned out, and I’m looking forward to open-sourcing as much of our JavaScript infrastructure as possible in the very near future. If you have a Backpack account, I hope you’re pleased with the changes, too. :)