diff --git a/01-JS-DOM-APIs/css/normalize.css b/01-JS-DOM-APIs/css/normalize.css new file mode 100644 index 00000000..aba238fe --- /dev/null +++ b/01-JS-DOM-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/01-JS-DOM-APIs/css/styles1.css b/01-JS-DOM-APIs/css/styles1.css new file mode 100644 index 00000000..1549e431 --- /dev/null +++ b/01-JS-DOM-APIs/css/styles1.css @@ -0,0 +1,74 @@ + +html{ + background-color: bisque; +} +#hidden{ + opacity: 0; +} + +#hidden.loaded{ + opacity: 1; +} + +h1{ + width: 100%; + text-align: center; +} +footer{ + display: inline-block; + text-align: center; + width: 100%; + bottom: 0%; +} + + +section#joke.error{ + background-color: red; +} + +section#joke{ + background-color: bisque; + margin-top:5%; +} + +section.wrapper { + margin-top: 2%; + float: left; + width:100%; +} +section.row{ + display: flex; +} +.wrapper section.column-two-third{ + margin-top: 5%; + top: 0%; + width: 66%; + text-align: center; +} +.wrapper aside.column-one-third{ + margin-top: 5%; + width: 33%; + text-align: left; +} + +.button{ + padding: 1%; + margin-top: 5%; + +} + +section#table{ + position: relative; + margin-left: 45%; + +} + +table{ + border: 1px solid black; +} +tr{ + border: 1px solid black; +} +td{ + border: 1px solid black; +} \ No newline at end of file diff --git a/01-JS-DOM-APIs/index.html b/01-JS-DOM-APIs/index.html new file mode 100644 index 00000000..f6d27d18 --- /dev/null +++ b/01-JS-DOM-APIs/index.html @@ -0,0 +1,53 @@ + + + + + + + + + + topic 1 + + +
+

TOPIC 1

+
+
+
+

Hello world!

+
+ + + +
+ + +
+ +
+
+ +
+
+ + + +
+ + + +
+ + + + + + diff --git a/01-JS-DOM-APIs/js/functions1.js b/01-JS-DOM-APIs/js/functions1.js new file mode 100644 index 00000000..9a15f4c2 --- /dev/null +++ b/01-JS-DOM-APIs/js/functions1.js @@ -0,0 +1,208 @@ +//exercise 1 + +function showSection(id){ + var element = document.getElementById(id); + + element.classList.add("loaded"); + }; + + window.addEventListener("load", function(){showSection("hidden")}); + + //exercise 2 + +function displayAlert(){ + window.alert("WELCOME!"); +} + +//exercise 3 + + +document.getElementById("btn").addEventListener("click", function(){readApi()}); +/* +function readApi(){ + + fetch('http://api.icndb.com/jokes/random') //connection returns a promise + .then(function(response) { + console.log(response); + return response.json(); //return as a json object + }) + .then(function(myJson) { //i can choose any name to the parameter + console.log(myJson); + //var obj = JSON.parse(myJson); + document.getElementById("joke").innerHTML=myJson.value.joke; + + }); + +} +*/ + + + +function readApi(){ + var request = new XMLHttpRequest(); + request.open("GET", "http://api.icndb.com/jokes/random", true); + + + request.onreadystatechange = function() { + if (this.readyState === 4 && this.status === 200) { + let obj = JSON.parse(request.responseText); //the xhttp.responseText returns a text in JSON format and JSON.parse create an object, + document.getElementById("joke").innerHTML = obj.value.joke; + document.getElementById("joke").classList.remove("error"); //if the conection failed and then, it returns, the background-color:red, disappear + } + }; + request.onerror = function() { + console.log('There was an error!'); + + document.getElementById("joke").innerHTML = 'there was an error'; + document.getElementById("joke").classList.add("error"); + }; + request.send(); +} + + +//reusable function to perform ajax calls + +//promise: it is an object that represents the termination or eventual failure of an asynchronous operation. + + function ajaxFunction(config) { + + return new Promise(function(resolve, reject) { + + var request = new XMLHttpRequest(); + request.open(config.method, config.url, true); + + request.onreadystatechange = function() { + if(request.readyState === 4){ + if (request.status === 200) { + // If successful, resolve the promise by passing back the request response + resolve(request.responseText); + + } else { + // If it fails, reject the promise with a error message + + reject(request.statusText); + } + } + }; + request.onerror = function() { + // in case the entire request fails. + // This is probably a network error, so reject the promise + + reject(Error('There was a network error.')); + + }; + // Send the request + request.send(); + }); +} + + + + + //exercise 4 without AJAX REUSABLE FUNCTION + +/* + +function readApiParameters(){ + var q = searchRepo().value; //it receive the type of the repo + var request = new XMLHttpRequest(); + var config={}; + config.url='https://api.github.com/search/repositories?q=' + q; + config.method='GET'; + request.open(config.method, config.url , true); + + + request.onreadystatechange = function() { + if (this.readyState === 4 && this.status === 200) { + let obj = JSON.parse(request.responseText); //the xhttp.responseText returns a text in JSON format and JSON.parse create an object, + document.getElementById("repositories").innerHTML =""; + obj.items.forEach(element => { + console.log(element) + document.getElementById("repositories").innerHTML += "
  • " + "" + 'https://github.com/' +element.full_name + "" + "
  • " + }); + }; + } + request.onerror = function() { + console.log('There was an error!'); + }; + request.send(); +} + +*/ + +//EXERCISE 4 using AJAX REUSABLE FUNCTION +function configUrl() +{ var q= searchRepo().value; + var config={}; + config.url='https://api.github.com/search/repositories?q=' + q; + config.method='GET'; + return config; +} + +function readApiParameters(){ + var config=configUrl(); + console.log(config); + var promise=ajaxFunction(config) + .then(resolve => printResolve(resolve)) + .catch(reject => console.log('error')); + console.log("fin"); +} + +function printResolve(resolve){ + let obj = JSON.parse(resolve); + document.getElementById("repositories").innerHTML =""; + obj.items.forEach(element => { + document.getElementById("repositories").innerHTML += "
  • " + "" + 'https://github.com/' +element["full_name"] + "" + "
  • " + }) +} + + +function searchRepo(){ + var search= document.getElementById("input"); + return search; +} + + + +//exercise 5 + +function createMatrix(r,c){ + var colArray= new Array(c); + for(let x=0; x < c; x++) + { + colArray[x] = new Array(r); + } + + for(let x=0; x