Approximating resizeComplete in jQuery

Most browsers fire resize events continuously as the viewport is scaled. This is handy when your interface needs to change responsively during a resize, but a PITA if you only need to perform a single action when it’s “done.” Even worse is when that action is resource-intensive (such as an animation), as it can render your resize choppy or unbearable. I was faced with this very problem on a recent site design, and I thought I’d share the solution I arrived at.

The basic idea is to call a function within the resize() callback on a delay. This function checks to see if the width and height of the window have maintained dimensions during this period, and if so performs your resize completed action. Here is the code in jQuery:

  1. // global queue of setTimeout handles
  2. var handleQueue = new Array();
  3. $(window).resize(function() {
  4. // store current dimensions using .data()
  5. $(window).data(′oldW′, $(window).width()).data(′oldH′, $(window).height());
  6. // call our function on a delay and push its handle on the queue
  7. handleQueue.push(setTimeout(_completeCheck, 750));
  8. });
  9. function _completeCheck() {
  10. var $window = $(window);
  11. if ($window.width() == $window.data(′oldW′) && $window.height() == $window.data(′oldH′) {
  12. // *** DO YOUR RESIZE COMPLETE STUFF HERE ***
  13. // unwind setTimeout handle queue to prevent further execution
  14. while (handleQueue.length != 0)
  15. clearTimeout(handleQueue.shift());
  16. } else {
  17. // otherwise shift the first handle off since it already executed
  18. handleQueue.shift()
  19. }
  20. }

I chose to go the route of a handle queue because I feel it’s a lot cleaner than some global boolean. The boolean approach will still execute delayed function calls after the resize is “done,” and I’d rather unwind a queue and cancel those calls immediately since they’re unnecessary. You might also need to noodle with the setTimeout interval to achieve the responsiveness you’re after. In my case, 750ms was just right.

This nice hamburger is from Jennifer Daniel aka Lacie Argyle /via vizualize

This nice hamburger is from Jennifer Daniel aka Lacie Argyle /via vizualize

Potato Risotto

Last night I made and fell in love with potato “risotto,” a side dish found in this month’s Bon Appétit magazine. It requires a bit of knife work to get a uniform brunoise out of the potatoes, but the contrast of textures and flavor are both well worth the effort.

  • 1 tbsp butter
  • 1 cup finely diced onion
  • 1 lb yukon gold potatoes brunoised
  • 1/8 tsp cayenne pepper
  • pinch of kosher salt
  • 1 1/2-2 cups chicken stock
  • 1/2 cup heavy cream
  • 1/4 cup grated parmesan cheese
  • 1/4 cup fresh chives
  1. Prepare potato brunoise—you have two options to begin: (1) cut the potato into a perfect rectangular box or (2) square off all sides and ends producing a rectangular box with rounded corners. The former is a lot more wasteful, but your brunoise will be perfectly uniform—go with whichever you prefer. To finish the brunoise cut the potato into 1/8” panels, rotate the stack 90° and cut into 1/8” juliennes, then cut the stacked juliennes into 1/8” cubes.
  2. Melt butter in a large sauce pan over medium heat. Add diced onions and sweat covered until translucent, stirring often.
  3. Add potatoes, 1.5 cups of stock, and cayenne pepper. Bring stock to a boil and reduce heat, simmering until potatoes are almost tender. Like a conventional risotto, add extra stock if needed and stir often. You’re looking for a creamy texture with a little bit of sauce in the pan.
  4. Add heavy cream and simmer until potatoes are tender but still hold their shape.
  5. Mix in parmesan cheese and chives before serving. Devour tout de suite.

If I could fault anything about this recipe it’d be that it’s a little on the rich side, so next time I’ll probably balance the fat with a little acid—either with white wine or lemon zest.

I too have thoughts on the iPad

I’ve given myself some time to mull over our latest gift from benevolent leader and arrived at this: bad name, exciting thesis, and nascent execution.

I’m happiest for Cassie, as come June she’ll have a shiny new iPad that fulfills her every need as a simple and inexpensive internet machine. I don’t feel like the iPad in its current form is compelling enough to steal me away from my Air, but its premise really excites me. Neven nails exactly why this is exciting, particularly from a UI/UX perspective:

And a bright light did shine upon my liberated face and a voice did whisper a thunder: You’re free. Free of pointless preferences and finger-baiting adjustments.

As Andy puts it, the iPad is an administrivia-removal device.

The iPad is to interface design what a magazine is to print design: a consistent, constrained, and explorable medium. That’s a refreshing break from designing UX around a multitude of permutations and preferences. Moreover, this freedom encourages you to re-imagine experiences from the ground up (as Apple has done with most of their core apps). Exciting times indeed.

Many people (most notably the Categorical Apple Denouncement Brigade™) are ready to call the iPad a flop due to missing bullet points, but I’m with Fraser Speirs: “What you’re seeing in the industry’s reaction to the iPad is nothing less than future shock.” The iPad’s positioning is decidedly forward, and in a culture trained to value malleability over elegance I can understand the backlash. It’ll be interesting to see how opinions maintain when people have the device in-hand.

I do have some beef with the interface—most notably the lock and home screens. The unimaginative use of space feels like an afterthought, and that strikes me as odd for something so prominent. I’m sure Apple will iterate this in future releases, but it’s clearly an area of deficiency in the current version. Also I’m not sold on the execution of the keyboard, which I imagine will be pretty clunky in portrait mode. I’ll wait until I play around with the it before I pass judgement, but I can’t picture it being very satisfying to use.

All in all the iPad is an intriguing first step into uncharted waters, and I can’t wait to check it out.

“When that chute opens you feel like you’ve done something kings and queens can’t even spell.”

— Gary Busey, on skydiving
For Haiti /via !.Keesssss.!

For Haiti /via !.Keesssss.!

Herzog & de Meuron - VitraHaus, Weil am Rhein. Now nearing completion. /via

Herzog & de Meuron - VitraHaus, Weil am Rhein. Now nearing completion. /via

“I think as a younger designer I was afraid if I did something that was cliched or literal straight out that that would ultimately be the end product, whereas now I look at it as sometimes you have to start there. Sometimes blue is blue and red is red and … as the process develops you start to question yourself and sort these things out as you go along.”

— Danny Yount