Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

THORSTEN RINNE Team Lead Engineering 36 Jahre

Slide 3

Slide 3 text

WER BIN ICH? • Sebastian Springer • https://github.com/sspringer82 • @basti_springer

Slide 4

Slide 4 text

Wer seid ihr?

Slide 5

Slide 5 text

AGENDA • HTML5 JavaScript APIs • CSS3 Neuerungen • ECMAScript 5 Features • Beispielapplikation

Slide 6

Slide 6 text

VORAUSSETZUNG

Slide 7

Slide 7 text

SERVERSEITE

Slide 8

Slide 8 text

https://github.com/sspringer82/chat

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

STRUKTUR • HTML (Templates) • CSS • LESS/SASS Quellen • JavaScript (Libraries und eigener Code) • Tests • Medien wie Bilder, Fonts, Audio, Video usw.

Slide 11

Slide 11 text

Hallo, Berlin

Hallo, Berlin

Slide 12

Slide 12 text

Hallo, Berlin

Hallo, Berlin

Slide 13

Slide 13 text

Hallo, Berlin

Hallo, Berlin

Slide 14

Slide 14 text

Hallo, Berlin

Hallo, Berlin

Slide 15

Slide 15 text

Hallo, Berlin

Hallo, Berlin

Slide 16

Slide 16 text

Hallo, Berlin

Hallo, Berlin

Slide 17

Slide 17 text

Hallo, Berlin

Hallo, Berlin

Slide 18

Slide 18 text

Slide 19

Slide 19 text

Hallo, Berlin

Hallo, Berlin

Slide 20

Slide 20 text

JAVASCRIPT API • FullScreen API • Forms • Webworkers • Geolocation • Storage • Offline Application

Slide 21

Slide 21 text

FULL SCREEN

Slide 22

Slide 22 text

FULL SCREEN var elem = $('#content')[0]; if (elem.requestFullscreen) { elem.requestFullscreen(); } else if (elem.mozRequestFullScreen) { elem.mozRequestFullScreen(); } else if (elem.webkitRequestFullscreen) { elem.webkitRequestFullscreen(); } go FullScreen

Slide 23

Slide 23 text

FULL SCREEN if(document.cancelFullScreen) { document.cancelFullScreen(); } else if(document.mozCancelFullScreen) { document.mozCancelFullScreen(); } else if(document.webkitCancelFullScreen) { document.webkitCancelFullScreen(); } cancel FullScreen

Slide 24

Slide 24 text

FULL SCREEN • Bitte mit Vorsicht verwenden • Styling für z.B. Hintergrund: • -webkit-full-screen • -moz-full-screen

Slide 25

Slide 25 text

FORMS

Slide 26

Slide 26 text

ELEMENTE

Slide 27

Slide 27 text

PROGRESS var interval = setInterval(function () { var progress = $('progress'); if (progress.val() < progress.attr('max')) { progress.val(progress.val() + 1); } else { clearInterval(interval); } }, 10);

Slide 28

Slide 28 text

METER $('meter').val(100); Keine Progress-Bar! Zur Anzeige von Werten in einem bestimmten Wertebereich

Slide 29

Slide 29 text

DATALIST Angela Merkel Gerhard Schröder ...

Slide 30

Slide 30 text

OUTPUT $('#output').on('input', function () { var nr1 = parseInt($('#nr1').val()); var nr2 = parseInt($('#nr2').val()); $('output').val(nr1 + nr2); }); Element zur Ausgabe von Berechnungen

Slide 31

Slide 31 text

Slide 32

Slide 32 text

INPUT TYPES • Viele Aufgaben, die bisher mit JavaScript erledigt wurden, funktionieren jetzt mit HTML5 nativ • Können kaum angepasst werden

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

INPUT TYPES • tel • search • url • email • date • month • week • time • number • range • color

Slide 35

Slide 35 text

HINWEIS datetime und datetime-local sind deprecated!

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

ATTRIBUTE

Slide 38

Slide 38 text

ATTRIBUTE • autofocus • placeholder • form • required • autocomplete • pattern • novalidate • formaction • formenctype • formmethod • formnovalidate • formtarget

Slide 39

Slide 39 text

WEBWORKER

Slide 40

Slide 40 text

WEBWORKER • Workerthreads im Browser • Rechenintensive Prozesse auslagern • Zugriff auf: navigator, location, XMLHttpRequest,... • Kein Zugriff auf: DOM, window, document, parent

Slide 41

Slide 41 text

WEBWORKER var worker = new Worker('/js/webworker.js'); worker.onmessage = function (msg) { $('#result').html(msg.data); };

