SlideShare a Scribd company logo
1 of 46
Download to read offline
Pavol Hejný
pavolhejny.com
Webové aplikace v
JavaScriptu
27.5.2016 | Praha | ITnetwork.cz
Stránka vs. Aplikace
WWW App
API
server DBDB
View
Controller
WWW
server
Model
HTML
page
Frontend
v JS
Proč?
Rychlost
využití 2D / 3D grafiky
Využití web audio
Využití files API
http://birds.cz/avif/atlas_nest_map.php?rok=2016&druh=Phasianus_colchicus
http://zastavky.birdlife.cz/
Towns.cz
Towns.cz
develop.towns.cz
develop.towns.cz
develop.towns.cz
develop.towns.cz
develop.towns.cz
JS
a
HTML
<body>
<p id="itnetwork">ITnetwork</p>
</body>
<script>
var element = window.document.getElementById
("itnetwork");
element.onclick = function(){
element.style.color = '#3B94E0';
}
</script>
DOM
ITnetwork
DOM vs. jQuery
$('#itnetwork').click(function(){
$(this).css('color','#00ff00');
});
var element = window.document.getElementById
("itnetwork");
element.onclick = function(){
element.style.color = '#00ff00';
}
7
var second=11;
var element =window.document.getElementById
("counter");
var interval = setInterval(function(){
second--;
element.innerHTML = second;
}, 1000);
setTimeout(function(){
alert('Ahoj!');
clearInterval(interval);
}
, 11000);
interval, timeout
https://jsfiddle.net/phejny/xjyerkq2/
var start = null;
var element = document.getElementById("ball");
element.style.position = 'absolute';
function step(timestamp) {
if (!start) start = timestamp;
var progress = timestamp - start;
element.style.top = Math.sin(progress/1000*Math.PI)
*100+100 + "px";
element.style.left = Math.cos(progress/1000*Math.PI)
*100+100 + "px";
window.requestAnimationFrame(step);
}
window.requestAnimationFrame(step);
Animation frame
https://jsfiddle.net/phejny/8nLcpffb/1/
5€ je 135,- kč.
var request = new XMLHttpRequest();
var url = "https://api.fixer.io/latest?symbols=CZK";
request.onreadystatechange = function() {
if (request.readyState == 4 && request.status == 200)
{
var response = JSON.parse(request.responseText);
var rate = response.rates.CZK;
document.getElementById('CZK').innerText = Math.
round(rate*5);
}
};
request.open("GET", url, true);
request.send();
XMLHttpRequest
https://jsfiddle.net/phejny/0y6dbyug/1
XMLHttpRequest vs. jQuery
var url = "https://api.fixer.io/latest?symbols=CZK";
$.get(url)
.done(function(response){
var rate = response.rates.CZK;
$('#CZK').text(Math.round(rate*5));
});
var request = new XMLHttpRequest();
var url = "https://api.fixer.io/latest?symbols=CZK";
request.onreadystatechange = function() {
if (request.readyState == 4 && request.status == 200) {
var response = JSON.parse(request.responseText);
var rate = response.rates.CZK;
document.getElementById('CZK').innerText = Math.round
(rate*5);
}
};
request.open("GET", url, true);
request.send();
https://jsfiddle.net/phejny/0y6dbyug/3
Sync vs. Async
$.get("https://api.fixer.io/latest?symbols=CZK")
.done(function(response){
var rate = response.rates.CZK;
$('#CZK').text(Math.round(rate*5));
});
$.get("https://api.fixer.io/latest?symbols=USD")
.done(function(response){
var rate = response.rates.USD;
$('#USD').text(Math.round(rate*5*100)/100);
});
<?php
$json = file_get_contents("https://api.fixer.io/latest?
symbols=CZK,EUR");
//...
echo('5€ je '.$CZK.',- kč.');
$json = file_get_contents("https://api.fixer.io/latest?
symbols=USD,EUR");
//...
echo('5€ je '.$USD.'$.');
?>
Sync vs. Async
Event
Event
Výsledek
Výsledek
Angular
<!doctype html>
<html ng-app>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5
/angular.min.js"></script>
</head>
<body>
<div>
<input type="text" ng-model="jmeno_cajovny">
<hr>
<h1>Jsme v čajovně {{jmeno_cajovny}}!</h1>
</div>
</body>
</html>
ECMAScript 5
var Position = function(x,y){
this.x= x || 0;
this.y= y || 0;
};
Position.prototype.getDistance = function(position){
return Math.sqrt(Math.pow(position.x-this.x,2)+Math.pow(position.y-
this.y,2));
};
Position.prototype.toString = function(){
return ''+this.x+','+this.y+'';
};
var multiline_string = (function () {/*
Podle
mě
ten nejhorší
způsob :(
*/}).toString().match(/[^]*/*([^]*)*/}$/)[1];
var multiline_string = `V ES6
to jde
bez problémů!`;
var multiline_string = 'Takhle
d*****e
se musí psát
string na více
řádků.';
var multiline_string = 'Nebo' +
'takhle - s tímhle zápisem alespoň umí' +
'pracovat PHPStorm';
var multiline_string =
['Nebo',
'takhle',
].join('n')
String
ECMAScript 6
var Position = class{
constructor(x=0,y=0){
this.x= x;
this.y= y;
}
getDistance(position){
return Math.sqrt(Math.pow(position.x-this.x,2)+Math.pow(position.
y-this.y,2));
}
toString(){
return ''+this.x+','+this.y+'';
}
};
CoffeeScript
transpiler
Position = (x, y) ->
@x = x or 0
@y = y or 0
return
Position::getDistance = (position) ->
Math.sqrt (position.x - (@x)) ** 2+ (position.y - (@y)) ** 2
Position::toString = ->
'' + @x + ',' + @y + ''
Backend
Proč?
Node JS
Přepínání
Rychlost
Sdílení kódu
REST API
používání WS
PHP vs. Node
● Apache
● Jednotlivé stránky
● node, pm2
● Celý server
Response
● http://www.itnetwork.
cz/software/sublime-text?
nastaveni=123#goto173043
● GET, POST, DELETE, HEAD,...
Body
● status code - 200, 404, 403,...
● mime type - text/html
● cache control
● form data, upload,... ● html, js, css, image, pdf,
video,...
Request
Header
Response Headers
alt-svc:quic=":443"; ma=2592000; v="
34,33,32,31,30,29,28,27,26,25"
alternate-protocol:443:quic
cache-control:private, max-age=0
content-encoding:gzip
content-type:text/html; charset=UTF-8
date:Fri, 27 May 2016 11:46:06 GMT
expires:-1
server:gws
status:200
x-frame-options:SAMEORIGIN
x-xss-protection:1; mode=block
Request Headers
URL:https://www.google.cz/search?
q=itnetwork+je+nej&oq=status+code&aqs=ch
rome..69i57.
395j0j7&sourceid=chrome&es_sm=93&ie=UT
F-8
Request Method:GET
Remote Address:216.58.212.67:443
RAW
Browser vs. Node
● window
● <script src="..."></script>
● HTTP klient
● JQuery, Angular
● global
● var module = require("...");
● HTTP server, klient
● Express
Express
Routing
var http = require("http");
http.createServer(function(request, response){
if(request.url=='/') {
response.writeHead(200);
response.end('GET request to the home');
}else
if(request.url=='/objects') {
response.writeHead(200);
response.end('GET request to the objects');
}else{
response.writeHead(404);
response.end('Not fount :( ');
}
}).listen(80);
var express = require('express');
var app = express();
app.get('/', function (req, res) {
res.send('GET request to the home');
});
app.get('/objects', function (req, res) {
res.send('GET request to the objects');
});
Jasmine
testování
describe('lineCollision', function() {
it('//', function () {
expect(T.Math.lineCollision(0,0,10,10,0,2,10,12)).toBe(false);
});
it('/|', function () {
expect(T.Math.lineCollision(0,0,10,10,100,0,100,10)).toBe(false);
});
it('X', function () {
expect(T.Math.lineCollision(0,0,10,10,0,2,2,0)).toBe(true);
});
it('L', function () {
expect(T.Math.lineCollision(0,0,10,10,10,10,10,0)).toBe(true);
});
it('T', function () {
expect(T.Math.lineCollision(0,0,10,0,10,10,10,-10)).toBe(true);
});
it('/', function () {
expect(T.Math.lineCollision(0,0,10,10,1,1,9,9)).toBe(true);
});
it('!', function () {
expect(T.Math.lineCollision(0,0,0,2,0,4,0,10)).toBe(false);
});
});
Middleware
načítání js souborů
HTML
browser includes
<script src="/app/js/00-other/cookie.static.js"></script>
<script src="/app/js/00-other/copy.static.js"></script>
<script src="/app/js/00-other/date.functions.js"></script>
<script src="/app/js/00-other/escape.functions.js"></script>
<script src="/app/js/00-other/generate-file.jquery.js"></script>
<script src="/app/js/00-other/interval.static.js"></script>
<script src="/app/js/00-other/is-image-ok.function.js"></script>
<script src="/app/js/00-other/is.functions.js"></script>
<script src="/app/js/00-other/log.functions.js"></script>
<script src="/app/js/00-other/outer-html.jquery.js"></script>
<script src="/app/js/00-other/select-text.function.js"></script>
<script src="/app/js/00-other/set-input-error.function.js"></script>
<script src="/app/js/00-other/string.class.js"></script>
<script src="/app/js/00-other/track-event.function.js"></script>
<script src="/app/js/00-other/uri-plugin.js"></script>
<script src="/app/js/00-other/validate.functions.js"></script>
<script src="/app/js/10-model/10-model-draw-3d.prototype.js"></script>
<script src="/app/js/10-model/10-model-draw-cache.prototype.js"></script>
<script src="/app/js/20-ui/10-browser-compatibility.static.js"></script>
<script src="/app/js/20-ui/10-messages.static.js"></script>
<script src="/app/js/20-ui/10-popup-window.static.js"></script>
<script src="/app/js/20-ui/10-status.static.js"></script>
<script src="/app/js/20-ui/10-templates.static.js"></script>
<script src="/app/js/20-uri/10-uri.static.js"></script>
<script src="/app/js/20-uri/20-uri.onload.js"></script>
<script src="/app/js/30-api/10-townsapi.class.js"></script>
GULP
build
<script src="/app-build/js/towns.min.js"></script>
//--------------------------------------------------------------------------------------------------
gulp.task('build', function () {
gulp.src(includes)
.pipe(sort())
.pipe(concat('towns-shared.js'))
.pipe(es6transpiler({
"disallowUnknownReferences": false,
"disallowDuplicated": false
}))
.pipe(gulp.dest('./build'))
.pipe(uglify())
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('./build'));
});
PHP
browser includes
<?php
$scripts = glob('./js/*.js');
foreach($scripts as $script){
echo('<script src="'.htmlentities($script).'"></script>'."n");
}
?>
Middleware
komunikace WWW a API serveru
http://www.itnetwork.cz/software/sublime-
text
Sublime Text 3 napsal Jon Skinner. Jde o komerční editor napsaný v C++ a jehož
licence stojí kolem 1400 Kč. Editor si ale můžete vyzkoušet a to na neomezenou
dobu. Bez licence se však čas od času při ukládání ukáže dialogové okno, kde je
doporučena koupě licence….
Honza Bittner | ITNetwork.cz
WWW App
API
server DB
WWW
server
WWW App
API
server DB
WWW
server
http://www.towns.
cz/story/572cbec9b8
3bf0b7710c6b58#23,
56
<title>Lesní mýtina | Towns</title>
<meta name="description" content="">
<link rel="icon" href="/favicon.ico">
<meta property="fb:app_id" content="408791555870621" >
<meta property="og:site_name" content="Lesní mýtina | Towns" >
<meta property="og:title" content="Lesní mýtina | Towns" >
<meta property="og:description" content="Na lesní mýtině…." >
<meta property="og:type" content="article" >
<meta property="og:url" content="http://towns.
cz/story/572cbec9b83bf0b7710c6b58" >
<meta property="og:image" content="http://cdn.towns.cz/towns-cdn/?
file=572cbec84cc89-bGVzMi5qcGc=&&width=1200" >
………………………………………………………………………………...
<main class="popup-window">
<div class="header">Lesní mýtina</div>
<article class="content">
<p><img src="http://cdn.towns.cz/towns-cdn/?file=572cbec84cc89-
bGVzMi5qcGc=&amp;&amp;width=800" alt="les2.jpg"></p>
</article>
</main>
Další témata
● TypeScript
● Angular
● Google Maps vs. Seznam Mapy
● WS
● REST API
● Mongo DB
● JS Files API - drag & drop
● 2D grafika - canvas / svg
● 3D grafika webgl
● Procedurální mapy
● Gulp
● Sass

