Control.Touchpad for script.aculo.us
Posted October 13th, 2006 in ProgrammingTags: JavaScript, Programming, Ruby on Rails
I’ve submitted a patch to the Rails developers that adds a Touchpad control to script.aculo.us. It is a 2D control based heavily off of Slider and so shares some of the same options and behavior. The Touchpad callbacks output an array [x, y] rather than a single value v which is what Slider does. Touchpad also has no handles so the last value is not preserved.
Patch: http://dev.rubyonrails.org/ticket/6398
So what can you do with it? The basic use is simply to capture mouse input in a defined area of a web page and then map that input to a specific range of values. Another use would be to hook the output of the Touchpad to the inputs of two Sliders. This way you have one controller that can control two controllers simultaneously. (Additionally, this preserves the last value of the Touchpad unless of course you move the Slider independent of the Touchpad.) Another slick use is one that I’ve seen requested on the forums. If you hide the overflow of the Touchpad and then nest a really wide div that contains thumbnails for products, you can then limit the output of the Touchpad to horizontal values—the vertical values are simply clamped to 0—and then use the callback to set the left coördinate of the child div. Now you can scroll through your products without an ugly scrollbar.
If this sounds like something you can use and you can’t wait til the developers choose to add it to the trunk, then go visit the URL above. Then simply download and run the attached diff file on your script.aculo.us installation using Subversion. I recommend you run the functional test included in the patch (tests/run_functional_test.html –> click on touchpad_test in the left frame) to see some examples of the touchpad in action.
script.aculo.us is at version 1.6.4 at the time of this writing.