I’ve sub­mit­ted a patch to the Rails devel­op­ers that adds a Touch­pad con­trol to script.aculo.us. It is a 2D con­trol based heav­ily off of Slider and so shares some of the same options and behav­ior. The Touch­pad call­backs out­put an array [x, y] rather than a sin­gle value v which is what Slider does. Touch­pad also has no han­dles so the last value is not preserved.

Patch: http://dev.rubyonrails.org/ticket/6398

Enable

So what can you do with it? The basic use is sim­ply to cap­ture mouse input in a defined area of a web page and then map that input to a spe­cific range of val­ues. Another use would be to hook the out­put of the Touch­pad to the inputs of two Slid­ers. This way you have one con­troller that can con­trol two con­trollers simul­ta­ne­ously. (Addi­tion­ally, this pre­serves the last value of the Touch­pad unless of course you move the Slider inde­pen­dent of the Touch­pad.) Another slick use is one that I’ve seen requested on the forums. If you hide the over­flow of the Touch­pad and then nest a really wide div that con­tains thumb­nails for prod­ucts, you can then limit the out­put of the Touch­pad to hor­i­zon­tal values—the ver­ti­cal val­ues are sim­ply clamped to 0—and then use the call­back to set the left coör­di­nate of the child div. Now you can scroll through your prod­ucts with­out an ugly scrollbar.

If this sounds like some­thing you can use and you can’t wait til the devel­op­ers choose to add it to the trunk, then go visit the URL above. Then sim­ply down­load and run the attached diff file on your script.aculo.us instal­la­tion using Sub­ver­sion. I rec­om­mend you run the func­tional test included in the patch (tests/run_functional_test.html –> click on touchpad_test in the left frame) to see some exam­ples of the touch­pad in action.

script.aculo.us is at ver­sion 1.6.4 at the time of this writing.

Comments are closed.