More Related Content

What's hot

An Impromptu Introduction to HTML5 Canvas
An Impromptu Introduction to HTML5 CanvasAn Impromptu Introduction to HTML5 Canvas
An Impromptu Introduction to HTML5 CanvasBen Hodgson
 
Mobile Web Development
Mobile Web DevelopmentMobile Web Development
Mobile Web DevelopmentJonathan Snook
 
Canvas
CanvasCanvas
CanvasRajon
 
Css sprite_maker-1
Css  sprite_maker-1Css  sprite_maker-1
Css sprite_maker-1lokku
 
CARATULA ASPT: PROAÑO
CARATULA ASPT: PROAÑOCARATULA ASPT: PROAÑO
CARATULA ASPT: PROAÑOzantytaz
 
كود شات عربي جميل
كود شات عربي جميلكود شات عربي جميل
كود شات عربي جميلguestf49e5c
 
Bootstrap Study Share
Bootstrap Study ShareBootstrap Study Share
Bootstrap Study ShareVincent Chang
 
Web Performance Workshop - Velocity London 2013
Web Performance Workshop - Velocity London 2013Web Performance Workshop - Velocity London 2013
Web Performance Workshop - Velocity London 2013Andy Davies
 
PreDevCampSF - CSS3 Tricks
PreDevCampSF - CSS3 TricksPreDevCampSF - CSS3 Tricks
PreDevCampSF - CSS3 Tricksincidentist
 