Slide 42

Slide 42 text

WEBWORKER var i, n = 1, results = 1; outerLoop: while (true) { n += 1; for (i = 2; i <= Math.sqrt(n); i += 1) { if (n % i === 0) { continue outerLoop; } } self.postMessage(n); results += 1; if (results >= 1000) { self.close(); } }

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

WEBSOCKETS

Slide 45

Slide 45 text

WEBSOCKETS • Bidirektionale Kommunikation zwischen Client und Server • Protokoll auf TCP-Basis • Eventbasiert • Sichere Variante wss://

Slide 46

Slide 46 text

WEBSOCKETS var addr = 'ws://localhost:8181/'; var socket = new WebSocket(addr, 'myapp'); $('#sayHello').on('click', function () { socket.send('Hello Server'); }); socket.onmessage = function (msg) { $('#response').html(msg.data); };

Slide 47

Slide 47 text

WEBSOCKETS var WebSocketServer = require('websocket').server; var http = require('http'); var server = http.createServer().listen(8181); wsServer = new WebSocketServer({ httpServer: server, autoAcceptConnections: false }); wsServer.on('request', function(req) { var connection = req.accept('myapp', req.origin); connection.on('message', function(message) { connection.sendUTF("Hello Client!"); console.log(message.utf8Data); }); });

Slide 48

Slide 48 text

WEBSOCKETS

Slide 49

Slide 49 text

GEOLOCATION

Slide 50

Slide 50 text

GEOLOCATION • Aktuelle Position des Clients • WLAN-Position • GPS-Position

Slide 51

Slide 51 text

GEOLOCATION var geolocation = navigator.geolocation; geolocation.getCurrentPosition(function (pos) { var posString = 'Lat: ' + pos.coords.latitude + ' Long: ' + pos.coords.longitude; $('#position').html(posString); });

Slide 52

Slide 52 text

GEOLOCATION

Slide 53

Slide 53 text

BEISPIEL

Slide 54

Slide 54 text

GEOLOCATION

Slide 55

Slide 55 text

<script src="/js/geolocation2.js" /> <body> <div id="map-canvas"></div> </body> </html>

Slide 56

Slide 56 text

function initialize() { navigator.geolocation.getCurrentPosition(function (pos) { var myLatlng = new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude); var mapOptions = { zoom: 4, center: myLatlng, mapTypeId: google.maps.MapTypeId.ROADMAP } var map = new google.maps.Map(document.getElementById('map- canvas'), mapOptions); var marker = new google.maps.Marker({ position: myLatlng, map: map, title: 'Hello World!' }); }); } google.maps.event.addDomListener(window, 'load', initialize);

Slide 57

Slide 57 text

STORAGE

Slide 58

Slide 58 text

STORAGE • Local Storage - zeitlich unbegrenzt • Session Storage - nur für eine Browser-Session • IndexedDB • Web SQL

Slide 59

Slide 59 text

Items in Storage:  
keyvalue
key:
value:
OK

Slide 60

Slide 60 text

var writeLine = function (k, v) { var line = '' + k + '' + v + 'delete' + ''; $('#content tbody').append(line); writeStorageLength(); }; for (var i = 0; i < localStorage.length; i++) { k = localStorage.key(i); v = localStorage.getItem(k); writeLine(k, v); }

Slide 61

Slide 61 text

var writeStorageLength = function () { $('#itemCount').html(localStorage.length); }; $('#save').on('click', function () { var k = $('#storageKey').val(); var v = $('#storageVal').val(); localStorage.setItem(k, v); writeLine(k, v); }); $('#content').on('click', function (e) { localStorage.removeItem($(e.target).data('value')); $(e.target).closest('tr').remove(); writeStorageLength(); });

Slide 62

Slide 62 text

No content

Slide 63

Slide 63 text

OFFLINE APPLICATION

Slide 64

Slide 64 text

OFFLINE APPLICATION • Dateien werden nur einmalig vom Server geholt • Manifestdatei enthält die Konfiguration

Slide 65

Slide 65 text

OFFLINE APPLICATION CACHE MANIFEST index.html js/articles.js js/customers.js js/init.js js/jquery.js js/orders.js css/bootstrap.css?v=1 NETWORK: orders offline.manifest

Slide 66

Slide 66 text

OFFLINE APPLICATION

Slide 67

Slide 67 text

