diff --git a/01-JS-DOM-APIs/.empty b/01-JS-DOM-APIs/.empty deleted file mode 100644 index e69de29bb..000000000 diff --git a/01-JS-DOM-APIs/css/normalize.css b/01-JS-DOM-APIs/css/normalize.css new file mode 100644 index 000000000..bcdf77b45 --- /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/style.css b/01-JS-DOM-APIs/css/style.css new file mode 100644 index 000000000..b6b37e238 --- /dev/null +++ b/01-JS-DOM-APIs/css/style.css @@ -0,0 +1,106 @@ +.header{ + box-shadow: 0px 10px 5px grey; + box-sizing: content-box; + margin-left: 10%; + width: 80%; + height: 50px; + background-color: orange; + text-align: center; +} + +.content{ + display: inline-block; + text-align: center; + width: 70%; + box-sizing: border-box; + margin-left: 15%; +} + +.hidden-list{ + box-sizing: border-box; + overflow-y: auto; + max-height: 300px; + width: 15%; + margin-top: 15%; + float: right; +} + +/*--------------Phone----------------*/ +@media screen and (max-width: 500px){ + .header{ + width: 100%; + margin-left: 0%; + } + + .hidden-list{ + padding-right: 20%; + box-sizing: border-box; + overflow-y: auto; + max-height: 300px; + float: none; + width: 80%; + margin-top: 15px; + margin-left: 20%; + } + + .content{ + text-align: center; + width: 80%; + box-sizing: border-box; + margin-left: 10%; + } +} + +@keyframes fadeInOpacity { + 0% { + opacity: 0; + } + 100% { + opacity: 1; + } +} + +button{ + box-shadow: 0 3px 8px grey; +} + +.hidden{ + box-sizing: border-box; + width: 80%; + margin-left: 10%; +} + +#hi{ + box-sizing: border-box; + width: 70%; + margin-left: 15%; +} + +.topic7{ + box-sizing: border-box; + width: 80%; + margin-left: 10%; + margin-top: 25px; +} + +.fade-in { + opacity: 1; + animation-name: fadeInOpacity; + animation-iteration-count: 1; + animation-timing-function: ease-in; + animation-duration: 2s; +} + +.footer{ + width: 100%; + box-sizing: border-box; + padding-top: 20px; + position: relative; + bottom: 0; + height: 100px; + text-align: center; +} + +.song{ + vertical-align: middle; +} diff --git a/01-JS-DOM-APIs/index.html b/01-JS-DOM-APIs/index.html new file mode 100644 index 000000000..3a068225b --- /dev/null +++ b/01-JS-DOM-APIs/index.html @@ -0,0 +1,50 @@ + + + + + + + + + Resolution + + +
+

Topic 1

+
+

Content

+
+

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." +

+

+ + Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur? + +