Introduction à AngularJS
Introduction à AngularJSIntroduction à AngularJS
Introduction à AngularJSNicolas PENNEC
 
ServiceWorker: New game changer is coming!
ServiceWorker: New game changer is coming!ServiceWorker: New game changer is coming!
ServiceWorker: New game changer is coming!Chang W. Doh
 
A brief look at CSS3 techniques by Aaron Rodgers, Web Designer @ vzaar.com
A brief look at CSS3 techniques by Aaron Rodgers, Web Designer @ vzaar.comA brief look at CSS3 techniques by Aaron Rodgers, Web Designer @ vzaar.com
A brief look at CSS3 techniques by Aaron Rodgers, Web Designer @ vzaar.comapplicake
 
Overview: How to Measure your WebApp
Overview: How to Measure your WebAppOverview: How to Measure your WebApp
Overview: How to Measure your WebAppChang W. Doh
 
Minimalism in Web Development
Minimalism in Web DevelopmentMinimalism in Web Development
Minimalism in Web DevelopmentJamie Matthews
 
Web Development for Mobile: GTUG Talk at Google
Web Development for Mobile: GTUG Talk at GoogleWeb Development for Mobile: GTUG Talk at Google
Web Development for Mobile: GTUG Talk at GoogleEstelle Weyl
 