OFFLINE APPLICATION Creating Application Cache with manifest http://localhost:8080/offline.manifest Application Cache Checking event Application Cache Downloading event Application Cache Progress event (0 of 7) http://localhost:8080/js/customers.js Application Cache Progress event (1 of 7) http://localhost:8080/css/bootstrap.css?v=1 Application Cache Progress event (2 of 7) http://localhost:8080/js/jquery.js Application Cache Progress event (3 of 7) http://localhost:8080/js/articles.js Application Cache Progress event (4 of 7) http://localhost:8080/index.html Application Cache Progress event (5 of 7) http://localhost:8080/js/init.js Application Cache Progress event (6 of 7) http://localhost:8080/js/orders.js Application Cache Progress event (7 of 7) Application Cache Cached event

Slide 68

Slide 68 text

No content

Slide 69

Slide 69 text

CSS LEVEL 3 • In der Entwicklung seit 2000 • Modularer Aufbau • Bekannte Module • Selectors Level 3 • Media Queries

Slide 70

Slide 70 text

BROWSER PREFIXES • -moz- • -ms- / -mso- • -kthml- • -o- • -webkit- • n/a

Slide 71

Slide 71 text

BROWSER PREFIXES .round-corners { border-radius: 12px; -moz-border-radius: 12px; -webkit-border-radius: 12px; -o-border-radius: 12px; -khtml-border-radius: 12px; }

Slide 72

Slide 72 text

Opacity Opacity Opacity Opacity Opacity

Slide 73

Slide 73 text

OPACITY .my-opacity { opacity: 0.8; -ms-filter: "alpha(opacity=80)"; filter:alpha(opacity=80); }

Slide 74

Slide 74 text

GRADIENTEN

Slide 75

Slide 75 text

