58
Programación Web con HTML5 Campus Party 2011 #CPES15 - #CPIN Parte 1

Programación web con HTML5

Embed Size (px)

DESCRIPTION

Taller realizado en la Campus Party Valencia 2011

Citation preview

Page 1: Programación web con HTML5

Programación Web con HTML5 Campus Party 2011

#CPES15 - #CPINParte 1

Page 2: Programación web con HTML5

Jorge del Casar@jorgecasar

Madrid Google Technology User GroupGTUG Madrid

·Frontend Spain

·ShoTools.com

Page 3: Programación web con HTML5

¿Qué NO es HTML5?

CSS3JS APIs (GEOlocation, workers, Drag&Drop, Web storage...)

Web Apps

Page 4: Programación web con HTML5

¿Qué NO es HTML5?Todo lo que esté fuera del lenguaje de marcado

Page 5: Programación web con HTML5

¿Qué es HTML5?

Lenguaje de marcadoWeb FormsVideo & AudioCanvasSVG

Page 6: Programación web con HTML5

¿Qué es HTML5?La base de las aplicaciones web

Page 7: Programación web con HTML5

Web Apps

HTML5

JS APis

canvasvideo

audio

web forms

SVG

GEOlocation

Drag & Drop

Storage CSSCSS1

CSS2.1

CSS3

Silverlight Flash

Page 8: Programación web con HTML5

Historia reciente

Page 9: Programación web con HTML5

Formada por gente de Mozilla, Opera y Apple para trabajar en avanzar HTML en respuesta a la decisión de la W3C de abandonar HTML en favor de tecnologías basadas en XML

2004 - WHATWG

Page 10: Programación web con HTML5

Se forma el grupo de trabajo HTML para trabajar conjuntamenteAmbos grupos trabajaron juntos en el desarrollo de la especificación HTML5

2007 - WHATWG + W3C

Page 11: Programación web con HTML5

Reconociendo el valor del grupo de trabajo de XHTML 2 la W3C decide abandonar el desarrollo

2009 - R.I.P. XHTML

Page 12: Programación web con HTML5

2011 - Logo HTML5http://www.w3.org/html/logo/

Page 13: Programación web con HTML5

Semántica

Dar significado a la estructura

Set de etiquetas más ricas

RDFa

Microdatos

Microformatos

Page 14: Programación web con HTML5
Page 15: Programación web con HTML5

sectionnav

section

header nav

asidearticle article article

footer

figure figurevideo

figcaptionfigcaption

header header header

header

Page 16: Programación web con HTML5

Nuevas etiquetas

articleasid

e

audio

canvasdata

list

commanddetailsfigure

figcaption

footer

header

hgroup

keygen

nav meter

outputvideo

time

source

summary

wbr

mark

progress

rubyrt

rp

Page 17: Programación web con HTML5

Offline & almacenamiento

Aplicaciones web sin conexión

Caché

Local storage

Indexed DB

File API

Page 18: Programación web con HTML5

Web storage

Pares etiqueta/valorEtiqueta: stringValor: cualquier objeto Javascript

var input = document.querySelector(‘input[name=‘nombre’]’);storageSaveButton.addEventListener(‘click’, function(){ window.localStorage.setItem(‘nombre’, input.value);}, false);input.value = window.localStorage.getItem(‘nombre’);

Page 19: Programación web con HTML5

Offline web aplications

Navegación offlineRecursos cacheados cargan más rápidoSolo descarga los recursos que cambian

<html manifest=”cache.appcache”>window.applicationCache.addEventListener(‘updateready’, function(e){ if(window.applicationCache.status == window.applicationCache.UPDATEREADY) { window.applicationCache.swapCache(); if(confirm(‘Una nueva versión está disponible. ¿Descargar?’)) { window.location.reload(); } }}, false);

Page 20: Programación web con HTML5

Acceso al dispositivo

Geolocalización API

Micrófono

Cámara

Datos locales(contactos y eventos)

Orientación

Page 21: Programación web con HTML5

Drag & Drop

document.addEventListener(‘dragstart’, function(e){ event.dataTransfer.setData(‘text’, ‘Texto personalizado’); event.dataTransfer.effectAllowed = ‘copy’;}, false);

Page 22: Programación web con HTML5

API de Geolocalización