What's hot (20)

An Impromptu Introduction to HTML5 Canvas
An Impromptu Introduction to HTML5 CanvasAn Impromptu Introduction to HTML5 Canvas
An Impromptu Introduction to HTML5 Canvas
 
RIAs
RIAsRIAs
RIAs
 
Mobile Web Development
Mobile Web DevelopmentMobile Web Development
Mobile Web Development
 
Canvas
CanvasCanvas
Canvas
 
Css sprite_maker-1
Css  sprite_maker-1Css  sprite_maker-1
Css sprite_maker-1
 
CARATULA ASPT: PROAÑO
CARATULA ASPT: PROAÑOCARATULA ASPT: PROAÑO
CARATULA ASPT: PROAÑO
 
Functional javascript
Functional javascriptFunctional javascript
Functional javascript
 
كود شات عربي جميل
كود شات عربي جميلكود شات عربي جميل
كود شات عربي جميل
 
Bootstrap Study Share
Bootstrap Study ShareBootstrap Study Share
Bootstrap Study Share
 
Web Performance Workshop - Velocity London 2013
Web Performance Workshop - Velocity London 2013Web Performance Workshop - Velocity London 2013
Web Performance Workshop - Velocity London 2013
 
PreDevCampSF - CSS3 Tricks
PreDevCampSF - CSS3 TricksPreDevCampSF - CSS3 Tricks
PreDevCampSF - CSS3 Tricks
 
Introduction à AngularJS
Introduction à AngularJSIntroduction à AngularJS
Introduction à AngularJS
 
ServiceWorker: New game changer is coming!
ServiceWorker: New game changer is coming!ServiceWorker: New game changer is coming!
ServiceWorker: New game changer is coming!
 
Javascript fullstasck
Javascript fullstasckJavascript fullstasck
Javascript fullstasck
 
A brief look at CSS3 techniques by Aaron Rodgers, Web Designer @ vzaar.com
A brief look at CSS3 techniques by Aaron Rodgers, Web Designer @ vzaar.comA brief look at CSS3 techniques by Aaron Rodgers, Web Designer @ vzaar.com
A brief look at CSS3 techniques by Aaron Rodgers, Web Designer @ vzaar.com
 
Overview: How to Measure your WebApp
Overview: How to Measure your WebAppOverview: How to Measure your WebApp
Overview: How to Measure your WebApp
 
OPTIMERA STHLM! Isac Lagerblad
OPTIMERA STHLM! Isac LagerbladOPTIMERA STHLM! Isac Lagerblad
OPTIMERA STHLM! Isac Lagerblad
 
Minimalism in Web Development
Minimalism in Web DevelopmentMinimalism in Web Development
Minimalism in Web Development
 
Web Development for Mobile: GTUG Talk at Google
Web Development for Mobile: GTUG Talk at GoogleWeb Development for Mobile: GTUG Talk at Google
Web Development for Mobile: GTUG Talk at Google
 
Javascipt ch1
Javascipt ch1Javascipt ch1
Javascipt ch1
 

Similar to JavaScript Web Apps and APIs

Analyzing the Performance of Mobile Web
Analyzing the Performance of Mobile WebAnalyzing the Performance of Mobile Web
Analyzing the Performance of Mobile WebAriya Hidayat
 
