Mike Mahemoff (@mahemoff)
Paul Kinlan (@paul_kinlan)
May 11, 2011
Twitter: #chrome
Feedback: goo.gl/VRi5f
@Mahemoff
@Paul_Kinlan
<!doctype html>
<html>
<body>
<article>
<header>
</header>
<section>
</section>
</article>
<article>
</article>
</body>
</html>
if (Modernizr.history) window.pushState(...)
formFactor.register({
formfactor: "phone",
resources:
["/scripts/phone/jquery.touch.js",
"/scripts/phone/controller.js",
"/css/phone.css"]
},
...
});
phone.js
window.addEventListener("articlechanged", function() {
// Do something cool with the UI to show the new article
});
window.addEventListener("categorychanged", function() {
// Do something cool with the UI to show the new category
});
<html class="menuState"></html> <html class="categoryState"></html> <html class="articleState"></html> <html class="articleState refreshing"></html>
.articleState article.active{
overflow: visible;
}
.articleState article.active .story {
display: block;
padding: 0 1em 1em 0;
text-align: justify;
}.articleState {
article.active {
overflow: visible;
.story {
display: block;
padding: 0 1em 1em 0;
text-align: justify;
}
}
}@bgcolor1: #788058; @color1: white; @bgcolor2: #9E9B59; @color2: white;
article {
h2 {
background-color: @bgcolor1;
}
h2:hover {
background-color: saturate(@bgcolor1, 10%);
}
}
Mobile === High latency...
$("a").click(function(e) {
fetchArticle(this.id);
e.preventDefault();
});2000: example.com/category/technology
2006: example.com/#category_technology
2009: example.com/#!category_technology
example.com/category/technology
window.pushState(
{}, "Business News", "/business"
);
Change UI when URL changes
window.onpopstate = function(e) {
var url = document.location;
if(url.indexOf("/business") > 0)
fetchCategory("business");
};
var app = new routes();
app.get("/:category", function(req) {
fetchCategory(req.params.category, "json");
});
app.get("/:category/:article", function(req) {
fetchArticle(req.params.category, req.params.article);
});
{{#articles}}
<article id="{{id}}" name="{{categoryId}}">
<header>
<h1>{{title}}</h1>
<img class="thumbnail" src="{{thumbnail}}" />
<div class="summary">{{{shortDescription}}}</div>
</header>
</article>
{{/articles}}
<html manifest="cache.manifest">
CACHE MANIFEST
# Timestamp {{now}}
# CSS
/css/base.css
/css/tablet.css
# SCRIPTS
/scripts/controller.js
/scripts/tablet/controller.js
NETWORK:
*
if(xhr.status == 200) {
window.localStorage[url] = xhr.responseText; // <- Save the data
callback(xhr.responseText);
}
else {
// There has been an error, use the saved data.
callback(window.localStorage[url]);
}
example.com/#category_technology
example.com/category/technology
el.ontouchstart = function(ev) {
x = ev.clientX;
y = ev.clientY;
};el.ontouchend = function(ev) {
...
};$(".categories").touch({
swipeX: function() { ... }
swipeY: function() { ... }
moveX: function() { ... }
moveY: function() { ... }
click: function() { ... }
longHold: function() { ... }
});var startEvent = Modernizr.touch ? "touchstart":"mouseEnter";
window.addEventListener(startEvent, function() { ... });
Attach USB
./adb devices ./adb -s deviceid logcat| grep I/browser
Read more: goo.gl/iK0PX
<meta name="viewport"
content="width=device-width">
<meta name="viewport"
content="width=device-width,
minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">@media screen and (orientation:landscape) {
article img.thumbnail {
display: block;
}
}
@media screen and (orientation:portrait) {
article img.thumbnail {
display: none;
}
}
Feedback: http://goo.gl/VRi5f
jQuery: jQuery.com
LessCSS: lesscss.org
Modernizr: github.com/modernizr/modernizr
FormfactorJS: github.com/PaulKinlan/formfactor
LeviRoutes: github.com/PaulKinlan/leviroutes
TouchLib: bit.ly/c1pxKA