Skip to content
Open

done #153

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion 01/app.js
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
console.log('DOM');
console.log("DOM");
const elCommentsItem = document.querySelector(
".comments__item.comments__item--newest"
);
if (elCommentsItem) {
const dataInfoElements = elCommentsItem.querySelectorAll("[data-info]");
console.log(`There are ${dataInfoElements.length} emelents.`);
}
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

13 changes: 12 additions & 1 deletion 02/app.js
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
console.log('DOM');
console.log("DOM");

const dataUrlList = document.querySelectorAll("a");
if (dataUrlList) {
Comment on lines +3 to +4
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jeśli wyszukujesz wiele elementów i żaden nie został odnaleziony to jest zwracana pusta tablica. Pusta tablica jest obiektem więc jest prawdą. Dlatego waki warunke nie ma sensu bo będzie zawsze prawdziwy. Można go pominać lub poprawić na coś takiego: if (dataUrlList.length > 0)

const dataUrlArr = Array.from(dataUrlList);
dataUrlArr.forEach((el) => {
if (el.dataset.url) {
const url = el.dataset.url;
el.setAttribute("href", url);
}
});
}
37 changes: 25 additions & 12 deletions 03/app.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
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!',
}
attr: {
className: "btn",
title: "super button",
},
css: {
border: "1px solid #336699",
padding: "5px 20px",
color: "#444",
},
text: "Click me!",
};

const parentSectionBtn = document.querySelector(".parent-for-button");
const button = document.createElement("button");

for (key in buttonSettings.attr) {
button.setAttribute(key, buttonSettings.attr[key]);
}
for (key in buttonSettings.css) {
button.style[key] = buttonSettings.css[key];
}
button.innerText = buttonSettings.text;

parentSectionBtn.appendChild(button);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

23 changes: 18 additions & 5 deletions 04/app.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
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'},
];
{ text: "start", url: "/" },
{ text: "galeria", url: "/gallery" },
{ text: "kontakt", url: "/contact" },
];

const navSection = document.querySelector("nav");
const unorderdList = document.createElement("ul");
navSection.appendChild(unorderdList);

for (let i = 0; i < menuItems.length; i++) {
const listItem = document.createElement("li");
const ancherTag = document.createElement("a");
listItem.appendChild(ancherTag);
ancherTag.href = menuItems[i].url;
ancherTag.innerText = menuItems[i].text;
unorderdList.appendChild(listItem);
}
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

68 changes: 66 additions & 2 deletions 05/app.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,67 @@
console.log('DOM');
console.log("DOM");

const curr = document.querySelector('.js-curr');
const curr = document.querySelector(".js-curr");
// 1.
const deletBtn = document.createElement("button");
deletBtn.innerText = "usuń z koszyka";
curr.parentElement.appendChild(deletBtn);
// 2.
const childArr = [...curr.parentElement.children];
childArr.forEach((element) => {
if (element) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wyszukujemy elementy więc one nigdy nie będą "fałszywe", dlatego warunek nie jest potrzeny.
Dodałbym go jednak z innego powodu. CHciałbym dodać klasę "sibling" do rodzeństwa, a nie samego siebie - trzeba curr wykluczyć.

element.classList.add("siblings");
}
});
// 3.
curr.parentElement.nextElementSibling.setAttribute(
"title",
"nextElementSibling"
);
// 4.
const lastArticle = curr.parentElement.parentElement.lastElementChild;
console.log(lastArticle);
const lastArticleBtn = lastArticle.querySelector("button");
const newP = document.createElement("p");
newP.innerText = "---> New text was added with JavaScript right here <---";
lastArticle.insertBefore(newP, lastArticleBtn);

// 5.

const articleData = {
article: {
element: "article",
classList: ["articles__item", "article"],
text: "",
},
header: {
element: "h1",
classList: ["article__title"],
text: "JS - Fist Article",
},
paragrph: {
element: "p",
classList: ["article__description"],
text: "JS - Lorem ipsum dolor sit amet consectetur adipisicing elit. Consequatur quo quibusdam, nemo neque consequuntur pariatur totam? Facere quaerat molestias hic.",
},
button: {
element: "button",
classList: ["article__btn"],
text: "JS - Kupuję!",
},
};

const sectionArticles = curr.parentElement.parentElement;
const newArticle = createElement(articleData.article);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Można też użyć cloneNode(true) - myślę, że wygodniejsze :)

sectionArticles.insertBefore(newArticle, sectionArticles.firstChild);
newArticle.appendChild(createElement(articleData.header));
newArticle.appendChild(createElement(articleData.paragrph));
newArticle.appendChild(createElement(articleData.button));

function createElement(obj) {
const element = document.createElement(obj.element);
for (classElement in obj.classList) {
element.classList.add(classElement);
}
element.innerText = obj.text;
return element;
}