Mobile UI
HTML
- allow app to be installed to homescreen
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="apple-touch-icon-precomposed" href="/mobile/icon.png" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
CSS
/* turn off the annoying highlight on a tap*/
{
-webkit-tap-highlight-color: transparent;
-moz-tap-highlight-color: transparent;
tap-highlight-color: transparent;
}
/* prevent the user from highlighting any text */
{
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
/* allow highlighting text in inputs */
input {
-webkit-user-select: text;
-moz-user-select: text;
-ms-user-select: text;
user-select: text;
}
JS
- don't use onclick! Use touch events!
-
jquery ontap plugin (include after jquery)
- api:
$('#elem').ontap(onDown, onUp, onTap, onLong)
-
$('#elem').onButtonTap(onTap, onLong)
- ontap, but applies buttonDown class and buttonUp class on down and up
- modularize your code so you can share js between your desktop/mobile versions
- see UI.js in the sample app
- patch bind on iOS
// iOS5 or less does not have .bind so add it if needed (iOS6 has it!)
function patchBind(){
if (Function.prototype.bind === undefined){
Function.prototype.bind = function (newScope) {
var self = this;
return function () {
var args = Array.prototype.slice.call(arguments);
return self.apply(newScope || null, args);
};
};
}
}
suggested folder structure / server design
- static
- put some middleware in your server to:
- check the user agent of the incoming request
- check if the file exists on /mobile or /desktop depending on the user apent
- prepend /mobile or /desktop to the url if the file exists
- there's an example of this in the todo app