Tuesday, May 4, 2010

iPhone Touch Events

Dear Apple,

This is one area that is fairly poorly documented.

In javascript with mobile safari I want to capture the mousemove event on a canvas object. It works fine in normal browsers and I'm using the technique on top here to do it in Firefox, but mobile safari won't let you use mousemove in the same way.

Mobile safari actually provides and even better event for you to use. It's called touchmove. Touch move already knows if your finger is on the screen so you don't have to check for that in your callback function. The code below replaces the code above when developing for mobile safari, however leaving them all in works well and provides mobile safari + desktop browser support for the application



The old way:
$("#canvas").mousedown(function(e) {
 e.preventDefault();
 click = true;
});
   
$("#canvas").mousemove(function(e) {
 e.preventDefault();
 if (click) { 
  sharky.y =  e.clientY;
 }
}); 

$("#canvas").mouseup(function(e) {
 e.preventDefault();
 click = false;
 sharky.y =  e.layerY;
 return false;
});



The new way:
$("#canvas").bind("touchmove", {}, function(e) {
  e.preventDefault();
  touch = window.event.targetTouches[ 0 ];
  sharky.y =  touch.clientY;
});
   


Thanks to:
Touching and Gesturing on the iPhone
Apple Developer Reference
Drawing On The iPhone Canvas With jQuery And ColdFusion

Wednesday, April 28, 2010

My iPhone App

Mobile Web Reserach and Twitter Info

I did some research about how much use each mobile platform gets for browsing the web.

I looked at two different reports, which both basically said the same thing.

In North America, when people use the mobile web they are pretty much on iPhone, Android or Blackberry.

iPhone: 50%-60%
Android: 10%-30%
Blackberry: 5%-10%
The rest: < 5% each

http://metrics.admob.com/2010/01/mobile-browsing-trends-from-quantcast/
http://metrics.admob.com/2010/01/december-2009-mobile-metrics-report/

Just wanted to think about twitter for a minute. Twitter gets huge percentage of its hits from mobile and processing almost a billion SMS messages a month.
http://blog.twitter.com/2010/04/cloudhopping.html

They've also said that their blackberry app gets 8% of their new sign-ups:
http://www.readwriteweb.com/archives/just_the_facts_statistics_from_twitter_chirp.php

And a WAP vs Mobile Web discussion:
http://www.balanceinteractive.com/blog/10/01/mobile-websites-101-wap-vs-css

iPhone animated moving image tutorial

I've been trying to figure out how to animate a sheep across a screen. I have looked a many tutorials. This is by far the most comprehensive tutorial I have seen so far.

http://www.permadi.com/blog/2009/05/iphone-sdk-bouncing-and-rotating-ball-example/

Here is one that lets you move an image with touch:
http://www.roseindia.net/tutorial/iphone/examples/iphone-DoubleImageMoveasd.html

Wednesday, April 21, 2010

.closest does not mean closest!

I found out recently that jQuery's closest() function doesn't find the nearest instance of the selector, but instead find the nearest parent that matches the selector. This is a really important difference and I just thought I would highlight it!

http://api.jquery.com/closest/

Monday, April 19, 2010

Functionally Equivalent


  // not sure if we need $(this).dequeue(), but it works alright
  $(this).before( $(""+msg+"").delay(1000).fadeOut("slow").queue(function() { $(this).remove(); $(this).dequeue(); })  );
  
  // use the built-in callback
  $(this).before( $(""+msg+"").delay(1000).fadeOut("slow", function() { $(this).remove()}) );
 

Awesome Website

http://html5demos.com/