End-to-end HTML5 APIs - The Geek Gathering 2013
End-to-end HTML5 APIs - The Geek Gathering 2013End-to-end HTML5 APIs - The Geek Gathering 2013
End-to-end HTML5 APIs - The Geek Gathering 2013Alexandre Morgaut
 
Pushing the Boundaries of Sencha and HTML5′s WebRTC
Pushing the Boundaries of Sencha and HTML5′s WebRTCPushing the Boundaries of Sencha and HTML5′s WebRTC
Pushing the Boundaries of Sencha and HTML5′s WebRTCRich Waters
 
Webkit overview
Webkit overviewWebkit overview
Webkit overviewEun Cho
 
Cape Cod Web Technology Meetup - 2
Cape Cod Web Technology Meetup - 2Cape Cod Web Technology Meetup - 2
Cape Cod Web Technology Meetup - 2Asher Martin
 
HTML5とIE10とWindows 8
HTML5とIE10とWindows 8HTML5とIE10とWindows 8
HTML5とIE10とWindows 8Microsoft
 
[convergese] Adaptive Images in Responsive Web Design
[convergese] Adaptive Images in Responsive Web Design[convergese] Adaptive Images in Responsive Web Design
[convergese] Adaptive Images in Responsive Web DesignChristopher Schmitt
 
Building Real-Time Applications with Android and WebSockets
Building Real-Time Applications with Android and WebSocketsBuilding Real-Time Applications with Android and WebSockets
Building Real-Time Applications with Android and WebSocketsSergi Almar i Graupera
 
It is not HTML5. but ... / HTML5ではないサイトからHTML5を考える
It is not HTML5. but ... / HTML5ではないサイトからHTML5を考えるIt is not HTML5. but ... / HTML5ではないサイトからHTML5を考える
It is not HTML5. but ... / HTML5ではないサイトからHTML5を考えるSadaaki HIRAI
 
Whatever it takes - Fixing SQLIA and XSS in the process
Whatever it takes - Fixing SQLIA and XSS in the processWhatever it takes - Fixing SQLIA and XSS in the process
Whatever it takes - Fixing SQLIA and XSS in the processguest3379bd
 
HTTP For the Good or the Bad
HTTP For the Good or the BadHTTP For the Good or the Bad
HTTP For the Good or the BadXavier Mertens
 
Minor Mistakes In Web Portals
Minor Mistakes In Web PortalsMinor Mistakes In Web Portals
Minor Mistakes In Web Portalsmsobiegraj
 
Web開発の技術選び、 好き嫌いでやってませんか 〜技術選びで注目すべきポイントとは〜
Web開発の技術選び、 好き嫌いでやってませんか  〜技術選びで注目すべきポイントとは〜Web開発の技術選び、 好き嫌いでやってませんか  〜技術選びで注目すべきポイントとは〜
Web開発の技術選び、 好き嫌いでやってませんか 〜技術選びで注目すべきポイントとは〜Yuki Okada
 

Similar to JavaScript Web Apps and APIs (20)

(C)NodeJS
(C)NodeJS(C)NodeJS
(C)NodeJS
 
Analyzing the Performance of Mobile Web
Analyzing the Performance of Mobile WebAnalyzing the Performance of Mobile Web
Analyzing the Performance of Mobile Web
 
End-to-end HTML5 APIs - The Geek Gathering 2013
End-to-end HTML5 APIs - The Geek Gathering 2013End-to-end HTML5 APIs - The Geek Gathering 2013
End-to-end HTML5 APIs - The Geek Gathering 2013
 
Pushing the Boundaries of Sencha and HTML5′s WebRTC
Pushing the Boundaries of Sencha and HTML5′s WebRTCPushing the Boundaries of Sencha and HTML5′s WebRTC
Pushing the Boundaries of Sencha and HTML5′s WebRTC
 
Webkit overview
Webkit overviewWebkit overview
Webkit overview
 
Cape Cod Web Technology Meetup - 2
Cape Cod Web Technology Meetup - 2Cape Cod Web Technology Meetup - 2
Cape Cod Web Technology Meetup - 2
 
URL Design
URL DesignURL Design
URL Design
 
HTML5とIE10とWindows 8
HTML5とIE10とWindows 8HTML5とIE10とWindows 8
HTML5とIE10とWindows 8
 
[convergese] Adaptive Images in Responsive Web Design
[convergese] Adaptive Images in Responsive Web Design[convergese] Adaptive Images in Responsive Web Design
[convergese] Adaptive Images in Responsive Web Design
 
OneRing @ OSCamp 2010
OneRing @ OSCamp 2010OneRing @ OSCamp 2010
OneRing @ OSCamp 2010
 