GRADIENTEN background: linear-gradient(135deg, #4c4c4c 0%,#595959 12%,#666666 25%,#474747 39%,#2c2c2c 50%,#000000 51%,#111111 60%,#2b2b2b 76%,#1c1c1c 91%,#131313 100%);

Slide 76

Slide 76 text

ANYONE?

Slide 77

Slide 77 text

GRADIENTEN filter: progid: DXImageTransform.Microsoft.gradient( startColorstr='#4c4c4c', endColorstr='#131313', GradientType=1 );

Slide 78

Slide 78 text

BORDER RADIUS

Slide 79

Slide 79 text

BORDER RADIUS .curved { -moz-border-radius: 20px; -webkit-border-radius: 20px; -khtml-border-radius: 20px; border-radius: 20px; }

Slide 80

Slide 80 text

BOX SHADOW

Slide 81

Slide 81 text

BOX SHADOW .shadow { -webkit-box-shadow: 2px 2px 2px 2px rgba(0, 0, 0, 1); box-shadow: 2px 2px 2px 2px rgba(0, 0, 0, 1); }

Slide 82

Slide 82 text

MEDIA QUERIES

Slide 83

Slide 83 text

MEDIA QUERIES @media (min-width: 1200px) { ... } @media (min-width: 768px) and (max-width: 979px) { ... } @media (max-width: 767px) { ... } @media (max-width: 480px) { ... }

Slide 85

Slide 85 text

SELECTORS LEVEL3 • p:nth-child(2n) Jedes 2.

Element seines Elternelements • :root Das Rootelement eines Dokuments • :empty Jedes Element ohne Kindelemente

Slide 86

Slide 86 text

SELECTORS LEVEL3 • input:enabled Jedes aktive Element • input:disabled Jedes nicht aktive Element • input:checked Jedes „ge-checkte“ Element (Checkbox)

Slide 87

Slide 87 text

No content

Slide 88

Slide 88 text

GRUNDLAGEN UND FORTGESCHRITTENE THEMEN • Frameworks • ECMAScript 5 • Object.* • JSLint

Slide 89

Slide 89 text

FRAMEWORKS

Slide 90

Slide 90 text

No content

Slide 91

Slide 91 text

ECMASCRIPT 5

Slide 92

Slide 92 text

ECMASCRIPT 5 • http://www.ecma-international.org/publications/files/ECMA-ST/ Ecma-262.pdf • JSON (parse, stringify) • Object.* • strict mode

Slide 93

Slide 93 text

OBJECT.*

Slide 94

Slide 94 text

OBJECT.* • Erweiterbarkeit • Object.preventExtensions(obj) • Object.isExtensible(obj)

Slide 95

Slide 95 text

OBJECT.* • Obj.create(proto, props) • Object.keys(obj) • Object.getOwnPropertyNames(obj) • Object.getOwnPropertyDescriptor(obj, prop) • Object.defineProperty(obj, prop, desc)

Slide 96

Slide 96 text

OBJECT.* • Object.seal(obj)/Object.isSealed(obj) • Keine Änderungen mehr an Eigenschaften • Object.freeze(obj)/Object.isFrozen(obj) • Keine Schreibzugriffe mehr auf Eigenschaften + seal

Slide 97

Slide 97 text

OBJECT.* • Object.defineProperty • set: magic setter function • get: magic getter function • value: default value • configurable: can be deleted • enumerable: can be iterated • writable: can be changed

Slide 98

Slide 98 text

JSLINT JSLint will hurt your feelings

Slide 99

Slide 99 text

JSLINT • „The JavaScript Quality Tool“ • http://www.jslint.com/ • Integriert in • CLI • IDE

Slide 100

Slide 100 text

“USE STRICT”

Slide 101

Slide 101 text

STRICT MODE MEHR FEHLER • Keine versehentlichen globals (ReferenceError) • Schärfere Regeln bei Zuweisungen • Non-writable, getter-only, neue Properties bei non-extensible Objekten • Kein Löschen von nicht löschbaren Eigenschaften (prototype) • Eindeutige Propertynamen • Eindeutige Namen für Argumente (function (a, a, b)...) • Keine Oktalnotation (z.B. 012 - SyntaxError)

Slide 102

Slide 102 text

STRICT MODE EINFACHERE BENUTZUNG • “with” ist verboten • (var x = 1; with (obj) { x};) • Keine neuen Variablen mit “eval” • eval(“var x”); • Keine Variablen löschen • var x = 123; delete x;

Slide 103

Slide 103 text

STRICT MODE EINFACHERE BENUTZUNG • “with” ist verboten • (var x = 1; with (obj) { x};) • Keine neuen Variablen mit “eval” • eval(“var x”); • Keine Variablen löschen • var x = 123; delete x;

Slide 104

Slide 104 text

STRICT MODE EVAL & ARGUMENTS • eval und arguments können nicht mehr mit anderen Werten belegt oder an einen Kontext gebunden werden • arguments kann nicht mehr durch Aliases verändert werden • function func(arg) { var arg = 15; return [arg, arguments[0]]}; • arguments.callee existiert nicht mehr - TypeError

Slide 105

Slide 105 text

STRICT MODE SICHERHEIT • Kein Zugriff mehr auf das globale Objekt aus Funktionen • function f() { return this; } - undefined • Kein Zugriff auf func.arguments und func.caller von außerhalb • Kein Zugriff auf Variablen in einer Funktion von außerhalb

Slide 106

Slide 106 text

STRICT MODE • Reservierte Wörter: implements, interface, let, package, private, protected, public, static, und yield • Keine Funktionsdefinition in Bedingungen und Schleifen

Slide 107

Slide 107 text

REALTIME CHAT

Slide 108

Slide 108 text

SERVERSEITE

Slide 109

Slide 109 text

PACKAGE.JSON { "dependencies": { "express": ">=3.4.x", "jade": ">=0.35.x", "socket.io": ">=0.9.x" } }

Slide 110

Slide 110 text

NPM INSTALL

Slide 111

Slide 111 text

INDEX.JS

Slide 112

Slide 112 text

var express = require('express'); var app = express(); app.get('/', function (req, res) { res.send('Hello World'); }); app.listen(8080);

Slide 113

Slide 113 text

EXPRESS

Slide 114

Slide 114 text

AUFBAU HTTP-Modul Webserver, Request, Response Connect Middleware Express Routing

Slide 115

Slide 115 text

ROUTING app.(url, [callback...], callback) function (req, res, next) { ... next(); } get post put delete ...

Slide 116

Slide 116 text

MIDDLEWARE app.use([path], function) function (req, res, next) { ... next(); }

Slide 117

Slide 117 text

MIDDLEWARE var dir = __dirname + ‘/images’ app.use(‘/images’, express.static(dir)); express.logger() Access Log auf der Konsole express.bodyParser() Zugriff auf req.body express.cookieParser() Cookies in Node.js express.cookieSession({secret: 'mySecret'}) Cookiebasierte Session req.session

Slide 118

Slide 118 text

JADE

Slide 119

Slide 119 text

JADE - TEMPLATE ENGINE • Shortcuts - Attribute, Klassen, IDs • Platzhalter • Mixins • Includes • Extends

Slide 120

Slide 120 text

JADE - EINBINDUNG app.set('views', __dirname + '/app/views'); app.set('view engine', 'jade');

Slide 121

Slide 121 text

SOCKET.IO

Slide 122

Slide 122 text

SOCKET.IO var http = require('http'); var server = http.createServer(app); server.listen(8080); var io = require('socket.io').listen(server); io.sockets.on('connection', function (socket) { socket.on('msg', function(message) { console.log(message); }); });

Slide 123

Slide 123 text

script(src="http://localhost:8080/ socket.io/socket.io.js") var socket = io.connect('http://localhost: 8080'); $('#chat').on('submit', function (e) { e.preventDefault(); var value = $('#message').val(); $('#message').val(''); $('#message').focus(); $('#messages').append(value + '
'); socket.emit('msg', value); return false; });

Slide 124

Slide 124 text

BOWER

Slide 125

Slide 125 text

BOWER • Package Manager • npm install -g bower

Slide 126

Slide 126 text

BOWER • bower search • bower install [#] • --save -> Installation + bower.json • bower update • bower uninstall • bower list • bower lookup

Slide 127

Slide 127 text

BOWER INSTALL • bower install jquery#1.7.0 • bower install git://github.com/pivotal/jasmin.git • bower install http://backbonejs.org/backbone.min.js •

Slide 128

Slide 128 text

BOWER.JSON • name • version • dependencies • main • devdependencies • resolutions

Slide 129

Slide 129 text

BOWER.JSON { "name": "Realtime Chat Application", "version": "0.1.0", "dependencies": { "jquery": "latest" } }

Slide 130

Slide 130 text

GRUNT

Slide 131

Slide 131 text

GRUNT • npm install -g grunt-cli • npm install grunt • Plugins • Gruntfile.js

Slide 132

Slide 132 text

BOOTSTRAP

Slide 133

Slide 133 text

BOOTSTRAP • Scaffolding (Grid, Layout, Responsive) • Base CSS (Buttons, Forms, Tables) • Components (Navigation, Alerts, Pagination) • JavaScript (Modal, Tooltip)

Slide 134

Slide 134 text

BOOTSTRAP <link rel="stylesheet" type="text/css" href="/public/css/bootstrap.min.css"> <link rel="stylesheet" type="text/css" href="/public/css/bootstrap- theme.min.css">

Slide 135

Slide 135 text

BOOTSTRAP

Slide 136

Slide 136 text

LESS

Slide 137

Slide 137 text

LESS Dynamic Stylesheet Language

Slide 138

Slide 138 text

LESS • Variablen • Nested Rules • Mixins

Slide 139

Slide 139 text

LESS - VARIABLEN @background: #FFFFE0; #messages { background-color: @background; }

Slide 140

Slide 140 text

LESS - NESTED RULES #head { background-color: @dark; height:25px; div { color: @light; background-color: @dark; &:hover { background-color: @light; color: @dark; } } }

Slide 141

Slide 141 text

LESS - MIXINS .rounded-corners (@radius: 10px;) { -webkit-border-radius: @radius; -moz-border-radius: @radius; border-radius: @radius; } #info { .rounded-corners(5px); width: 250px; margin: 10px; padding-left: 5px; background-color: lightgreen; }

Slide 142

Slide 142 text

LOGIN

Slide 143

Slide 143 text

No content

Slide 144

Slide 144 text

CHAT

Slide 145

Slide 145 text

No content

Slide 146

Slide 146 text

USER LISTE

Slide 147

Slide 147 text

DISTANZ geolocation

Slide 148

Slide 148 text

HISTORY localstorage

Slide 149

Slide 149 text

LITTLE HELPERS

Slide 150

Slide 150 text

No content

Slide 151

Slide 151 text

No content

Slide 152

Slide 152 text

POLYFILLS

Slide 153

Slide 153 text

POLYFILLS https://github.com/Modernizr/Modernizr/wiki/HTML5-Cross- browser-Polyfills

Slide 154

Slide 154 text

No content

Slide 155

Slide 155 text

yepnope({ test : Modernizr.geolocation, yep : 'normal.js', nope : ['polyfill.js', 'wrapper.js'] });

Slide 156

Slide 156 text

FRAMEWORKS

Slide 157

Slide 157 text

FRAMEWORKS • Bootstrap • Foundation v3 • Foundation v4 • Skeleton • 960.gs • http://responsive.vermilion.com/compare.php

Slide 158

Slide 158 text

No content

Slide 159

Slide 159 text

MOZILLA DEVELOPER NETWORK

Slide 160

Slide 160 text

No content

Slide 161

Slide 161 text

FRAGEN?

Slide 162

Slide 162 text

KONTAKT Sebastian Springer sebastian.springer@mayflower.de Mayflower GmbH Mannhardtstr. 6 80538 München Deutschland @basti_springer https://github.com/sspringer82 Thorsten Rinne [email protected] Yatego GmbH Kobellstr. 15 80336 München Deutschland @ThorstenRinne https://github.com/thorsten