-
Notifications
You must be signed in to change notification settings - Fork 172
done #153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
done #153
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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.`); | ||
| } | ||
| 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
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: |
||
| const dataUrlArr = Array.from(dataUrlList); | ||
| dataUrlArr.forEach((el) => { | ||
| if (el.dataset.url) { | ||
| const url = el.dataset.url; | ||
| el.setAttribute("href", url); | ||
| } | ||
| }); | ||
| } | ||
| 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); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| 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); | ||
| } | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| 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) { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| 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); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Można też użyć |
||
| 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; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