From 5ce14b28c64c5a61eadc23103e95094284871e8c Mon Sep 17 00:00:00 2001 From: MichalNowakowski-dev Date: Mon, 4 Nov 2024 17:28:59 +0100 Subject: [PATCH] all done --- 01/app.js | 4 +++- 02/app.js | 7 ++++++- 03/app.js | 41 +++++++++++++++++++++++++++++------------ 04/app.js | 27 +++++++++++++++++++++------ 05/app.js | 39 +++++++++++++++++++++++++++++++++++++-- 5 files changed, 96 insertions(+), 22 deletions(-) diff --git a/01/app.js b/01/app.js index 1c9992ed..56d9b562 100644 --- a/01/app.js +++ b/01/app.js @@ -1 +1,3 @@ -console.log('DOM'); \ No newline at end of file +const item = document.querySelector(".comments__item.comments__item--newest"); + +console.log(item?.querySelectorAll("[data-info]").length); diff --git a/02/app.js b/02/app.js index 1c9992ed..c8724936 100644 --- a/02/app.js +++ b/02/app.js @@ -1 +1,6 @@ -console.log('DOM'); \ No newline at end of file +const links = document.querySelectorAll("[data-url]"); +console.log(links); + +links.forEach((a) => { + a.href = a.getAttribute("data-url"); +}); diff --git a/03/app.js b/03/app.js index c299ca32..8bc506db 100644 --- a/03/app.js +++ b/03/app.js @@ -1,14 +1,31 @@ -console.log('DOM'); +console.log("DOM"); const buttonSettings = { - attr: { - className: 'btn', - title: 'super button' - }, - css: { - border: '1px solid #336699', - padding: '5px 20px', - color: '#444' - }, - text: 'Click me!', -} \ No newline at end of file + attr: { + className: "btn", + title: "super button", + }, + css: { + border: "1px solid #336699", + padding: "5px 20px", + color: "#444", + }, + text: "Click me!", +}; +const btn = document.createElement("button"); + +for (const key in buttonSettings) { + if (Object.prototype.hasOwnProperty.call(buttonSettings, key)) { + const element = buttonSettings[key]; + if (key === "attr") { + btn.className = element.className; + btn.title = element.title; + } else if (key === "css") { + btn.style = element; + } else { + btn.textContent = element; + } + } +} + +document.querySelector(".parent-for-button").appendChild(btn); diff --git a/04/app.js b/04/app.js index e6411e4e..936bc26c 100644 --- a/04/app.js +++ b/04/app.js @@ -1,8 +1,23 @@ -console.log('DOM'); +console.log("DOM"); -// struktura do wykorzystania w pętli const menuItems = [ - {text: 'start', url: '/'}, - {text: 'galeria', url: '/gallery'}, - {text: 'kontakt', url: '/contact'}, -]; \ No newline at end of file + { text: "start", url: "/" }, + { text: "galeria", url: "/gallery" }, + { text: "kontakt", url: "/contact" }, +]; + +const ul = document.createElement("ul"); + +menuItems.forEach((item) => { + const li = document.createElement("li"); + const a = document.createElement("a"); + a.href = item.url; + a.textContent = item.text; + li.appendChild(a); + ul.appendChild(li); +}); + +const nav = document.createElement("nav"); +nav.appendChild(ul); + +document.body.appendChild(nav); diff --git a/05/app.js b/05/app.js index 39abe5d5..8296dc9d 100644 --- a/05/app.js +++ b/05/app.js @@ -1,3 +1,38 @@ -console.log('DOM'); +console.log("DOM"); -const curr = document.querySelector('.js-curr'); +const curr = document.querySelector(".js-curr"); + +const removeButton = document.createElement("button"); +removeButton.classList.add("article__btn"); +removeButton.textContent = "Usuń z koszyka"; +curr.parentNode.appendChild(removeButton); + +const siblings = curr.parentNode.children; +for (let sibling of siblings) { + if (sibling !== curr) { + sibling.classList.add("siblings"); + } +} + +const nextArticle = curr.parentNode.nextElementSibling; +if (nextArticle && nextArticle.classList.contains("article")) { + nextArticle.setAttribute("title", "nextElementSibling"); +} + +const lastArticle = curr.parentNode.parentNode.lastElementChild; +if (lastArticle) { + const newParagraph = document.createElement("p"); + newParagraph.classList.add("article__description"); + newParagraph.textContent = "To jest dodatkowy paragraf przed przyciskiem."; + lastArticle.insertBefore(newParagraph, lastArticle.querySelector("button")); +} + +const firstArticle = curr.parentNode.parentNode.firstElementChild; +const newArticle = firstArticle.cloneNode(true); + +newArticle.querySelector(".article__title").textContent = "JS - Nowy Artykuł"; +newArticle.querySelector(".article__description").textContent = + "To jest nowy artykuł dodany na początku listy."; + +const articlesSection = curr.parentNode.parentNode; +articlesSection.insertBefore(newArticle, articlesSection.firstChild);