MLNTN

Maniacal musings of a pixel perfectionist

jQuery undo plugin

Posted by Jared on March 9, 2009

I got a crazy idea when I was working with some AJAX interfaces – a quick and painless jQuery undo plugin.

What does that mean? I’m not entirely sure.

(Demo)

Here’s the goal…

I want to be easily able to add a function to the undo queue.  When I press the undo key combination, that function will run again and it will be placed in the redo queue:

$().undoable(function(){ $('#sample' + n).toggle(); });

This is really not ideal.  While some functions toggle correctly, not all do.

What I really is to be able to define a function for undo and a function for redo:

$().undoable(function(){ $('#sample' + n).hide(); }, function(){ $('#sample' + n).show(); });

I really think I can get away with both of them.

Check out the demo and let me know what you think. (Hint: Open the Firebug console)

5 Responses to “jQuery undo plugin”

  1. SeanJA says:

    Not bad… but right now it seems more like a toggle rather than an undo (and the demo won’t work in IE)

  2. Yeah, the demo just toggles the divs with one exception – console logging. If you open the Firebug console, you’ll see that it’s actually running different functions for undo and redo.

    I guess I’ll need to check IE too. =)

  3. Tim says:

    Doesn’t work in IE because of the console.log ;)

  4. thomasd says:

    Doesn’t work for me!
    CTRL+Z does nothing, CTRL+Y brings up the download-manager (as it should).
    Environment: FF 3.0.7, Ubuntu 8.10, Keyboard German Layout

    Great idea, anyway!

  5. thomasd says:

    Ok, my fault!

    I had to activate the console-tab in firebug. Now it works.

Leave a Reply