Skip to content
Open

done #155

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
11 changes: 10 additions & 1 deletion 01/app.js
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
console.log('DOM');
console.log('DOM');

const UlElement = document.querySelector('ul');
if (UlElement) {
const classElement = UlElement.querySelector(
'.comments__item.comments__item--newest'
);
const dataInfo = classElement.querySelectorAll('[data-info]');
console.log(dataInfo.length);
}
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.

👍

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

const linksEl = document.querySelectorAll('[data-url]');
linksEl.forEach((link) => {
const url = link.dataset.url;
link.setAttribute('href', url);
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.

👍

});
36 changes: 25 additions & 11 deletions 03/app.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
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 button = document.createElement('button');
for (const key in buttonSettings.attr) {
button[key] = buttonSettings.attr[key];
}
for (const styleKey in buttonSettings.css) {
button.style[styleKey] = buttonSettings.css[styleKey];
}
button.innerText = buttonSettings.text;

const parentElement = document.querySelector('.parent-for-button');
if (parentElement) {
parentElement.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.

👍

55 changes: 51 additions & 4 deletions 04/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,54 @@ 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' },
];

// z użyciem pętli
const navElement = document.querySelector('nav');
const ulElement = document.createElement('ul');

menuItems.forEach((item) => {
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.

Jak widać zdecydowanie wygodniej i lepiej używać pętli :)
Czasami trzeba rozpisać sobie krok po kroku, aby użyć pętli - to nie jest źle, ale ostateczna wersja powinna być z wykorzystaniem pętli.

const li = document.createElement('li');
const a = document.createElement('a');

a.setAttribute('href', item.url);
a.innerText = item.text;

li.appendChild(a);
ulElement.appendChild(li);
});

navElement.appendChild(ulElement);

//bez pętli

const ulElement = document.createElement('ul');
const li1 = document.createElement('li');
const a1 = document.createElement('a');
const li2 = document.createElement('li');
const a2 = document.createElement('a');
const li3 = document.createElement('li');
const a3 = document.createElement('a');
const navElement = document.querySelector('nav');
a1.setAttribute('href', '/');
a1.innerText = 'start';
li1.appendChild(a1);
ulElement.appendChild(li1);


a2.setAttribute('href', '/gallery');
a2.innerText = 'galeria';
li2.appendChild(a2);
ulElement.appendChild(li2);

a3.setAttribute('href', '/contact');
a3.innerText = 'kontakt';
li3.appendChild(a3);
ulElement.appendChild(li3);


navElement.appendChild(ulElement);

49 changes: 49 additions & 0 deletions 05/app.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,52 @@
console.log('DOM');

const curr = document.querySelector('.js-curr');
const button = document.createElement('button');
button.innerText = 'usuń z koszyka';
curr.parentElement.appendChild(button);

const parent = curr.parentElement;
const children = parent.children;

for (let i = 0; i < children.length; i++) {
if (children[i] !== curr) {
children[i].classList.add('siblings');
}
}

const nextArticle = parent.nextElementSibling;
if (nextArticle && nextArticle.classList.contains('article')) {
nextArticle.setAttribute('title', 'nextElementSibling');
}

const articles = document.querySelectorAll('.article');
const lastArticle = articles[articles.length - 1];
const lastButton = lastArticle.querySelector('button');
const newParagraph = document.createElement('p');
newParagraph.innerText = 'Nowy paragraf przed przyciskiem';

lastArticle.insertBefore(newParagraph, lastButton);

const newArticle = document.createElement('article');
newArticle.classList.add('articles__item', 'article');

const newTitle = document.createElement('h1');
newTitle.classList.add('article__title');
newTitle.innerText = 'Nowy artykuł';

const newDescription = document.createElement('p');
newDescription.classList.add('article__description');
newDescription.innerText = 'Nowy opis';

const newButton = document.createElement('button');
newButton.classList.add('article__btn');
newButton.innerText = 'Nowy przycisk';

newArticle.appendChild(newTitle);
newArticle.appendChild(newDescription);
newArticle.appendChild(newButton);


const articlesContainer = document.querySelector('.articles');

articlesContainer.insertBefore(newArticle, articlesContainer.firstChild);
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.

👍