Although my team is in the early stages of developing Theoryville, we’re always thinking ahead when it comes to our interface. We think the iPad is going to be huge in the academic world, and we’d love to give people the satisfaction of doing science with the tap of a finger, Avatar–style. But rather than splitting our development efforts between a website and a dedicated iPad app, we decided to make our site iPad-compatible by introducing a few behavioral tweaks. I recently coded the first of these tweaks into a small jQuery plugin, which I’m now releasing as an open-source project under the MIT License and giving its own home at http://jqtap.org.
This is an early effort, and I’m hoping that it will grow into a much more robust and feature-rich project, just as jqTouch has grown to become a top-notch way to develop dedicated iPhone webapps. jqTap is not a substitute for jqTouch: Whereas jqTouch is for creating separate versions of sites aimed specifically at devices using mobile WebKit, jqTap is for sites that want to play two different tunes, one for mice and one for fingers.
When you initialize jqTap, it automatically detects whether you’ve got a touchscreen or a mouse. (Actually, it currently only detects iPhone and iPad touchscreens. If there’s a JS library out there for touchscreen detection, let me know!) Then, by default, it hides every DOM element with the class mouse if you’re on a touchscreen, and hides everything with class touch if you’ve got a mouse. This lets you alter details of your site; for instance, using a couple of spans, you can say either “Click here” or “Tap here” as appropriate. You can make your own code conditional on the touch/mouse mode using the $.jqTap.mode value, or you can pass a function into $(selector).ifTouch() or $(selector).ifMouse(). For instance, if there are Twitter-style hover controls on your site, you could wrap the code that hides them in ifMouse(); or if they’re hidden by CSS, override that CSS within an ifTouch() block.
All of that is pretty trivial. The cool part is the added events. More of these will be added in the future, but here’s what jqTap has to offer so far:
tap(): jqTap is intended to be a harmless drop-in, soclick()events will continue to work on both touch and mouse interfaces. However,tap()overrides them on touchscreen devices, allowing you to replace the default click functionality as needed. [Note: In order to overrideclick()events,tap()must be defined later. This will be addressed in the next release.]tapOut(): Responds to a touchscreen tap outside of an element.hoverOrTap(): Equivalent tohoverfor a mouse interface, responding tomouseenter()andmouseleave()events. Since those events don’t exist on a touchscreen,hoverOrTap()responds totap()andtapOut()instead.
Go ahead and grab the source at GitHub. Feedback would be much appreciated. Feedback with code contributions, doubly so!
Tags: jqTapNo Comments

0 responses so far ↓
Comments are closed.