Created
May 21, 2017 14:44
-
-
Save pmyagkov/b971e8ac0a4111acd13a243e7e81384e to your computer and use it in GitHub Desktop.
[HJ-2.3] Denis Blinkov
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| document.addEventListener('DOMContentLoaded',ready); | |
| //=============== | |
| //Объявляем переменные,которые прослеживаются во всем коде | |
| let arrayObj; | |
| let blockContent; | |
| let xhr; | |
| //============ | |
| function ready() { | |
| xhr = new XMLHttpRequest(); | |
| blockContent = document.querySelector('#content'); | |
| xhr.open('GET', 'https://netology-fbb-store-api.herokuapp.com/book/', true); | |
| xhr.send(); | |
| xhr.addEventListener('load',createBook); | |
| xhr.addEventListener('load', onLoad); | |
| } | |
| function onLoad() { | |
| arrayObj = JSON.parse(xhr.responseText); | |
| } | |
| function createBook() { | |
| for (let i = 0; i < arrayObj.length; i++) { | |
| let tmpLi = document.createElement('li'); | |
| blockContent.appendChild(tmpLi); | |
| tmpLi.setAttribute('data-title', arrayObj[i].title); | |
| tmpLi.setAttribute('data-author', arrayObj[i].author.name); | |
| tmpLi.setAttribute('data-info', arrayObj[i].info); | |
| tmpLi.setAttribute('data-price', arrayObj[i].price); | |
| let tmpImg = document.createElement('img'); | |
| tmpLi.appendChild(tmpImg); | |
| tmpImg.src = arrayObj[i].cover.small; | |
| // console.log(tmpImg) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const dinamycContent = document.querySelector('#content'); | |
| const preloader = document.querySelector('#preloader'); | |
| document.addEventListener('DOMContentLoaded',ready); | |
| function ready() { | |
| document.addEventListener('click', onClick); | |
| function onClick(e) { | |
| e.preventDefault(); | |
| elem = e.target; | |
| console.log(elem); | |
| var tmpActive = document.querySelector(".active"); | |
| tmpActive.classList.remove('active'); | |
| elem.classList.add('active'); | |
| var tmpHrf = elem.getAttribute('href'); | |
| if(tmpHrf !== null) { | |
| LoadPage(tmpHrf); | |
| } | |
| } | |
| } | |
| function LoadPage(tmpHrf) { | |
| console.log(tmpHrf); | |
| var xhr = new XMLHttpRequest(); | |
| xhr.open('GET', tmpHrf); | |
| xhr.addEventListener('loadstart', onLoadStart); | |
| function onLoadStart() { | |
| preloader.classList.remove('hidden') | |
| } | |
| xhr.addEventListener('loadend', onLoadEnd); | |
| function onLoadEnd() { | |
| preloader.classList.add('hidden') | |
| } | |
| xhr.send(); | |
| xhr.addEventListener('load', onLoad); | |
| function onLoad() { | |
| const htmlStructure = xhr.responseText; | |
| console.log(htmlStructure); | |
| dinamycContent.innerHTML = htmlStructure; | |
| } | |
| } | |
| LoadPage('email-tab.html'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const request = new XMLHttpRequest(); | |
| request.addEventListener('load',onLoad); | |
| request.open('GET', 'https://netology-fbb-store-api.herokuapp.com/weather', true); | |
| request.send(); | |
| function onLoad() { | |
| if (request.status === 200) { | |
| const response = JSON.parse(request.responseText); | |
| setData(response); | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment