diff --git a/03-HTML5-APIs/.empty b/03-HTML5-APIs/.empty deleted file mode 100644 index e69de29b..00000000 diff --git a/03-HTML5-APIs/.gitignore b/03-HTML5-APIs/.gitignore new file mode 100644 index 00000000..185e6631 --- /dev/null +++ b/03-HTML5-APIs/.gitignore @@ -0,0 +1,21 @@ +.DS_Store +node_modules +/dist + +# local env files +.env.local +.env.*.local + +# Log files +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Editor directories and files +.idea +.vscode +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw* diff --git a/03-HTML5-APIs/css/grid.css b/03-HTML5-APIs/css/grid.css new file mode 100644 index 00000000..ba4204d5 --- /dev/null +++ b/03-HTML5-APIs/css/grid.css @@ -0,0 +1,144 @@ +/*________________________________________________________________________________________________ +Borders and padding are drawn inside the set width of your content. The margin is drawn outside.*/ + +*, +*:before, +*:after { + -moz-box-sizing: border-box; + -webkit-box-sizing: border-box; + box-sizing: border-box; +} + +/*________________________________________________________________________________________________ +Grid Layout.*/ + +@media (min-width: 600px) { + main { + display: grid; + grid-template-columns: repeat(6, 1fr); + } + + + .col-1-row-1 { + grid-column: span 1; + grid-row: span 1; + } + + .col-2-row-1 { + grid-column: span 2; + grid-row: span 1; + } + + .col-3-row-1 { + grid-column: span 3; + grid-row: span 1; + } + + .col-4-row-1 { + grid-column: span 4; + grid-row: span 1; + } + + .col-5-row-1 { + grid-column: span 5; + grid-row: span 1; + } + + .col-6-row-1 { + grid-column: span 6; + grid-row: span 1; + } + + .col-1-row-1 { + grid-column: span 1; + grid-row: span 1; + } + + .col-2-row-2 { + grid-column: span 2; + grid-row: span 2; + } + + .col-3-row-2 { + grid-column: span 3; + grid-row: span 2; + } + + .col-4-row-2 { + grid-column: span 4; + grid-row: span 2; + } + + .col-5-row-2 { + grid-column: span 5; + grid-row: span 2; + } + + .col-6-row-2 { + grid-column: span 6; + grid-row: span 2; + } + + .col-1-row-3 { + grid-column: span 1; + grid-row: span 3; + } + + .col-2-row-3 { + grid-column: span 2; + grid-row: span 3; + } + + .col-3-row-3 { + grid-column: span 3; + grid-row: span 3; + } + + .col-4-row-3 { + grid-column: span 4; + grid-row: span 3; + } + + .col-5-row-3 { + grid-column: span 5; + grid-row: span 3; + } + + .col-6-row-3 { + grid-column: span 6; + grid-row: span 3; + } + + .col-1-row-4 { + grid-column: span 1; + grid-row: span 4; + } + + .col-2-row-4 { + grid-column: span 2; + grid-row: span 4; + } + + .col-3-row-4 { + grid-column: span 3; + grid-row: span 4; + } + + .col-4-row-4 { + grid-column: span 4; + grid-row: span 4; + } + + .col-5-row-4 { + grid-column: span 5; + grid-row: span 4; + } + + .col-6-row-4 { + grid-column: span 6; + grid-row: span 4; + } + +} + +/*________________________________________________________________________________________________*/ \ No newline at end of file diff --git a/03-HTML5-APIs/css/normalize.css b/03-HTML5-APIs/css/normalize.css new file mode 100644 index 00000000..aba238fe --- /dev/null +++ b/03-HTML5-APIs/css/normalize.css @@ -0,0 +1,341 @@ +/*! normalize.css v8.0.0 | MIT License | github.com/necolas/normalize.css */ + +/* Document + ========================================================================== */ + +/** + * 1. Correct the line height in all browsers. + * 2. Prevent adjustments of font size after orientation changes in iOS. + */ + + html { + line-height: 1.15; /* 1 */ + -webkit-text-size-adjust: 100%; /* 2 */ + } + + /* Sections + ========================================================================== */ + + /** + * Remove the margin in all browsers. + */ + + body { + margin: 0; + } + + /** + * Correct the font size and margin on `h1` elements within `section` and + * `article` contexts in Chrome, Firefox, and Safari. + */ + + h1 { + font-size: 2em; + margin: 0.67em 0; + } + + /* Grouping content + ========================================================================== */ + + /** + * 1. Add the correct box sizing in Firefox. + * 2. Show the overflow in Edge and IE. + */ + + hr { + box-sizing: content-box; /* 1 */ + height: 0; /* 1 */ + overflow: visible; /* 2 */ + } + + /** + * 1. Correct the inheritance and scaling of font size in all browsers. + * 2. Correct the odd `em` font sizing in all browsers. + */ + + pre { + font-family: monospace, monospace; /* 1 */ + font-size: 1em; /* 2 */ + } + + /* Text-level semantics + ========================================================================== */ + + /** + * Remove the gray background on active links in IE 10. + */ + + a { + background-color: transparent; + } + + /** + * 1. Remove the bottom border in Chrome 57- + * 2. Add the correct text decoration in Chrome, Edge, IE, Opera, and Safari. + */ + + abbr[title] { + border-bottom: none; /* 1 */ + text-decoration: underline; /* 2 */ + text-decoration: underline dotted; /* 2 */ + } + + /** + * Add the correct font weight in Chrome, Edge, and Safari. + */ + + b, + strong { + font-weight: bolder; + } + + /** + * 1. Correct the inheritance and scaling of font size in all browsers. + * 2. Correct the odd `em` font sizing in all browsers. + */ + + code, + kbd, + samp { + font-family: monospace, monospace; /* 1 */ + font-size: 1em; /* 2 */ + } + + /** + * Add the correct font size in all browsers. + */ + + small { + font-size: 80%; + } + + /** + * Prevent `sub` and `sup` elements from affecting the line height in + * all browsers. + */ + + sub, + sup { + font-size: 75%; + line-height: 0; + position: relative; + vertical-align: baseline; + } + + sub { + bottom: -0.25em; + } + + sup { + top: -0.5em; + } + + /* Embedded content + ========================================================================== */ + + /** + * Remove the border on images inside links in IE 10. + */ + + img { + border-style: none; + } + + /* Forms + ========================================================================== */ + + /** + * 1. Change the font styles in all browsers. + * 2. Remove the margin in Firefox and Safari. + */ + + button, + input, + optgroup, + select, + textarea { + font-family: inherit; /* 1 */ + font-size: 100%; /* 1 */ + line-height: 1.15; /* 1 */ + margin: 0; /* 2 */ + } + + /** + * Show the overflow in IE. + * 1. Show the overflow in Edge. + */ + + button, + input { /* 1 */ + overflow: visible; + } + + /** + * Remove the inheritance of text transform in Edge, Firefox, and IE. + * 1. Remove the inheritance of text transform in Firefox. + */ + + button, + select { /* 1 */ + text-transform: none; + } + + /** + * Correct the inability to style clickable types in iOS and Safari. + */ + + button, + [type="button"], + [type="reset"], + [type="submit"] { + -webkit-appearance: button; + } + + /** + * Remove the inner border and padding in Firefox. + */ + + button::-moz-focus-inner, + [type="button"]::-moz-focus-inner, + [type="reset"]::-moz-focus-inner, + [type="submit"]::-moz-focus-inner { + border-style: none; + padding: 0; + } + + /** + * Restore the focus styles unset by the previous rule. + */ + + button:-moz-focusring, + [type="button"]:-moz-focusring, + [type="reset"]:-moz-focusring, + [type="submit"]:-moz-focusring { + outline: 1px dotted ButtonText; + } + + /** + * Correct the padding in Firefox. + */ + + fieldset { + padding: 0.35em 0.75em 0.625em; + } + + /** + * 1. Correct the text wrapping in Edge and IE. + * 2. Correct the color inheritance from `fieldset` elements in IE. + * 3. Remove the padding so developers are not caught out when they zero out + * `fieldset` elements in all browsers. + */ + + legend { + box-sizing: border-box; /* 1 */ + color: inherit; /* 2 */ + display: table; /* 1 */ + max-width: 100%; /* 1 */ + padding: 0; /* 3 */ + white-space: normal; /* 1 */ + } + + /** + * Add the correct vertical alignment in Chrome, Firefox, and Opera. + */ + + progress { + vertical-align: baseline; + } + + /** + * Remove the default vertical scrollbar in IE 10+. + */ + + textarea { + overflow: auto; + } + + /** + * 1. Add the correct box sizing in IE 10. + * 2. Remove the padding in IE 10. + */ + + [type="checkbox"], + [type="radio"] { + box-sizing: border-box; /* 1 */ + padding: 0; /* 2 */ + } + + /** + * Correct the cursor style of increment and decrement buttons in Chrome. + */ + + [type="number"]::-webkit-inner-spin-button, + [type="number"]::-webkit-outer-spin-button { + height: auto; + } + + /** + * 1. Correct the odd appearance in Chrome and Safari. + * 2. Correct the outline style in Safari. + */ + + [type="search"] { + -webkit-appearance: textfield; /* 1 */ + outline-offset: -2px; /* 2 */ + } + + /** + * Remove the inner padding in Chrome and Safari on macOS. + */ + + [type="search"]::-webkit-search-decoration { + -webkit-appearance: none; + } + + /** + * 1. Correct the inability to style clickable types in iOS and Safari. + * 2. Change font properties to `inherit` in Safari. + */ + + ::-webkit-file-upload-button { + -webkit-appearance: button; /* 1 */ + font: inherit; /* 2 */ + } + + /* Interactive + ========================================================================== */ + + /* + * Add the correct display in Edge, IE 10+, and Firefox. + */ + + details { + display: block; + } + + /* + * Add the correct display in all browsers. + */ + + summary { + display: list-item; + } + + /* Misc + ========================================================================== */ + + /** + * Add the correct display in IE 10+. + */ + + template { + display: none; + } + + /** + * Add the correct display in IE 10. + */ + + [hidden] { + display: none; + } \ No newline at end of file diff --git a/03-HTML5-APIs/css/style.css b/03-HTML5-APIs/css/style.css new file mode 100644 index 00000000..70cde22d --- /dev/null +++ b/03-HTML5-APIs/css/style.css @@ -0,0 +1,66 @@ +body { + max-width: 1600px; + margin: 0 auto; + font-family: Helvetica, sans-serif; + text-rendering: optimizeLegibility; + -webkit-font-smoothing: antialiased; +} + +svg { + width: 128px; + height: 128px; + -webkit-animation: rotation 3s infinite linear; +} + +@-webkit-keyframes rotation { + from { + -webkit-transform: rotate(0deg); + } + to { + -webkit-transform: rotate(359deg); + } +} + + +label { + font-weight: bold; +} + +#textCenter { + text-align: center; +} + +#bio { + border: 5px solid green; +} + +#socket { + border: 5px solid red; +} + +h1 { + border-collapse: collapse; + padding: 0; + margin: 0; + text-align: center; + font-size: 3em; + line-height: 1.3em; +} + +h2 { + font-size: 2em; + margin-bottom: 1em; +} + +.footer { + + right: 0; + bottom: 0; + left: 0; + padding: 1rem; + background-color: #efefef; + text-align: center; + font-size: 2em; + line-height: 1.3em; + font-family: trench +} diff --git a/03-HTML5-APIs/img/favicon.png b/03-HTML5-APIs/img/favicon.png new file mode 100644 index 00000000..7518023d Binary files /dev/null and b/03-HTML5-APIs/img/favicon.png differ diff --git a/03-HTML5-APIs/index.html b/03-HTML5-APIs/index.html new file mode 100644 index 00000000..b3f15125 --- /dev/null +++ b/03-HTML5-APIs/index.html @@ -0,0 +1,73 @@ + + + + + + + 03-HTML5-APIs + + + + + + + + + + +
+

03-HTML5-APIs

+
+
+
+ + + +
+
+

+
+ +

+ +
+
+ + +
+
+
+ + +
+

Write or drop a text file in the Text Area Green.

+

This Text Area only suport files based in text, for example (text/plain , text/html , text/css)

+
+
+

+
+ +

+ +
+ +

Write or drop a text file in the Text Area Red.

+

This Text Area only suport files based in text, for example (text/plain , text/html , text/css)

+
+
+
+ + + + + + + + + + \ No newline at end of file diff --git a/03-HTML5-APIs/js/clearContent.js b/03-HTML5-APIs/js/clearContent.js new file mode 100644 index 00000000..b9a5ebb4 --- /dev/null +++ b/03-HTML5-APIs/js/clearContent.js @@ -0,0 +1,4 @@ +function clearContent(id) { + let clear = document.getElementById(id); + clear.value = ""; +} \ No newline at end of file diff --git a/03-HTML5-APIs/js/dragAndDrop.js b/03-HTML5-APIs/js/dragAndDrop.js new file mode 100644 index 00000000..0f9d512a --- /dev/null +++ b/03-HTML5-APIs/js/dragAndDrop.js @@ -0,0 +1,27 @@ +function handlerDrop(event, idToPut) { + + let htmlPut = document.getElementById(idToPut); + event.preventDefault(); + + let file = event.dataTransfer.files[0]; + let reader = new FileReader(); + + reader.readAsText(file); + + reader.onload = event => { + if(/text/.test(file.type)){ + htmlPut.value = event.target.result; + }else{ + console.log("Only suport files based in text"); + } + } + removeData(event); +} + +function removeData (event) { + if (event.dataTransfer.items) { + event.dataTransfer.items.clear(); + } else { + event.dataTransfer.clearData(); + } +} \ No newline at end of file diff --git a/03-HTML5-APIs/js/indexedDB.js b/03-HTML5-APIs/js/indexedDB.js new file mode 100644 index 00000000..599d771c --- /dev/null +++ b/03-HTML5-APIs/js/indexedDB.js @@ -0,0 +1,96 @@ +function indexedDB_Suported() { + let isSuported = false; + + if (self.indexedDB) { + isSuported = true; + } + return isSuported; +} + +function indexedDB_CreateDB(dbName, nameObjectStore) { + + if (indexedDB_Suported) { + + let requestDB = self.indexedDB.open(dbName); + + requestDB.onupgradeneeded = event => { + let db = event.target.result; + db.createObjectStore(nameObjectStore, { + autoIncrement: true + }); + } + requestDB.onerror = event => { + this.handleError(event.target.errorCode); + } + + } else { + this.handleError('IndexedDB not is supported') + } +} + + +function indexedDB_Save(dbName, nameObjectStore, idToSave) { + + let toSave = document.getElementById(idToSave).value; + + if (indexedDB_Suported) { + + this.indexedDB_CreateDB(dbName, nameObjectStore); + + let requestDB = self.indexedDB.open(dbName); + + requestDB.onsuccess = event => { + let db = event.target.result; + let transaction = db.transaction(nameObjectStore, 'readwrite'); + + let store = transaction.objectStore(nameObjectStore); + store.put(toSave); + + transaction.oncomplete = event => { + console.log('The element "' + toSave + '" has saved correctly in IndexedDB.'); + } + transaction.onerror = event => { + this.handleError(event.target.errorCode); + } + } + requestDB.onerror = event => { + this.handleError(event.target.errorCode); + } + + } else { + this.handleError('IndexedDB not is supported') + } +} + +function indexedDB_Clear(dbName, nameObjectStore) { + + if (indexedDB_Suported) { + + let requestDB = self.indexedDB.open(dbName); + + requestDB.onsuccess = event => { + let db = event.target.result; + let transaction = db.transaction(nameObjectStore, 'readwrite'); + + let store = transaction.objectStore(nameObjectStore); + store.clear(); + + transaction.oncomplete = event => { + console.log('The IndexedDB has erased correctly.'); + } + transaction.onerror = event => { + this.handleError(event.target.errorCode); + } + } + requestDB.onerror = event => { + this.handleError(event.target.errorCode); + } + + } else { + this.handleError('IndexedDB not is supported') + } +} + +function handleError(err) { + console.log("Database error: " + err); +} \ No newline at end of file diff --git a/03-HTML5-APIs/js/localStorage.js b/03-HTML5-APIs/js/localStorage.js new file mode 100644 index 00000000..efb48c98 --- /dev/null +++ b/03-HTML5-APIs/js/localStorage.js @@ -0,0 +1,10 @@ +function localStorage_Save(keyName, idToSave) { + let toSave = document.getElementById(idToSave).value; + localStorage.setItem(keyName, JSON.stringify(toSave)); + console.log('The element "' + toSave + '" has saved correctly in LocalStorage.'); +} + +function localStorage_Clear(keyName) { + localStorage.removeItem(keyName); + console.log('The LocalStorage has erased correctly.'); +} \ No newline at end of file diff --git a/03-HTML5-APIs/js/socket.js b/03-HTML5-APIs/js/socket.js new file mode 100644 index 00000000..8b9f7e3c --- /dev/null +++ b/03-HTML5-APIs/js/socket.js @@ -0,0 +1,29 @@ +function testWebSocket(web, idToInsert, idToExtract) { + + let message = document.getElementById(idToExtract).value; + websocket = new WebSocket(web); + + websocket.onopen = event => { + onOpen(event, message) + } + websocket.onmessage = event => { + onMessage(event, idToInsert) + } + websocket.onerror = event => { + onError(event, idToInsert) + } +} + +function onOpen(event, message) { + websocket.send(message); +} + +function onMessage(event, idToInsert) { + document.getElementById(idToInsert).value = event.data; + websocket.close(); +} + +function onError(event, idToInsert) { + document.getElementById(idToInsert).value = ("ERROR: " + event.data); + websocket.close(); +} \ No newline at end of file diff --git a/03-HTML5-APIs/readme.md b/03-HTML5-APIs/readme.md new file mode 100644 index 00000000..c4fef3a2 --- /dev/null +++ b/03-HTML5-APIs/readme.md @@ -0,0 +1,55 @@ +# Topic 3 - HTML5 APIs + + +### Storages + +:black_large_square: **IndexedDB** + +If your wish is using IndexedDB but with promises, exits one library call idb written by Jake Archibald. + +[IndexedDB with promises and async/await Medium Blog](https://medium.com/@filipvitas/indexeddb-with-promises-and-async-await-3d047dddd313) + +[IndexedDB, with promises GitHub](https://github.com/jakearchibald/idb) + + +### SVG vs Bitmaps + + +:black_large_square: **Bitmaps** + +![Image of Bitmaps](http://www.ne14design.co.uk/images/bitmap-graphic.jpg) + + +##### Advantages + + - Is a good method of reproducing 'continuous tone' images, such as photographs. + + +##### Disadvantages + + - In terms of the amount of digital storage, bitmaps are memory intensive, and the higher the resolution, the larger the file size. + + - When an image is enlarged, the individual coloured squares become visible and the illusion of a smooth image is lost to the viewer. + + + +:black_large_square: **Scalable Vector Graphics (SVG)** + +![Image of SVG](http://www.ne14design.co.uk/images/vector-graphic.gif) + + +##### Advantages + + - Small file size and the ability to scale the image to any size without loss of quality; see the image above. + + +##### Disadvantages + + - Vector graphics, cannot reproduce 'continuous tone' photographic images like bitmaps. + + +#### Conclusion + + - SVG are perfect to logos, save space and scale images to any size. + + - Bitmaps are ideal to photographs images. \ No newline at end of file