From dbd3a0269f7b01b9eb899f910e9bf6b3da1767c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Mako=CC=81wka?= Date: Mon, 17 Feb 2025 22:56:39 +0100 Subject: [PATCH 1/6] Task 01 --- 01/app.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/01/app.js b/01/app.js index 1c9992ed..23f0d8b9 100644 --- a/01/app.js +++ b/01/app.js @@ -1 +1,8 @@ -console.log('DOM'); \ No newline at end of file +console.log('DOM'); + +const commentsNewest = document.querySelector('.comments__item.comments__item--newest'); + +if (commentsNewest) { + const commentsNewestWithDataInfo = commentsNewest.querySelectorAll('[data-info]'); + console.log(`${commentsNewestWithDataInfo.length} elements found with data-info attribute.`); +}; \ No newline at end of file From d315e82720818442419f527475ff206227b3dc39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Mako=CC=81wka?= Date: Mon, 17 Feb 2025 23:25:21 +0100 Subject: [PATCH 2/6] Task 02 --- 02/app.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/02/app.js b/02/app.js index 1c9992ed..ebd40644 100644 --- a/02/app.js +++ b/02/app.js @@ -1 +1,8 @@ -console.log('DOM'); \ No newline at end of file +console.log('DOM'); + +const linksWithDataUrl = document.querySelectorAll('a[data-url]'); + +linksWithDataUrl.forEach(link => { + const url = link.getAttribute('data-url'); + link.setAttribute('href', url); +}); \ No newline at end of file From 998429377d8f7d4b08a45150519e6e7560d92627 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Mako=CC=81wka?= Date: Tue, 18 Feb 2025 00:09:10 +0100 Subject: [PATCH 3/6] Task 03 --- 03/app.js | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/03/app.js b/03/app.js index c299ca32..29dcd013 100644 --- a/03/app.js +++ b/03/app.js @@ -2,7 +2,7 @@ console.log('DOM'); const buttonSettings = { attr: { - className: 'btn', + class: 'btn', title: 'super button' }, css: { @@ -10,5 +10,27 @@ const buttonSettings = { padding: '5px 20px', color: '#444' }, - text: 'Click me!', -} \ No newline at end of file + textContent: 'Click me!' +}; + +const applySettings = (element, settings) => { + for (const [key, value] of Object.entries(settings)) { + if (key === 'attr') { + for (const [attr, attrValue] of Object.entries(value)) { + element.setAttribute(attr, attrValue); + } + } else if (key === 'css') { + for (const [prop, propValue] of Object.entries(value)) { + element.style[prop] = propValue; + } + } else { + element[key] = value; + } + } +}; + +const button = document.createElement('button'); +applySettings(button, buttonSettings); + +const buttonParent = document.querySelector('.parent-for-button'); +buttonParent.appendChild(button); \ No newline at end of file From e77e240468d3b3e2852165af99b608ab22301c6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Mako=CC=81wka?= Date: Tue, 18 Feb 2025 00:25:07 +0100 Subject: [PATCH 4/6] Task 04 --- 04/app.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/04/app.js b/04/app.js index e6411e4e..88113742 100644 --- a/04/app.js +++ b/04/app.js @@ -5,4 +5,20 @@ const menuItems = [ {text: 'start', url: '/'}, {text: 'galeria', url: '/gallery'}, {text: 'kontakt', url: '/contact'}, -]; \ No newline at end of file +]; + +const navList = document.createElement('ul'); + +menuItems.forEach(item => { + const listItem = document.createElement('li'); + const listItemLink = document.createElement('a'); + + listItemLink.href = item.url; + listItemLink.textContent = item.text; + + listItem.appendChild(listItemLink); + navList.appendChild(listItem); +}); + +const nav = document.querySelector('nav'); +nav.appendChild(navList); \ No newline at end of file From 11c78ca98c5259247abcf4b4794b2d31697735ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Mako=CC=81wka?= Date: Tue, 18 Feb 2025 01:28:56 +0100 Subject: [PATCH 5/6] Task 05 --- 05/app.js | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/05/app.js b/05/app.js index 39abe5d5..1b92d1e0 100644 --- a/05/app.js +++ b/05/app.js @@ -1,3 +1,44 @@ console.log('DOM'); const curr = document.querySelector('.js-curr'); +if (!curr) { + console.error('.js-curr elem not found'); +} else { + const currParent = curr.parentElement; + const articlesSection = currParent.parentElement; + const articles = articlesSection.children; + const lastArticle = articles[articles.length - 1]; + const newArticle = lastArticle.cloneNode(true); // Used the last article as a template + + //1 + const removeButton = document.createElement('button'); + removeButton.textContent = 'UsuĊ„ z koszyka'; + currParent.insertBefore(removeButton, curr.nextElementSibling); + + //2 + for (let child of currParent.children) { + if (child !== curr) child.classList.add('siblings'); + } + + //3 + const nextArticle = currParent.nextElementSibling; + if (nextArticle && nextArticle.classList.contains('article')) nextArticle.setAttribute('title', 'nextElementSibling'); + + //4 + if (lastArticle) { + const extraParagraph = document.createElement('p'); + extraParagraph.textContent = 'Extra paragraph'; + const btnInLast = lastArticle.querySelector('button'); + + btnInLast ? lastArticle.insertBefore(extraParagraph, btnInLast) : lastArticle.appendChild(extraParagraph); + } + + //5 + const titleEl = newArticle.querySelector('.article__title'); + if (titleEl) titleEl.textContent = 'JS - New Article'; + + const descEl = newArticle.querySelector('.article__description'); + if (descEl) descEl.textContent = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'; + + articlesSection.insertBefore(newArticle, articlesSection.firstElementChild); +} \ No newline at end of file From e9948f3c74ae0d76650f55f4fdebc5275c63c9e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Mako=CC=81wka?= Date: Tue, 18 Feb 2025 19:26:48 +0100 Subject: [PATCH 6/6] Improvements --- 03/app.js | 5 ++--- 05/app.js | 6 +++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/03/app.js b/03/app.js index 29dcd013..12767f80 100644 --- a/03/app.js +++ b/03/app.js @@ -2,7 +2,7 @@ console.log('DOM'); const buttonSettings = { attr: { - class: 'btn', + className: 'btn', title: 'super button' }, css: { @@ -17,7 +17,7 @@ const applySettings = (element, settings) => { for (const [key, value] of Object.entries(settings)) { if (key === 'attr') { for (const [attr, attrValue] of Object.entries(value)) { - element.setAttribute(attr, attrValue); + element[attr] = attrValue } } else if (key === 'css') { for (const [prop, propValue] of Object.entries(value)) { @@ -31,6 +31,5 @@ const applySettings = (element, settings) => { const button = document.createElement('button'); applySettings(button, buttonSettings); - const buttonParent = document.querySelector('.parent-for-button'); buttonParent.appendChild(button); \ No newline at end of file diff --git a/05/app.js b/05/app.js index 1b92d1e0..04be152b 100644 --- a/05/app.js +++ b/05/app.js @@ -1,9 +1,7 @@ console.log('DOM'); const curr = document.querySelector('.js-curr'); -if (!curr) { - console.error('.js-curr elem not found'); -} else { +if (curr) { const currParent = curr.parentElement; const articlesSection = currParent.parentElement; const articles = articlesSection.children; @@ -41,4 +39,6 @@ if (!curr) { if (descEl) descEl.textContent = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'; articlesSection.insertBefore(newArticle, articlesSection.firstElementChild); +} else { + console.error('.js-curr elem not found'); } \ No newline at end of file