Sanjeev ghai 12
Sanjeev ghai 12Sanjeev ghai 12
Sanjeev ghai 12
 
Building Real-Time Applications with Android and WebSockets
Building Real-Time Applications with Android and WebSocketsBuilding Real-Time Applications with Android and WebSockets
Building Real-Time Applications with Android and WebSockets
 
It is not HTML5. but ... / HTML5ではないサイトからHTML5を考える
It is not HTML5. but ... / HTML5ではないサイトからHTML5を考えるIt is not HTML5. but ... / HTML5ではないサイトからHTML5を考える
It is not HTML5. but ... / HTML5ではないサイトからHTML5を考える
 
前端概述
前端概述前端概述
前端概述
 
Whatever it takes - Fixing SQLIA and XSS in the process
Whatever it takes - Fixing SQLIA and XSS in the processWhatever it takes - Fixing SQLIA and XSS in the process
Whatever it takes - Fixing SQLIA and XSS in the process
 
HTTP For the Good or the Bad
HTTP For the Good or the BadHTTP For the Good or the Bad
HTTP For the Good or the Bad
 
php
phpphp
php
 
Minor Mistakes In Web Portals
Minor Mistakes In Web PortalsMinor Mistakes In Web Portals
Minor Mistakes In Web Portals
 
Isomorphic Javascript - nodebr
Isomorphic Javascript - nodebrIsomorphic Javascript - nodebr
Isomorphic Javascript - nodebr
 
Web開発の技術選び、 好き嫌いでやってませんか 〜技術選びで注目すべきポイントとは〜
Web開発の技術選び、 好き嫌いでやってませんか  〜技術選びで注目すべきポイントとは〜Web開発の技術選び、 好き嫌いでやってませんか  〜技術選びで注目すべきポイントとは〜
Web開発の技術選び、 好き嫌いでやってませんか 〜技術選びで注目すべきポイントとは〜
 

Recently uploaded

The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Hyundai Motor Group
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetEnjoy Anytime
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 

Recently uploaded (20)

The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 