+
Hidden content next
+ +
+
Laugh with Chuck Norris jokes
+ +
+
+
Search on Git
+ + +
+
+
+
Hidden list
+ +
+ + \ No newline at end of file diff --git a/01-JS-DOM-APIs/js/jst1.js b/01-JS-DOM-APIs/js/jst1.js new file mode 100644 index 000000000..5029e5f8d --- /dev/null +++ b/01-JS-DOM-APIs/js/jst1.js @@ -0,0 +1,189 @@ +function changeMe(){ + let text = document.getElementById("hi"); + text.hidden = false; +} + +// Ex. 6 +function getJoke(){ + let url = "http://api.icndb.com/jokes/random"; + let joke = "No response received"; + /* We do a try-catch block to manage the + type of response*/ + try{ + let response; + let request; + // We create a new Request + if (window.XMLHttpRequest) { + // code for modern browsers + request = new XMLHttpRequest(); + } else { + // code for old IE browsers + request = new ActiveXObject("Microsoft.XMLHTTP"); + }/*Open the request with the Method and the url, + last boolean is for asynchronous operation*/ + request.open('Get',url,true); + //No parameters needed + request.send(null); + /*Now we do a function that allow the browser to + continue working */ + request.onreadystatechange = function(event){ + if (request.readyState == 4) { + //Number 200 means OK + if (request.status == 200) { + console.log("Request done"); + response = JSON.parse(request.response); + joke = response.value.joke; + document.getElementById("jokeResponse").innerHTML = joke; + } + }else{ + console.log("Making the request"); + } + }; + + }catch (e){ + console.log("Error"); + } + +} + +function errorHandler(statusCode){ + let text = document.getElementById('hi').parentElement; + text.style.backgroundColor = "red"; + console.log("Failed with status: ", statusCode); +} + +//Ex. 7 +function jokeWithPromise(){ + /*Uncomment the next line to test matrixFunc and receive the joke*/ + //testingMatrix(); + let data = { + method: "GET", + url:"http://api.icndb.com/jokes/random", + async:true, + }; + ajaxCall(data).then(promiseToJoke,errorHandler); +} +//Receives the Promise content +function promiseToJoke(data){ + let text = document.getElementById("hi"); + text.innerHTML = data.value.joke; + text.parentElement.style.backgroundColor = "white"; +} + +function ajaxCall(config){ + let promiseObj = new Promise (function (resolve, reject){ + let request; + if (window.XMLHttpRequest) { + // code for modern browsers + request = new XMLHttpRequest(); + } else { + // code for old IE browsers + request = new ActiveXObject("Microsoft.XMLHTTP"); + } + if(config.method == "GET"){ + request.open(config.method,config.url,config.async); + request.send(); + }else{ + request.open(config.method,config.url,config.async); + request.setRequestHeader("Content-type","application/x-ww-form-urlencoded"); + request.send(config.data); + } + request.onreadystatechange = function(){ + if (request.readyState == 4) { + if (request.status == 200) { + let response = JSON.parse(request.responseText); + resolve(response); + } else { + reject(request.status); + } + } else { + console.log("Still processing the request"); + } + } + }); + return promiseObj; +} +/*Another way to do ex 7 is using fetch + but this functionality isnt supported by all browsers*/ +// Ex. 9 - 10 +function gitSearch(){ + let param = document.getElementById("search"); + let data = { + url : "https://api.github.com/search/repositories", + param : "", + method : "GET", + async : true, + } + if (param.value.length > 0) { + if(data.method == "GET"){ + data.url += "?q="+ param.value; + }else{ + data.param = data.value; + } + ajaxCall(data).then(promiseToList,errorHandler); + }else{ + param.placeholder = "Empty search"; + console.log("Empty param"); + } +} + +function promiseToList(data){ + let field = document.getElementById("list"); + field.innerHTML = "Search results: "; + let items = data.items; + for (let item of items){ + let node = document.createElement('li'); + node.innerHTML = item.full_name; + field.appendChild(node); + console.log(item.full_name); + } + field.hidden = false; +} + + +//12 +function matrixToTable(matrix){ + //Create the father node + let table = document.createElement('table'); + table.className = "generatedTable"; + table.style.width = "50%"; + table.style.marginLeft = "25%"; + table.style.marginTop = "20px"; + for (let row of matrix){ + //create the child node + let tableRow = document.createElement('tr'); + for (let col of row){ + //Create the grandchild + let tableCol = document.createElement('td'); + let text = document.createTextNode(col); + //Sticking the text to the td + tableCol.appendChild(text); + tableRow.appendChild(tableCol); + } + table.appendChild(tableRow); + } + let body = document.getElementsByTagName("body"); + let ifExists = document.getElementsByClassName("generatedTable"); + //We create the table if wasnt created before + if(ifExists.length < 1){ + /*Both funcs return an array with all elements that + match with the parameter*/ + let footer = document.getElementsByClassName("footer"); + //To fix this, we put [0] + body[0].insertBefore(table,footer[0]); + }else{ + //We replace the table if was already created + body[0].replaceChild(table,ifExists[0]); + } +} + +function testingMatrix(){ + let matrix = []; + for(let r = 0; r < 6; r++){ + matrix[r] = []; + for(let c = 0; c < 4; c++){ + matrix[r][c] = Math.floor((Math.random() * 100) + 1); + } + } + matrixToTable(matrix); +}