if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(showPosition, handlePositionError);}function showPosition(position) { var latLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude); var marker = new google.maps.Marker({position: latLng, map: map }); map.setCenter(latLng);}

Page 23: Programación web con HTML5

Conectividad

Chats en tiempo real

Juegos más rapidos

Mejor comunicación

Notificaciones Push(Web Sockets, Server-Sent Events)

Page 24: Programación web con HTML5

WebSockets

var socket = new WebSocket(url);socket.onopen = function(e) { socket.send(‘Hola, socket’);}socket.onmessage = function(e) { alert(e.data);}socket.close = function(e) { alert(‘Adios’);}

Page 25: Programación web con HTML5

Multimedia

Audio

Video

Page 26: Programación web con HTML5

3D, gráficos y efectos

SVG

Canvas

WebGL

CSS3 3D

Page 27: Programación web con HTML5

SVG

<svg xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg" height="100%" width="100%" viewBox="0 0 512 512" version="1.1"><polygon points="74.633,100.62 437.37,100.62 404.32,470.82 255.78,512 107.64,470.88" fill="#E44D26"/><polygon points="376.03,447.25 404.27,130.89 256,130.89 256,480.52" fill="#F16529"/><polygon points="195.91,268.22 191.76,221.72 256,221.72 256,176.3 255.84,176.3 142.13,176.3 143.22,188.49 154.38,313.63 256,313.63 256,268.22" fill="#EBEBEB"/><polygon points="255.8,386.21 205.23,372.55 201.99,336.33 177.42,336.33 156.41,336.33 162.77,407.63 255.79,433.46 256,433.4 256,386.15" fill="#EBEBEB"/> <path d="m108.38,0h23.077v22.8h21.11v-22.8h23.078v69.044h-23.08v-23.12h-21.11v23.12h-23.077v-69.044z"/><path d="M205.99,22.896h-20.312v-22.896h63.72v22.896h-20.327v46.148h-23.078v-46.148z"/><path d="m259.51,0h24.063l14.81,24.26,14.78-24.26h24.072v69.044h-22.977v-34.222l-15.877,24.549h-0.397l-15.89-24.549v34.222h-22.58v-69.044z"/><path d="m348.72,0h23.084v46.222h32.453v22.822h-55.53v-69.044z"/><polygon points="255.84,313.63 311.76,313.63 306.49,372.52 255.84,386.19 255.84,433.44 348.94,407.63 349.62,399.96 360.29,280.41 361.4,268.22 349.16,268.22 255.84,268.22" fill="#FFF"/><polygon points="255.84,204.51 255.84,221.6 255.84,221.72 365.38,221.72 365.38,221.72 365.53,221.72 366.44,211.51 368.51,188.49 369.6,176.3 255.84,176.3" fill="#FFF"/></svg>

Page 28: Programación web con HTML5

Canvas

function draw() { var canvas = document.getElementById(“canvas”); if (canvas.getContext) { var ctx = canvas.getContext(“2d”);

ctx.fillStyle = “rgb(40,0,0)”; ctx.fillRect (20, 20, 65, 60);

ctx.fillStyle = “rgba(0, 0, 160, 0.5)”; ctx.fillRect (40, 40, 65, 60); }}

Page 29: Programación web con HTML5

Rendimiento e integración

Web Workers

XMLHttpRequest 2

Page 30: Programación web con HTML5

Web Workers

// main.jsvar worker = new Worker(‘tarea.js’);worker.onmessage = function(e) { alert(e.data);};worker.postMessage(‘data’);

// tarea.jsself.onmessage = function(e) { // Algunas tareas... self.postMessage(‘recibido: ’ e.data);}

Page 31: Programación web con HTML5

Estilos CSS3

Estilos

Efectos

Web Open Font

Page 32: Programación web con HTML5

Insignias

Page 33: Programación web con HTML5

Progressive Enhancement

Page 34: Programación web con HTML5

Graceful Degradation

Page 35: Programación web con HTML5

¿Cómo empezar?

Page 36: Programación web con HTML5

XHTML 1.0 Strict

HTML5

!DOCTYPE

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<!DOCTYPE html>

Page 37: Programación web con HTML5

XHTML 1.0 Strict

HTML5

Encoding

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

<meta charset="utf-8" />

