Shake gesture detection in PhoneGap / Cordova (migrated from gist https://gist.github.com/leecrossley/4078996)