JavaScript Web Apps and APIs

  • 1. Pavol Hejný pavolhejny.com Webové aplikace v JavaScriptu 27.5.2016 | Praha | ITnetwork.cz
  • 2. Stránka vs. Aplikace WWW App API server DBDB View Controller WWW server Model HTML page
  • 4. Proč? Rychlost využití 2D / 3D grafiky Využití web audio Využití files API
  • 5.
  • 15.
  • 17. <body> <p id="itnetwork">ITnetwork</p> </body> <script> var element = window.document.getElementById ("itnetwork"); element.onclick = function(){ element.style.color = '#3B94E0'; } </script> DOM ITnetwork
  • 18. DOM vs. jQuery $('#itnetwork').click(function(){ $(this).css('color','#00ff00'); }); var element = window.document.getElementById ("itnetwork"); element.onclick = function(){ element.style.color = '#00ff00'; }
  • 19. 7 var second=11; var element =window.document.getElementById ("counter"); var interval = setInterval(function(){ second--; element.innerHTML = second; }, 1000); setTimeout(function(){ alert('Ahoj!'); clearInterval(interval); } , 11000); interval, timeout https://jsfiddle.net/phejny/xjyerkq2/
  • 20. var start = null; var element = document.getElementById("ball"); element.style.position = 'absolute'; function step(timestamp) { if (!start) start = timestamp; var progress = timestamp - start; element.style.top = Math.sin(progress/1000*Math.PI) *100+100 + "px"; element.style.left = Math.cos(progress/1000*Math.PI) *100+100 + "px"; window.requestAnimationFrame(step); } window.requestAnimationFrame(step); Animation frame https://jsfiddle.net/phejny/8nLcpffb/1/
  • 21. 5€ je 135,- kč. var request = new XMLHttpRequest(); var url = "https://api.fixer.io/latest?symbols=CZK"; request.onreadystatechange = function() { if (request.readyState == 4 && request.status == 200) { var response = JSON.parse(request.responseText); var rate = response.rates.CZK; document.getElementById('CZK').innerText = Math. round(rate*5); } }; request.open("GET", url, true); request.send(); XMLHttpRequest https://jsfiddle.net/phejny/0y6dbyug/1
  • 22. XMLHttpRequest vs. jQuery var url = "https://api.fixer.io/latest?symbols=CZK"; $.get(url) .done(function(response){ var rate = response.rates.CZK; $('#CZK').text(Math.round(rate*5)); }); var request = new XMLHttpRequest(); var url = "https://api.fixer.io/latest?symbols=CZK"; request.onreadystatechange = function() { if (request.readyState == 4 && request.status == 200) { var response = JSON.parse(request.responseText); var rate = response.rates.CZK; document.getElementById('CZK').innerText = Math.round (rate*5); } }; request.open("GET", url, true); request.send(); https://jsfiddle.net/phejny/0y6dbyug/3
  • 23. Sync vs. Async $.get("https://api.fixer.io/latest?symbols=CZK") .done(function(response){ var rate = response.rates.CZK; $('#CZK').text(Math.round(rate*5)); }); $.get("https://api.fixer.io/latest?symbols=USD") .done(function(response){ var rate = response.rates.USD; $('#USD').text(Math.round(rate*5*100)/100); }); <?php $json = file_get_contents("https://api.fixer.io/latest? symbols=CZK,EUR"); //... echo('5€ je '.$CZK.',- kč.'); $json = file_get_contents("https://api.fixer.io/latest? symbols=USD,EUR"); //... echo('5€ je '.$USD.'$.'); ?>
  • 25. Angular <!doctype html> <html ng-app> <head> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5 /angular.min.js"></script> </head> <body> <div> <input type="text" ng-model="jmeno_cajovny"> <hr> <h1>Jsme v čajovně {{jmeno_cajovny}}!</h1> </div> </body> </html>
  • 26. ECMAScript 5 var Position = function(x,y){ this.x= x || 0; this.y= y || 0; }; Position.prototype.getDistance = function(position){ return Math.sqrt(Math.pow(position.x-this.x,2)+Math.pow(position.y- this.y,2)); }; Position.prototype.toString = function(){ return ''+this.x+','+this.y+''; };
  • 27. var multiline_string = (function () {/* Podle mě ten nejhorší způsob :( */}).toString().match(/[^]*/*([^]*)*/}$/)[1]; var multiline_string = `V ES6 to jde bez problémů!`; var multiline_string = 'Takhle d*****e se musí psát string na více řádků.'; var multiline_string = 'Nebo' + 'takhle - s tímhle zápisem alespoň umí' + 'pracovat PHPStorm'; var multiline_string = ['Nebo', 'takhle', ].join('n') String
  • 28. ECMAScript 6 var Position = class{ constructor(x=0,y=0){ this.x= x; this.y= y; } getDistance(position){ return Math.sqrt(Math.pow(position.x-this.x,2)+Math.pow(position. y-this.y,2)); } toString(){ return ''+this.x+','+this.y+''; } };
  • 29. CoffeeScript transpiler Position = (x, y) -> @x = x or 0 @y = y or 0 return Position::getDistance = (position) -> Math.sqrt (position.x - (@x)) ** 2+ (position.y - (@y)) ** 2 Position::toString = -> '' + @x + ',' + @y + ''
  • 32. PHP vs. Node ● Apache ● Jednotlivé stránky ● node, pm2 ● Celý server
  • 33. Response ● http://www.itnetwork. cz/software/sublime-text? nastaveni=123#goto173043 ● GET, POST, DELETE, HEAD,... Body ● status code - 200, 404, 403,... ● mime type - text/html ● cache control ● form data, upload,... ● html, js, css, image, pdf, video,... Request Header
  • 34. Response Headers alt-svc:quic=":443"; ma=2592000; v=" 34,33,32,31,30,29,28,27,26,25" alternate-protocol:443:quic cache-control:private, max-age=0 content-encoding:gzip content-type:text/html; charset=UTF-8 date:Fri, 27 May 2016 11:46:06 GMT expires:-1 server:gws status:200 x-frame-options:SAMEORIGIN x-xss-protection:1; mode=block Request Headers URL:https://www.google.cz/search? q=itnetwork+je+nej&oq=status+code&aqs=ch rome..69i57. 395j0j7&sourceid=chrome&es_sm=93&ie=UT F-8 Request Method:GET Remote Address:216.58.212.67:443 RAW
  • 35. Browser vs. Node ● window ● <script src="..."></script> ● HTTP klient ● JQuery, Angular ● global ● var module = require("..."); ● HTTP server, klient ● Express
  • 36. Express Routing var http = require("http"); http.createServer(function(request, response){ if(request.url=='/') { response.writeHead(200); response.end('GET request to the home'); }else if(request.url=='/objects') { response.writeHead(200); response.end('GET request to the objects'); }else{ response.writeHead(404); response.end('Not fount :( '); } }).listen(80); var express = require('express'); var app = express(); app.get('/', function (req, res) { res.send('GET request to the home'); }); app.get('/objects', function (req, res) { res.send('GET request to the objects'); });
  • 37. Jasmine testování describe('lineCollision', function() { it('//', function () { expect(T.Math.lineCollision(0,0,10,10,0,2,10,12)).toBe(false); }); it('/|', function () { expect(T.Math.lineCollision(0,0,10,10,100,0,100,10)).toBe(false); }); it('X', function () { expect(T.Math.lineCollision(0,0,10,10,0,2,2,0)).toBe(true); }); it('L', function () { expect(T.Math.lineCollision(0,0,10,10,10,10,10,0)).toBe(true); }); it('T', function () { expect(T.Math.lineCollision(0,0,10,0,10,10,10,-10)).toBe(true); }); it('/', function () { expect(T.Math.lineCollision(0,0,10,10,1,1,9,9)).toBe(true); }); it('!', function () { expect(T.Math.lineCollision(0,0,0,2,0,4,0,10)).toBe(false); }); });
  • 39. HTML browser includes <script src="/app/js/00-other/cookie.static.js"></script> <script src="/app/js/00-other/copy.static.js"></script> <script src="/app/js/00-other/date.functions.js"></script> <script src="/app/js/00-other/escape.functions.js"></script> <script src="/app/js/00-other/generate-file.jquery.js"></script> <script src="/app/js/00-other/interval.static.js"></script> <script src="/app/js/00-other/is-image-ok.function.js"></script> <script src="/app/js/00-other/is.functions.js"></script> <script src="/app/js/00-other/log.functions.js"></script> <script src="/app/js/00-other/outer-html.jquery.js"></script> <script src="/app/js/00-other/select-text.function.js"></script> <script src="/app/js/00-other/set-input-error.function.js"></script> <script src="/app/js/00-other/string.class.js"></script> <script src="/app/js/00-other/track-event.function.js"></script> <script src="/app/js/00-other/uri-plugin.js"></script> <script src="/app/js/00-other/validate.functions.js"></script> <script src="/app/js/10-model/10-model-draw-3d.prototype.js"></script> <script src="/app/js/10-model/10-model-draw-cache.prototype.js"></script> <script src="/app/js/20-ui/10-browser-compatibility.static.js"></script> <script src="/app/js/20-ui/10-messages.static.js"></script> <script src="/app/js/20-ui/10-popup-window.static.js"></script> <script src="/app/js/20-ui/10-status.static.js"></script> <script src="/app/js/20-ui/10-templates.static.js"></script> <script src="/app/js/20-uri/10-uri.static.js"></script> <script src="/app/js/20-uri/20-uri.onload.js"></script> <script src="/app/js/30-api/10-townsapi.class.js"></script>
  • 40. GULP build <script src="/app-build/js/towns.min.js"></script> //-------------------------------------------------------------------------------------------------- gulp.task('build', function () { gulp.src(includes) .pipe(sort()) .pipe(concat('towns-shared.js')) .pipe(es6transpiler({ "disallowUnknownReferences": false, "disallowDuplicated": false })) .pipe(gulp.dest('./build')) .pipe(uglify()) .pipe(rename({suffix: '.min'})) .pipe(gulp.dest('./build')); });
  • 41. PHP browser includes <?php $scripts = glob('./js/*.js'); foreach($scripts as $script){ echo('<script src="'.htmlentities($script).'"></script>'."n"); } ?>
  • 43. http://www.itnetwork.cz/software/sublime- text Sublime Text 3 napsal Jon Skinner. Jde o komerční editor napsaný v C++ a jehož licence stojí kolem 1400 Kč. Editor si ale můžete vyzkoušet a to na neomezenou dobu. Bez licence se však čas od času při ukládání ukáže dialogové okno, kde je doporučena koupě licence…. Honza Bittner | ITNetwork.cz
  • 44. WWW App API server DB WWW server WWW App API server DB WWW server
  • 45. http://www.towns. cz/story/572cbec9b8 3bf0b7710c6b58#23, 56 <title>Lesní mýtina | Towns</title> <meta name="description" content=""> <link rel="icon" href="/favicon.ico"> <meta property="fb:app_id" content="408791555870621" > <meta property="og:site_name" content="Lesní mýtina | Towns" > <meta property="og:title" content="Lesní mýtina | Towns" > <meta property="og:description" content="Na lesní mýtině…." > <meta property="og:type" content="article" > <meta property="og:url" content="http://towns. cz/story/572cbec9b83bf0b7710c6b58" > <meta property="og:image" content="http://cdn.towns.cz/towns-cdn/? file=572cbec84cc89-bGVzMi5qcGc=&&width=1200" > ………………………………………………………………………………... <main class="popup-window"> <div class="header">Lesní mýtina</div> <article class="content"> <p><img src="http://cdn.towns.cz/towns-cdn/?file=572cbec84cc89- bGVzMi5qcGc=&amp;&amp;width=800" alt="les2.jpg"></p> </article> </main>
  • 46. Další témata ● TypeScript ● Angular ● Google Maps vs. Seznam Mapy ● WS ● REST API ● Mongo DB ● JS Files API - drag & drop ● 2D grafika - canvas / svg ● 3D grafika webgl ● Procedurální mapy ● Gulp ● Sass