Page 38: Programación web con HTML5

XHTML 1.0 Strict

HTML5

Links

<link rel="stylesheet" type="text/css" href="style.css"/>

<link rel=stylesheet href=style.css>

Page 39: Programación web con HTML5

XHTML 1.0 Strict

HTML5

Script

<script type="text/javascript" src="jquery.js"></script>

<script src=jquery.js></script>

Page 40: Programación web con HTML5

Polyfills

html5shim

<!-- [if lt IE 9]><script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script><![endif]-->

Page 41: Programación web con HTML5

DemoConvertir una web cualquiera a HTML5

Page 42: Programación web con HTML5

Programación Web con HTML5 Campus Party 2011

#CPES15 - #CPINParte 2

Page 43: Programación web con HTML5

Concurso GTUGConvertir una web a HTML5

versiones tablet y smartphone

Page 44: Programación web con HTML5

Premio del concurso

Page 45: Programación web con HTML5

Características Chrome Book

12,1 pulgadas1,48KgIntel® AtomTM Dual-CoreWebcam HD2 USBRanura tarjetas 4 en 1Minipuerto VGA

Page 46: Programación web con HTML5

HTML5 ★ BOILERPLATE

Todos los navegadores (IE6)Preparado para HTML5.Recomendaciones sobre caché y compresiónConfiguración por defecto basada en buenas prácticasOptimizaciones para navegadores móvilesMejora progresiva con degradación gradual … sí, lo conseguimos!Clases específicas para IEClases .no-js y .jsCompleta e interconectada test suite

Page 47: Programación web con HTML5

HTML5 ★ BOILERPLATE

Medir el rendimiento de Javascriptconsole.logCSS para impresiónMarcado y estructura CSS adaptables a Smartphones y tabletsAjuste pngfix para IE6 incluído.Clases .clearfix, .visuallyhidden.htaccess para HTML5 y mayor velocidadAlojamiento CDN de jQuery con sistema de anticaídas

Page 48: Programación web con HTML5

<html>

Detectar el navegadorDetectar capacidades

<!--[if lt IE 7 ]> <html class="no-js ie6" lang="es"> <![endif]--><!--[if IE 7 ]> <html class="no-js ie7" lang="es"> <![endif]--><!--[if IE 8 ]> <html class="no-js ie8" lang="es"> <![endif]--><!--[if (gte IE 9)|!(IE)]><!--> <html class="no-js" lang="es"> <!--<![endif]-->

Page 49: Programación web con HTML5

Chrome Frame

Google Chrome en IE

<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

Page 50: Programación web con HTML5

Librerías que usa

jQuery · http://jquery.com/

QUnit · http://docs.jquery.com/Qunit

modernizr · http://www.modernizr.com/

DD_belatedPNG · http://www.dillerdesign.com/experiment/DD_belatedPNG/

Page 51: Programación web con HTML5

jQuery

31KB (Minified and Gzipped)Soporta selectores CSS3 y másIE 6.0+, FF 2.0+, Safari 3.0+, Opera 9.0+, Chrome

Page 52: Programación web con HTML5

QUnit

Unit testing para javascript

test("a basic test example", function() { ok( true, "this test is fine" ); var value = "hello"; equals( "hello", value, "We expect value to be hello" );});module("Module A");test("first test within module", function() { ok( true, "all pass" );});test("second test within module", function() { ok( true, "all pass" );});module("Module B");test("some other test", function() { expect(2); equals( true, false, "failing test" ); equals( true, true, "passing test" );});

Page 53: Programación web con HTML5

Modernizr

compatibilidad con HTML5 y CSS3

Page 54: Programación web con HTML5

Modernizr

soporte PNG transparentes en IE6

Page 55: Programación web con HTML5

Formularios

Page 56: Programación web con HTML5

Nuevos atributos

placeholder

autofocus

required

novalidate

<input id="buscar" placeholder=”Buscar” autofocus required><script>if (!("autofocus" in document.createElement("input"))) { document.getElementById("buscar").focus();}var elements = document.getElementsByTagName("INPUT");for (var i=0; i<elements.length; i++) { elements[i].setCustomValidity("This field cannot be left blank");}</script>

Page 58: Programación web con HTML5

<mark>Gacias</mark>

@jorgecasar#CPES15 - #CPIN