forked from html5rocks/slides.html5rocks.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
html5.html
3005 lines (2645 loc) · 121 KB
/
html5.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<!--
Copyright 2011 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Original slides: Marcin Wichary ([email protected])
Modifications: Chrome DevRel Team ([email protected])
Alex Russell ([email protected])
Brad Neuberg
-->
<html manifest="cache.appcache">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=Edge;chrome=1" />
<title>HTML5 Presentation</title>
<link href="http://fonts.googleapis.com/css?family=Droid+Sans|Droid+Sans+Mono" rel="stylesheet" type="text/css" />
<link id="prettify-link" href="src/prettify/prettify.css" rel="stylesheet" disabled />
<link href="styles/fonts.css" rel="stylesheet" type="text/css" media="screen" />
<link href="styles/presentation.css" rel="stylesheet" type="text/css" media="screen" />
<link href="styles/common.css" rel="stylesheet" type="text/css" media="screen" />
<link class="theme" href="styles/default.css" rel="stylesheet" type="text/css" media="screen" />
<link class="theme" href="styles/moon.css" rel="stylesheet" type="text/css" media="screen" />
<link class="theme" href="styles/sand.css" rel="stylesheet" type="text/css" media="screen"/>
<link class="theme" href="styles/sea_wave.css" rel="stylesheet" type="text/css" media="screen"/>
</head>
<body>
<div id="flex-container">
<nav id="helpers">
<button title="Previous slide" id="nav-prev" class="nav-prev">⇽</button>
<button title="Jump to a random slide" id="slide-no">5</button>
<button title="Next slide" id="nav-next" class="nav-next">⇾</button>
<menu>
<button type="checkbox" data-command="toc" title="Table of Contents" class="toc">TOC</button>
<!-- <button type="checkbox" data-command="resources" title="View Related Resources">☆</button> -->
<button type="checkbox" data-command="notes" title="View Slide Notes">✏</button>
<button type="checkbox" data-command="source" title="View slide source">↻</button>
<button type="checkbox" data-command="help" title="View Help">?</button>
</menu>
</nav>
<div class="slides">
<div id="presentation-counter">Loading...</div>
<div class="slide" id="landing-slide">
<section class="middle">
<p>This presentation is an HTML5 website</p>
<p>Press <span id="left-init-key" class="key">→</span> key to advance.</p>
<p id="disclaimer-message">Having issues seeing the presentation? Read the <a href="disclaimer.html">disclaimer</a></p>
</section>
<aside class="note">
<section>
Welcome! (This field is for speaker notes and commentary.)
</section>
</aside>
</div>
<div class="slide" id="controls-slide">
<header>Slides controls</header>
<section>
<ul>
<li><span class="key">←</span> and <span class="key">→</span> to move around.</li>
<li><span class="key">Ctrl/Command</span> and <span class="key">+</span> or <span class="key">-</span> to zoom in and out if slides don’t fit.</li>
<li><span class="key">S</span> to view page source.</li>
<li><span class="key">T</span> to change the theme.</li>
<li><span class="key">H</span> to toggle syntax highlight.</li>
<li><span class="key">N</span> to toggle speaker notes.</li>
<li><span class="key">3</span> to toggle 3D effect.</li>
<li><span class="key">0</span> to toggle help.</li>
</ul>
</section>
</div>
<div class="slide" id="title-slide">
<section class="middle">
<hgroup>
<h1>
HTML5*
</h1>
<h2>
Web Development to the next level
</h2>
</hgroup>
<p>*Including other next generation technologies of the Web Development stack</p>
</section>
</div>
<div class="slide" id="timeline-slide">
<header>Rough Timeline of Web Technologies</header>
<section>
<ul id="timeline">
<li data-auto><span class="year">1991</span> <span class="html">HTML</span></li>
<li data-auto><span class="year">1994</span> <span class="html">HTML 2</span></li>
<li data-auto><span class="year">1996</span> <span class="css">CSS 1</span> + <span class="js">JavaScript</span></li>
<li data-auto><span class="year">1997</span> <span class="html">HTML 4</span></li>
<li data-auto><span class="year">1998</span> <span class="css">CSS 2</span></li>
<li data-auto><span class="year">2000</span> <span class="html">XHTML 1</span></li>
<li><span class="year"><em class="stroke">2002</em></span> <span class="css">Tableless Web Design</span></li>
<li><span class="year"><em class="stroke">2005</em></span> <span class="js">AJAX</span></li>
<li><span class="year"><em class="stroke">2009</em></span> <span class="html">HTML 5</span></li>
</ul>
</section>
</div>
<div class="slide" id="formula-intro-slide">
<section class="middle formula" data-build>
HTML5 ~=
<span class="html">HTML</span>
+
<span class="css">CSS</span>
+
<span class="js">JS</span>
</section>
</div>
<div class="slide" id="table-of-contents">
<header><h1>Today, we will cover...</h1></header>
<section>
<ul id="toc-list">
</ul>
</section>
</div>
<div class="slide transitionSlide" id="offline-storage-title">
<section class="middle">
<h2>Offline / Storage</h2>
<p>Expect the unexpected</p>
<img src="http://www.html5rocks.com/static/images/identity/classes_64/HTML5_Offline_Storage_64.png" title="HTML5 Offline & Storage" alt="HTML5 Offline & Storage">
</section>
</div>
<div class="slide offline-storage" id="web-storage">
<header><span class="js">JS</span> <h1>Web Storage</h1></header>
<section>
<pre>
// use localStorage for persistent storage
// use sessionStorage for per tab storage
saveButton.addEventListener('click', function () {
window.<b>localStorage</b>.<b>setItem</b>('value', area.value);
window.<b>localStorage</b>.<b>setItem</b>('timestamp', (new Date()).getTime());
}, false);
textarea.value = window.<b>localStorage</b>.<b>getItem</b>('value');
</pre>
<p id="localstorage-message">Save text value on the client side (crash-safe)</p>
<textarea id="ta" placeholder="Type your text here..."></textarea>
<button id="save-ta">Save</button>
<p id="ta-log"></p>
<script defer>
(function(){
try {
(window.localStorage.getItem) // will throw in Firefox under some settings
} catch(e){
return; // quit because dom.storage.enabled is false
}
var area = document.querySelector('#ta');
// place content from previous edit
if (!area.value) {
area.value = window.localStorage.getItem('value');
}
updateLog(false);
// your content will be saved locally
document.querySelector('#save-ta').addEventListener('click', function () {
window.localStorage.setItem('value', area.value);
window.localStorage.setItem('timestamp', (new Date()).getTime());
updateLog(true);
}, false);
function updateLog(new_save) {
var log = document.querySelector("#ta-log");
var delta = 0;
if (window.localStorage.getItem('value')) {
delta = ((new Date()).getTime() - (new Date()).setTime(window.localStorage.getItem('timestamp'))) / 1000;
if (new_save) {
log.textContent = 'Saved. Content will be available after browser refresh/reopen.';
setTimeout(function() {
log.textContent = '';
}, 3000);
} else {
log.textContent = 'last saved: ' + delta + 's ago';
}
}
}
})();
</script>
</section>
</div>
<div class="slide offline-storage" id="web-sql-db">
<header><span class="js">JS</span> <h1>Web SQL Database</h1></header>
<section>
<pre>var db = window.<b>openDatabase</b>("DBName", "1.0", "description", 5*1024*1024); //5MB
db.<b>transaction</b>(function(tx) {
tx.<b>executeSql</b>(<em>"SELECT * FROM test"</em>, [], successCallback, errorCallback);
});
</pre>
<div class="center" id="websqldb-example">
<input type="text" id="todoitem" />
<button onclick="webSqlSample.newRecord()">new to do item</button>
<button onclick="webSqlSample.createTable()">create table</button>
<button onclick="webSqlSample.dropTable()">drop table</button>
<p>See the generated database: Developer > Developer Tools > Storage</p>
<ul class="record-list" id="db-results"></ul>
<div id="db-log"></div>
</div>
<script defer>
var webSqlSample = (function() {
var db;
var log = document.getElementById('db-log');
if (window.openDatabase) {
db = openDatabase("DBTest", "1.0", "HTML5 Database API example", 200000);
showRecords();
}
document.getElementById('db-results').addEventListener('click', function(e) { e.preventDefault(); }, false);
function onError(tx, error) {
log.innerHTML = '<p class="error">Error: ' + error.message + '</p>';
}
// select all records and display them
function showRecords() {
document.getElementById('db-results').innerHTML = '';
db.transaction(function(tx) {
tx.executeSql("SELECT * FROM Table1Test", [], function(tx, result) {
for (var i = 0, item = null; i < result.rows.length; i++) {
item = result.rows.item(i);
document.getElementById('db-results').innerHTML +=
'<li><span contenteditable="true" onkeyup="webSqlSample.updateRecord('+item['id']+', this)">'+
item['text'] + '</span> <a href="#" onclick="webSqlSample.deleteRecord('+item['id']+')">[Delete]</a></li>';
}
});
});
}
function createTable() {
db.transaction(function(tx) {
tx.executeSql("CREATE TABLE Table1Test (id REAL UNIQUE, text TEXT)", [],
function(tx) { log.innerHTML = '<p>"Table1Test" created!</p>' },
onError);
});
}
// add record with random values
function newRecord() {
var num = Math.round(Math.random() * 10000); // random data
db.transaction(function(tx) {
tx.executeSql("INSERT INTO Table1Test (id, text) VALUES (?, ?)", [num, document.querySelector('#todoitem').value],
function(tx, result) {
log.innerHTML = '';
showRecords();
},
onError);
});
}
function updateRecord(id, textEl) {
db.transaction(function(tx) {
tx.executeSql("UPDATE Table1Test SET text = ? WHERE id = ?", [textEl.innerHTML, id], null, onError);
});
}
function deleteRecord(id) {
db.transaction(function(tx) {
tx.executeSql("DELETE FROM Table1Test WHERE id=?", [id],
function(tx, result) { showRecords() },
onError);
});
}
// delete table from db
function dropTable() {
db.transaction(function(tx) {
tx.executeSql("DROP TABLE Table1Test", [],
function(tx) { showRecords() },
onError);
});
}
return {
newRecord: newRecord,
createTable: createTable,
updateRecord: updateRecord,
deleteRecord: deleteRecord,
dropTable: dropTable
}
})();
</script>
</section>
</div>
<div class="slide offline-storage" id="indexed-db">
<header><span class="js">JS</span> <h1>IndexedDB</h1></header>
<section>
<pre>var idbRequest = window.<b>indexedDB</b>.<b>open</b>('Database Name');
idbRequest.onsuccess = function(event) {
<b>var db = event.srcElement.result</b>;
var transaction = db.<b>transaction</b>([], <b>IDBTransaction.READ_ONLY</b>);
var curRequest = transaction.<b>objectStore</b>('ObjectStore Name').<b>openCursor</b>();
curRequest.<b>onsuccess</b> = ...;
};
</pre>
<div class="center" id="indexeddb-example">
<input type="text" placeholder="key" id="idb-key" size="10" /> <input type="text" placeholder="value" id="idb-value" size="15" />
<button onclick="indexedDbSample.idbSet()">set</button>
<button onclick="indexedDbSample.idbCreate()">create objectStore</button>
<button onclick="indexedDbSample.idbRemove()">remove objectStore</button>
<div id="idb-log"></div>
<div class="record-list" id="idb-results-wrapper"></div>
</div>
<script defer>
var indexedDbSample = (function() {
var idb_;
var idbRequest_;
var idbLog_ = document.getElementById('idb-log');
var idResultsWrapper_ = document.getElementById('idb-results-wrapper');
// IndexedDB spec is still evolving, various browsers keep it
// behind various flags and implementation varies.
if ('webkitIndexedDB' in window) {
window.indexedDB = window.webkitIndexedDB;
window.IDBTransaction = window.webkitIDBTransaction;
} else if ('moz_indexedDB' in window) {
window.indexedDB = window.moz_indexedDB;
}
// Open our IndexedDB if the browser supports it.
if (window.indexedDB) {
idbRequest_ = window.indexedDB.open("Test", "A test object store.");
idbRequest_.onerror = idbError_;
idbRequest_.addEventListener('success', function(event) {
idb_ = event.srcElement.result;
idbShow_(event);
}, false);
}
function idbError_(event) {
idbLog_.innerHTML += '<p class="error">Error: ' +
event.message + ' (' + event.code + ')</p>';
}
function idbShow_(event) {
if (!idb_.objectStoreNames.contains('myObjectStore')) {
idbLog_.innerHTML = "<p>Object store not yet created.</p>";
return;
}
var html = [];
var transaction = idb_.transaction([], IDBTransaction.READ_ONLY); // Read is default.
var request = transaction.objectStore('myObjectStore').openCursor(); // Get all results.
// This callback will continue to be called until we have no more results.
request.onsuccess = function(e) {
var cursor = e.srcElement.result;
if (!cursor) {
idResultsWrapper_.innerHTML = '<ul class="record-list" id="idb-results">' + html.join('') + '</ul>';
return;
}
html.push('<li><span class="keyval" contenteditable onblur="indexedDbSample.updateKey(\'',
cursor.key, '\', this)">', cursor.key, '</span> ',
'=> <span class="keyval" contenteditable onblur="indexedDbSample.updateValue(\'',
cursor.key, '\', this)">', cursor.value, '</span> ',
'<a href="javascript:void(0)" onclick="indexedDbSample.deleteKey(\'',
cursor.key, '\')">[Delete]</a></li>');
cursor['continue']();
}
request.onerror = idbError_;
}
function idbCreate_() {
if (!idb_) {
if (idbRequest_) {
idbRequest_.addEventListener('success', removeObjectStore, false); // If indexedDB is still opening, just queue this up.
}
return;
}
var request = idb_.setVersion('the new version string');
request.onerror = idbError_;
request.onsuccess = function(e) {
if (!idb_.objectStoreNames.contains('myObjectStore')) {
try {
var objectStore = idb_.createObjectStore('myObjectStore', null); // FF is requiring the 2nd keyPath arg. It can be optional :(
idbLog_.innerHTML = "<p>Object store created.</p>";
} catch (err) {
idbLog_.innerHTML = '<p class="error">' + err.toString() + '</p>';
}
} else {
idbLog_.innerHTML = '<p class="error">Object store already exists.</p>';
}
}
}
function idbSet_() {
if (!idb_) {
if (idbRequest_) {
idbRequest_.addEventListener('success', removeObjectStore, false); // If indexedDB is still opening, just queue this up.
}
return;
}
if (!idb_.objectStoreNames.contains('myObjectStore')) {
idbLog_.innerHTML = "<p class=\"error\">Object store doesn't exist.</p>";
return;
}
// Create a transaction that locks the world.
var objectStore = idb_.transaction([], IDBTransaction.READ_WRITE)
.objectStore("myObjectStore");
var request = objectStore.put(
document.getElementById('idb-value').value,
document.getElementById('idb-key').value);
request.onerror = idbError_;
request.onsuccess = idbShow_;
}
function updateKey_(key, element) {
var newKey = element.textContent;
var transaction = idb_.transaction([], IDBTransaction.READ_WRITE); // Create a transaction that locks the world.
var objectStore = transaction.objectStore("myObjectStore");
var request = objectStore.get(key);
request.onerror = idbError_;
request.onsuccess = function(event) {
var value = event.srcElement.result;
var request;
if (objectStore['delete']) {
request = objectStore['delete'](key);
} else {
request = objectStore.remove(key);
}
request.onerror = idbError_;
request.onsuccess = function(event) {
var request = objectStore.add(value, newKey);
request.onerror = idbError_;
request.onsuccess = idbShow_;
};
};
}
function updateValue_(key, element) {
var transaction = idb_.transaction([], IDBTransaction.READ_WRITE); // Create a transaction that locks the world.
var objectStore = transaction.objectStore("myObjectStore");
var request = objectStore.put(element.textContent, key);
request.onerror = idbError_;
request.onsuccess = idbShow_;
}
function deleteKey_(key) {
var transaction = idb_.transaction([], IDBTransaction.READ_WRITE); // Create a transaction that locks the world.
var objectStore = transaction.objectStore("myObjectStore");
var request;
if (objectStore['delete']) {
request = objectStore['delete'](key);
} else {
request = objectStore.remove(key);
}
request.onerror = idbError_;
request.onsuccess = idbShow_;
}
function idbRemove_() {
if (!idb_) {
if (idbRequest_) {
idbRequest_.addEventListener('success', removeObjectStore, false); // If indexedDB is still opening, just queue this up.
}
return;
}
var request = idb_.setVersion("the new version string");
request.onerror = idbError_;
request.onsuccess = function(event) {
if (idb_.objectStoreNames.contains('myObjectStore')) {
try {
// Spec has been updated to deleteObjectStore.
if (idb_.deleteObjectStore) {
idb_.deleteObjectStore('myObjectStore');
} else {
idb_.removeObjectStore('myObjectStore');
}
idResultsWrapper_.innerHTML = '';
idbLog_.innerHTML = "<p>Object store removed.</p>";
} catch (err) {
idbLog_.innerHTML = '<p class="error">' + err.toString() + '</p>';
}
} else {
idbLog_.innerHTML = "<p class=\"error\">Object store doesn't exist.</p>";
}
};
}
return {
idbSet: idbSet_,
idbCreate: idbCreate_,
idbRemove: idbRemove_,
updateKey: updateKey_,
updateValue: updateValue_,
deleteKey: deleteKey_
}
})();
</script>
</section>
</div>
<div class="slide offline-storage" id="app-cache">
<header><span class="js">JS</span> <h1>Application Cache</h1></header>
<section class="appcache-examples">
<pre><html <b>manifest="cache.appcache"</b>></pre>
<pre>
window.<b>applicationCache</b>.addEventListener('updateready', function(e) {
if (window.<b>applicationCache</b>.<b>status</b> == window.<b>applicationCache</b>.<b>UPDATEREADY</b>) {
window.<b>applicationCache</b>.<b>swapCache()</b>;
if (confirm('A new version of this site is available. Load it?')) {
window.location.reload();
}
}
}, false);
</pre>
cache.appcache:
<pre>CACHE MANIFEST
# version 1.0.0
CACHE:
/html5/src/logic.js
/html5/src/style.css
/html5/src/background.png
NETWORK:
*
</pre>
<p id="appcache-message">Turn off your internet connection and refresh this page!
<img src="src/refresh.png" onclick="window.location.reload();"/></p>
</section>
</div>
<div class="slide offline-storage" id="quota-api">
<header><span class="js">JS</span> <h1>Quota API</h1></header>
<style>
#quota-api table {
width: 100%;
border-collapse: collapse;
margin-top: 40px;
}
#quota-api th {
font-weight: 600;
text-align: left;
}
#quota-api td,
#quota-api th {
border: 1px solid #222;
padding: 5px 10px;
vertical-align: top;
}
.quota-info-bubble {
background-color: #FCFCE4;
border: 1px solid yellow;
font-size: 80%;
padding: 5px;
}
.quota-info-bubble input, .quota-info-bubble button {
font-size: 12px;
}
.quota-info-bubble span {
display: block;
}
</style>
<section>
<pre style="font-size: 80%">
// Request Status
<b>webkitStorageInfo</b>.<b>queryUsageAndQuota</b>(webkitStorageInfo.TEMPORARY, function(used, remaining) {
console.log("Used quota: " + used + ", remaining quota: " + remaining);
}
);
// Request Quota (only for File System API)
<b>webkitStorageInfo</b>.<b>requestQuota</b>(webkitStorageInfo.PERSISTENT, 10 * 1024 * 1024, function(used) {
console.log("Used quota: " + used + ", remaining quota: " + remaining);
}
);</pre>
<table border="0" cellspacing="5" cellpadding="5">
<tr><th></th><th>Default (Temporary)</th><th>Quota Requested (Persistent)</th></tr>
<tr><td>Web Storage</td><td>5Mb</td><td rowspan="4">N/A</td></tr>
<tr><td>App Cache</td><td rowspan="4">10% of available disk in total<div class="quota-info-bubble"><button id="temp-query">Show Usage</button><span>Used: <output>--</output> Bytes</span><span>Remaining: <output>--</output> Bytes</span></div></td></tr>
<tr><td>IndexedDB</td></tr>
<tr><td>WebSQL</td></tr>
<tr><td>File System API</td><td>Arbitrary<div class="quota-info-bubble"><input id="requested-quota" type="text" placeholder="Request quota amount..."/> in Bytes <button id="perm-request" style="margin-left: 5px">Request Quota</button><span>Used: <output>--</output> Bytes</span></div></td></tr>
</table>
</section>
<script>
(function() {
var outputs = document.querySelectorAll('#quota-api output');
document.querySelector('#temp-query').addEventListener(
'click', function() {
webkitStorageInfo.queryUsageAndQuota(
webkitStorageInfo.TEMPORARY,
function(used, remaining) {
outputs[0].textContent = used;
outputs[1].textContent = remaining;
}, function(error) { alert(error) });
}, false);
document.querySelector('#perm-request').addEventListener(
'click', function() {
webkitStorageInfo.requestQuota(
webkitStorageInfo.PERSISTENT,
document.querySelector('#requested-quota').value,
function(used) {
outputs[2].textContent = used;
}, function(error) { alert(error) });
}, false);
}())
</script>
</div>
<div class="slide transitionSlide" id="realtime-title">
<section class="middle">
<h2>Realtime / Communication</h2>
<p>Stay connected</p>
<img src="http://www.html5rocks.com/static/images/identity/classes_64/HTML5_Connectivity_64.png" title="HTML5 Realtime & Communication" alt="HTML5 Realtime & Communication">
</section>
</div>
<div class="slide realtime-communication" id="web-workers">
<header><span class="js">JS</span> <h1>Web Workers</h1></header>
<section>
main.js:
<pre>
var worker = new <b>Worker</b>('task.js');
worker.<b>onmessage</b> = function(event) { alert(event.data); };
worker.<b>postMessage</b>('data');
</pre>
task.js:
<pre>
self.<b>onmessage</b> = function(event) {
// Do some work.
self.<b>postMessage</b>("recv'd: " + event.data);
};
</pre>
<div id="w-wrapper">
<div id="wmap" class="gmap example">
<img src="http://maps.google.com/maps/api/staticmap?center=13,13&zoom=3&size=680x200&sensor=false"/>
</div>
<div style="margin-top:5px">
<button id="find-route-y">Find route with Workers</button>
<button id="find-route-n">Find route without Workers</button>
<p id="w-loading">Loading Route...</p>
</div>
<p style="font-size: 90%;" class="center">Try dragging the map while the complex route is being calculated (you will only be able to do that with Workers!)</p>
</div>
<script src="src/webworkers/points.js" defer></script>
<script src="src/webworkers/annealing.js" defer></script>
<script defer>
(function() {
var markersArray = [];
var map = null;
var useThreads = false;
document.querySelector('#w-wrapper').addEventListener('click', function(event) {
if (!map) {
map = new google.maps.Map(document.querySelector('#wmap'), {
zoom: 3,
center: new google.maps.LatLng(13, 13),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
map.getDiv().style.border = '1px solid #ccc';
drawPoints();
}
if (event.target.id == 'find-route-y') {
useThreads = true;
document.querySelector('#w-loading').style.visibility = 'visible';
test();
} else if (event.target.id == 'find-route-n'){
useThreads = false;
document.querySelector('#w-loading').style.visibility = 'visible';
// this setTimout is so that we see the 'loading' label
setTimeout(function() { test(); }, 10);
}
}, false);
function drawPath(path) {
var firstPoint = true;
var l = p1.length;
var scaleFactor = 5;
for (var i = 0; i < l - 1; ++i) {
var points = [
new google.maps.LatLng(p1[i].x / scaleFactor,
p1[i].y / scaleFactor),
new google.maps.LatLng(p1[i + 1].x / scaleFactor,
p1[i + 1].y / scaleFactor)
];
var polyline = new google.maps.Polyline(
{path: points, strokeColor: '#ff0000', strokeWeight: 1});
markersArray.push(polyline);
polyline.setMap(map);
}
}
function drawPoints() {
var blueIcon = new google.maps.MarkerImage(
'src/webworkers/point.png',
new google.maps.Size(3, 3), // size
new google.maps.Point(0, 0), // origin
new google.maps.Point(0, 0)); // anchor
for (var i = 0; i < p1.length; ++i) {
// Render in Gmap instead of canvas
var point = new google.maps.LatLng(p1[i].x / 5, p1[i].y / 5);
var marker = new google.maps.Marker({
position: point, icon: blueIcon, map: map});
markersArray.push(marker);
}
}
function deleteOverlays() {
if (markersArray) {
for (var i in markersArray) {
markersArray[i].setMap(null);
}
markersArray = [];
}
}
function test() {
var name = "Test 1";
var self = this;
deleteOverlays();
drawPoints();
setTimeout(function() {
var opts = {
points: p1,
t0: 1,
g: 0.99,
stepsPerT: 10
};
var callback = {
name: name,
newMin: function(p) {
},
draw: function(p) {
document.querySelector('#w-loading').style.visibility = 'hidden';
drawPath(p);
}
};
var a;
if (useThreads) {
var worker = new Worker('src/webworkers/Worker.js')
worker.onmessage = function(event) {
var returnedData = JSON.parse(event.data);
var msg = returnedData[0];
var p = returnedData[1];
callback[msg](p);
};
worker.onerror = function(event) {
console.log(event);
};
worker.postMessage(JSON.stringify({
opts: opts,
width: 200,
height: 200
}));
} else {
var annealing = new Annealing();
var callback2 = {
onNewMin: function(p) {
// postMessage('newmin')
},
onDone: function(p) {
document.querySelector('#w-loading').style.visibility = 'hidden';
drawPath(p);
}
};
annealing.init(opts, opts.width, opts.height, callback2);
annealing.go();
}
}, 10);
}
})();
</script>
</section>
</div>
<div class="slide realtime-communication" id="web-sockets">
<header><span class="js">JS</span> <h1>WebSocket</h1></header>
<section>
<pre>var socket = new <b>WebSocket</b>('ws://html5rocks.websocket.org/echo');
socket.<b>onopen</b> = function(event) {
socket.<b>send</b>('Hello, WebSocket');
};
socket.<b>onmessage</b> = function(event) { alert(event.data); }
socket.<b>onclose</b> = function(event) { alert('closed'); }
</pre>
<p id="websockets-message">Full-duplex, bi-directional communication over the Web:
Both the server and client can send data at any time, or even at the same time.
Only the data itself is sent, without the overhead of HTTP headers, dramatically
reducing bandwidth.</p>
<div id="ws-left">
Use the echo demo below to test a WebSocket connection from your browser.
Both the message you send and the response you receive travel over the same WebSocket connection.
<div id="ws-config-location">
<h4>Location:</h4>
<input type="text" id="wsUri" disabled />
<br>
<input type="checkbox" id="wsSecureCb" onclick="wsToggleTls();" disabled />
<label id="wsSecureCbLabel" for="wsSecureCb">Use secure WebSocket (TLS/SSL)</label>
<br>
<button id="wsConnectBut" disabled>Connect</button>
<button id="wsDisconnectBut" disabled>Disconnect</button>
</div>
<div id="ws-config-message">
<h4>Message:</h4>
<input type="text" id="wsMessage" value="Hello, WebSocket" disabled />
<button id="wsSendBut" disabled>Send</button>
</div>
</div>
<div id="ws-right">
<div id="ws-log">
<strong>Output:</strong>
<div id="wsConsoleLog"></div>
<button id="wsClearLogBut">Clear log</button>
</div>
</div>
<div id="ws-powered">
Demo powered by <a href="http://kaazing.com" target="_blank"><img id="wsKaazingLogo" src="src/websocket/kaazing-logo_99x16.png" width="99" height="16" alt="Powered by Kaazing" /></a>
</div>
</section>
<script src="src/websocket/websocket.js" defer></script>
</div>
<div class="slide realtime-communication" id="notifications-api">
<header><span class="js">JS</span> <h1>Notifications</h1></header>
<section>
<pre>if (window.<b>webkitNotifications</b>.<b>checkPermission</b>() == 0) {
// you can pass any url as a parameter
window.<b>webkitNotifications</b>.<b>createNotification</b>(tweet.picture, tweet.title,
tweet.text).<b>show</b>();
} else {
window.<b>webkitNotifications</b>.<b>requestPermission</b>();
}
</pre>
<div id="notifications-message">
<p>
<button id="request-permission" href="#">Set notification permissions for this page</button>
</p>
<p>Note: Use this button if you also want to <em>reset</em> the permissions</p>
<br>
<p>Enter your twitter user name to show your last tweet as a notification</p>
<input type="text" id="username" placeholder="username" />
<button id="show-tweets">Show tweet notifications</button>
</div>
<script defer>
document.getElementById('request-permission').addEventListener('click', function() {
window.webkitNotifications.requestPermission();
}, false);
document.getElementById('show-tweets').addEventListener('click', function() {
readTweets();
}, false);
function readTweets() {
var username = document.getElementById('username').value;
if (username == 'username') {
alert('Enter a username first');
return;
}
var script = document.createElement("script");
script.src = 'http://twitter.com/statuses/user_timeline/'+ username+'.json?count=1&callback=fetchTweets';
document.body.appendChild(script);
}
function fetchTweets(data) {
var tweet;
var i = data.length;
while (i--) {
tweet = data[i];
if (window.webkitNotifications.checkPermission() == 0) {
// note the show()
window.webkitNotifications.createNotification(tweet.user.profile_image_url, tweet.user.name, tweet.text).show();
} else {
// Note that we can't call requestPermission from here as we are in the callback function and not triggered just on user action
alert('You have to click on "Set notification permissions for this page" first to be able to receive notifications.');
return;
}
}
}
</script>
</section>
</div>
<div class="slide transitionSlide" id="hardware-access-title">
<section class="middle">
<h2>File / Hardware Access</h2>
<p>Deeper integration with the Operating System</p>
<img src="http://www.html5rocks.com/static/images/identity/classes_64/HTML5_Device_Access_64.png" title="HTML5 Device Access" alt="HTML5 Device Access">
</section>
</div>
<div class="slide device-access" id="native-drag-and-drop">
<header><span class="js">JS</span> <h1>Native Drag & Drop</h1></header>
<section id="dnd-section">
<pre>document.addEventListener(<em>'dragstart'</em>, function(event) {
event.<b>dataTransfer.setData</b>('text', 'Customized text');
event.<b>dataTransfer.effectAllowed</b> = 'copy';
}, false);
</pre>
<ol id="drag-zone">
<li><img src="src/dwd1.png" draggable class="copy" /></li>
<li><span class="draggable-text" draggable>Select text and drag (original text will be dropped)</span></li>
<li><span class="draggable-text" draggable class="overwrite">Select text and drag (dragged text data will be altered from original)</span></li>
</ol>
<div id="drop-data">Source Data</div>
<div id="drop-zone">Drop Area</div>
<script defer>
(function() {
var dragZone = document.querySelector('#drag-zone');
var dropZone = document.querySelector('#drop-zone');
dragZone.addEventListener('dragstart', function(event) {
if (event.target.className) { // img case
event.dataTransfer.effectAllowed = event.target.className;
event.target.style.border = "4px solid #cc3300";
}
else { // text case
if (event.target.parentNode.className == 'overwrite') {
event.dataTransfer.setData("text", "<strong>Overwritten Content</strong>");
}
event.target.parentNode.style.border = "4px solid #cc3300";
}
return true;
}, true);
dragZone.addEventListener('dragend', function(event) {
if (event.target.className) { // img case
event.target.style.border = "4px solid #888";
}
else { // text case
event.target.parentNode.style.border = "4px solid #888";
}
return true;
}, true);
dropZone.addEventListener('dragenter', function(event) {
if (event.preventDefault) event.preventDefault();
event.dataTransfer.dropEffect = 'copy';
this.className = 'hovering';
return false;
}, false);
dropZone.addEventListener('dragover', function(event) {
if (event.preventDefault) event.preventDefault(); // allows us to drop
event.dataTransfer.dropEffect = 'copy';
return false;
}, false);
dropZone.addEventListener('dragleave', function(event) {
if (event.preventDefault) event.preventDefault(); // allows us to drop
this.className = '';
return false;
}, false);
dropZone.addEventListener('drop', function(event) {
if (event.preventDefault) event.preventDefault();
var imgPassed = null;
var dropdata = document.querySelector('#drop-data');
var types = event.dataTransfer.types;
document.querySelector('#drop-data').textContent = '';
this.innerHTML = '';
for (var i = 0; i < types.length; i++) {
if (types[i] == 'Files') {
var files = event.dataTransfer.files;
for (var j = 0; j < files.length; j++) {
dropdata.textContent += 'File Name: '+files[j].fileName;
dropdata.textContent += 'File Size: '+files[j].fileSize;
}
}
else {