diff --git a/task5/css/style.css b/task5/css/style.css new file mode 100644 index 0000000..129abc1 --- /dev/null +++ b/task5/css/style.css @@ -0,0 +1,426 @@ +html{ + overflow-x: hidden; + overflow-y: hidden; +} +body{ + width: 100vw; + height: 100vh; + margin: 0; +} + +.main{ + width: 100vw; + height: 100vh; +} + +.main-header{ + width: 100vw; + height: 8vh; + border: none; + background: url("../img/header.jpg") no-repeat; + background-size: 100% 100%; +} + +.ver-button{ + width: 10%; + height: 50%; + margin: 1% 0 0 87%; + background-color: rgb(0, 163, 232); + border-radius: 10px; + text-align: center; + font-size: 1.1vw; +} + +.filter-page-part{ + width: 100vw; + height: 85vh; + border: none; + background: url("../img/bl.jpg") no-repeat; + background-size: 100% 100%; +} + +.question-user{ + width: 20%; + height: 10.5%; + background-color: rgb(200, 191, 231); + float:left; + margin-top: 1.6%; + margin-left: 4%; + border-radius: 10px; + border: 3px solid #000; + text-align: center; + display: flex; + align-items: center; + font-weight: bold; + font-size: 1.3vw; +} + +.filters-block{ + width: 30%; + height: 16.5%; + border: 3px solid #000; + float:left; + margin-top: 0.6%; + margin-left: 6%; + border-radius: 10px; + background-color: rgb(200, 191, 231); + padding: 0.2%; + padding-top: 0.7%; +} +.filter-single{ + width:100%; + height:30%; +} +#cb-author{ + width:3vw; + height: 3vh; + margin-top:4.4%; +} +.cb{ + float:left; + width:15%; + height:50%; + margin-left: 0%; +} +.label-filter{ + padding:1.2%; + width:35%; + height:50%; + float:left; +} +.filter-text-input{ + margin-top:1%; + font-size: 0.8vw; +} + +.text-of-filters{ + font-size:1.1vw; +} + +.filter-input-part{ + height:95%; + width:80%; + + float: left; +} +#cb-date{ + width:3vw; + height: 3vh; +} +#cb-hashtag{ + width:3vw; + height: 3vh; +} +.block-filter-button{ + height: 95%; + width:17%; + float:right; +} +.filter-button{ + width: 85%; + height: 50.5%; + background-color: rgb(200, 191, 231); + margin-top: 31.4%; + margin-left: 6%; + border-radius: 0.6vw; + font-size: 1.0vw; + outline: none; +} +.add-post-button{ + width: 17%; + height: 10.5%; + background-color: rgb(200, 191, 231); + float: right; + margin-top: 1.6%; + margin-right: 4%; + border-radius: 1.6vw; + font-size: 1.7vw; + outline: none; + visibility: hidden; +} +.cards { + + width: 35vw; + height: 100vw; + position: absolute; + top: -44%; + left: 32.5%; + overflow-x: hidden; + overflow-y: scroll; + transform: rotate(270deg); +} +.cards::-webkit-scrollbar { + display: none; +} +.cards-content { + background-color: rgb(200, 191, 231); + width: 23vw; + height: 30vw; + margin: 3px auto; + transform: rotate(90deg); + border-radius: 10px; + border: 3px solid #000; + +} + +.post-header{ + + width: 95%; + height: 10%; + margin:auto; + +} + +.edit-button{ + outline: none; + width: 15%; + height: 90%; + float:right; + margin-top:1%; + visibility: hidden; +} +.post-hashtags{ + margin-left: 6%; + width: 55%; + height: 90%; + display:inline-block; + font-size: 1vw; + font-style:italic; + overflow:hidden; + margin-top: 2%; +} +.delete-button{ + outline: none; + width: 15%; + height: 90%; + margin-left: 1%; + margin-top:2%; + float: left; + visibility: hidden; +} +.del-add-post-image{ + width: 95%; + height: 95%; + +} +.like-post-image{ + width: 95%; + height: 95%; +} +.like-button{ + outline: none; + width: 23%; + margin-left: 2%; + margin-top: 2%; + float:left; + visibility: hidden; +} +.like-and-comment{ + width: 98%; + height: 16.5%; +} +.image-post{ + margin-top: 1%; + margin-left: 14%; + width: 70%; +} +.post-body{ + height: 66%; + width: 100%; +} +.comments{ + width: 67%; + height: 72.6%; + margin-left: 4%; + margin-top: 2%; + border: 0.2vw solid black; + border-radius: 1vw; + padding: 1%; + background-color: rgb(200, 191, 231); + font-size: 1vw; + overflow:hidden; + float: left; +} +.logged-user{ + + height: 80%; + width: 15%; + margin-left: 83% +} +.user-avatar{ + height:88%; + width:22%; + margin-top: 3%; + background: url("../img/av1.png") no-repeat; + background-size: 100% 100%; + float: left +} +.user-name{ + margin-top: 5%; + float:left; + height:88%; + width:76%; + text-align: center; + font-size: 2vw; + font-weight:bold + +} +.post-data{ + + margin-top: 1%; + margin-left: 2%; + width: 70%; + float: left; + height: 6%; + background-color: rgb(200, 191, 231); + text-align: left; + font-size: 1.3vw; + font-style:italic +} +.post-name{ + margin-top: 1%; + margin-left: 1%; + width: 25%; + height: 6%; + float: left; + background-color: rgb(200, 191, 231); + text-align: right; + font-size: 1.3vw; + font-weight:bold +} +.main-footer{ + width: 100vw; + height: 7vh; + border: none; + background: url("../img/footer.jpg") no-repeat; + background-size: 100% 100%; + alignment: bottom; + padding-top: 1%; + padding-left: 0.5%; +} +.text-footer-date{ + opacity: 0.7; + font-size: 1.0vw; + float: left; +} + +.text-footer-creator{ + opacity: 0.9; + font-size: 1.0vw; + margin-left: 79%; +} +.auth-button{ + width: 57%; + height: 60.5%; + background-color: rgb(200, 191, 231); + float: right; + margin-top: 5%; + margin-right: 1%; + border-radius: 0.6vw; + font-size: 0.9vw; + outline: none; +} +.submit-auth-button{ + width: 25%; + height: 15%; + background-color: rgb(73, 113, 231); + margin-top: 5%; + margin-left: 37.5%; + border-radius: 0.6vw; + font-size: 0.9vw; + outline: none; +} +.cancel-auth-button{ + width: 25%; + height: 15%; + background-color: rgb(73, 113, 231); + margin-top: 5%; + float: right; + border-radius: 0.6vw; + font-size: 0.9vw; + outline: none; +} +.auth-window{ + position: absolute; + top: 20%; + left: 39%; + width: 22%; + height: 30.5%; + border-radius: 0.6vw; + padding: 0.5%; + border: 3px solid yellow; + background-color: rgb(200, 191, 231); + z-index: 100; +} +.ed-window{ + position: absolute; + top: 20%; + left: 39%; + width: 22%; + height: 30.5%; + border-radius: 0.6vw; + padding: 0.5%; + border: 3px solid yellow; + background-color: rgb(200, 191, 231); + z-index: 100; +} +.back-button-edit{ + width: 30%; + height: 51%; + border: solid #090400; + float: right; + alignment: right; + background-color: rgb(91, 164, 231); + cursor: pointer; + outline: none; +} +.user-name-edit{ + float: left; + font-size: 1.6vw; + font-weight: bold; + margin-top: 0; + color: #429eff; +} +.edit-header{ + width: 100%; + height: 25%; +} +.edit-main{ + width: 100%; + height:30%; +} + +.edit-footer{ + width: 100%; + height: 25%; +} +.description-edit{ + height: 100%; + width: 65%; + float: left; + margin-top: 0px; +} +.submit-button-edit{ + height: 112%; + width: 30%; + border: 2px solid #090400; + float: right; + background-color: rgb(91, 164, 231); + cursor: pointer; + outline: none; +} +.input-text-image-edit{ + width: 55%; + height: 16%; + alignment: left; +} +.font-image-edit{ + float: left; + font-size: 0.8vw; + font-weight: bold; + margin-top: 0; + color: #429eff; +} +.login-password-font-style{ + padding: 0 15px; +} diff --git a/task5/img/.gitignore b/task5/img/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/task5/img/av1.png b/task5/img/av1.png new file mode 100644 index 0000000..e337615 Binary files /dev/null and b/task5/img/av1.png differ diff --git a/task5/img/av2.png b/task5/img/av2.png new file mode 100644 index 0000000..5b3b82e Binary files /dev/null and b/task5/img/av2.png differ diff --git a/task5/img/avatar.png b/task5/img/avatar.png new file mode 100644 index 0000000..f2e96bc Binary files /dev/null and b/task5/img/avatar.png differ diff --git a/task5/img/bl.jpg b/task5/img/bl.jpg new file mode 100644 index 0000000..938babc Binary files /dev/null and b/task5/img/bl.jpg differ diff --git a/task5/img/brush.png b/task5/img/brush.png new file mode 100644 index 0000000..0f1ea10 Binary files /dev/null and b/task5/img/brush.png differ diff --git a/task5/img/cross.png b/task5/img/cross.png new file mode 100644 index 0000000..beb1a48 Binary files /dev/null and b/task5/img/cross.png differ diff --git a/task5/img/footer.jpg b/task5/img/footer.jpg new file mode 100644 index 0000000..0565037 Binary files /dev/null and b/task5/img/footer.jpg differ diff --git a/task5/img/header.jpg b/task5/img/header.jpg new file mode 100644 index 0000000..c6224e6 Binary files /dev/null and b/task5/img/header.jpg differ diff --git a/task5/img/like.svg b/task5/img/like.svg new file mode 100644 index 0000000..a1d32f5 --- /dev/null +++ b/task5/img/like.svg @@ -0,0 +1,17 @@ + + + + + background + + + + + + + Layer 1 + + + + + \ No newline at end of file diff --git a/task5/img/liked.svg b/task5/img/liked.svg new file mode 100644 index 0000000..d47dd0e --- /dev/null +++ b/task5/img/liked.svg @@ -0,0 +1,17 @@ + + + + + background + + + + + + + Layer 1 + + + + + \ No newline at end of file diff --git a/task5/img/naruto.png b/task5/img/naruto.png new file mode 100644 index 0000000..2029821 Binary files /dev/null and b/task5/img/naruto.png differ diff --git a/task5/img/sham.png b/task5/img/sham.png new file mode 100644 index 0000000..3920c9d Binary files /dev/null and b/task5/img/sham.png differ diff --git a/task5/js/Data.js b/task5/js/Data.js new file mode 100644 index 0000000..ac5f4ac --- /dev/null +++ b/task5/js/Data.js @@ -0,0 +1,112 @@ +var basicPosts = [ + { + id: '1', + description: 'NARUTO best anime', + createdAt: new Date('2014-12-12'), + author: 'Misha', + photoLink: 'img/naruto.png', + postVisibility: true, + hashTags: ['#NARUTOBESTANIME'], + likes: ['Alex'] + }, + + { + id: '2', + description: 'AVATAR best anime', + createdAt: new Date('2015-12-12'), + author: 'Misha', + photoLink: 'img/avatar.png', + postVisibility: true, + hashTags: ['#AVATARBESTANIME'], + likes: ['Egor'] + }, { + id: '3', + description: 'SHAMAN-KING best anime', + createdAt: new Date('2012-12-12'), + author: 'Misha2019', + photoLink: 'img/sham.png', + postVisibility: true, + hashTags: ['#SHAMANKINGBESTANIME'], + likes: ['Pomeedorka'] + }, + { + id: '4', + description: 'NARURO best anime', + createdAt: new Date('2013-12-12'), + author: 'Misha20', + photoLink: 'img/naruto.png', + postVisibility: true, + hashTags: ['#NARUTOBESTANIME'], + likes: ['Jora'] + }, + { + id: '5', + description: 'AVATAR best anime', + createdAt: new Date('2018-12-12'), + author: 'Misha', + photoLink: 'img/avatar.png', + postVisibility: true, + hashTags: ['#AVATARBESTANIME'], + likes: ['Jaga'] + }, + { + id: '6', + description: 'SHAMAN-KING best anime', + createdAt: new Date('2017-12-12'), + author: 'Misha22', + photoLink: 'img/sham.png', + postVisibility: true, + hashTags: ['#SHAMANKINGBESTANIME'], + likes: ['Jaguar'] + }, + { + id: '7', + description: 'NARUTO best anime', + createdAt: new Date('2016-12-12'), + author: 'Misha23', + photoLink: 'img/naruto.png', + postVisibility: true, + hashTags: ['#NARUTOBESTANIME'], + likes: ['Jagorka'] + }, + { + id: '8', + description: 'AVATAR best anime', + createdAt: new Date('2091-12-12'), + author: 'Misha', + photoLink: 'img/avatar.png', + postVisibility: true, + hashTags: ['#AVATARBESTANIME'], + likes: ['Igor'] + }, + { + id: '9', + description: 'SHAMAN-KING best anime', + createdAt: new Date('2020-12-12'), + author: 'Misha', + photoLink: 'img/sham.png', + postVisibility: true, + hashTags: ['#SHAMANKINGBESTANIME'], + likes: ['Egr'] + }, +]; + +for (var i = 0; i < basicPosts.length; i++) { + addPostToLocalStorage(basicPosts[i]); +} + +function addCurrentUserToLocalStorage(userName){ + localStorage.setItem("user", userName); +} + +function addPostToLocalStorage(post) { + localStorage.setItem(post.id, JSON.stringify(post)); +} + +function getPostFromLocalStorage(keyOfPost){ + return localStorage.getItem(keyOfPost); +} + +function removePostFromLocalStorage(keyOfPost){ + localStorage.removeItem(keyOfPost); +} diff --git a/task5/js/dom.js b/task5/js/dom.js new file mode 100644 index 0000000..d2d49b3 --- /dev/null +++ b/task5/js/dom.js @@ -0,0 +1,277 @@ +var domBlockOfFunc = (function () { + + function createAuthWindow() { + let windowForAuth = document.createElement('div'); + let authButton = document.getElementById('a-button'); + authButton.style.pointerEvents = 'none'; + authButton.style.cursor = 'default'; + let posts = document.getElementById('anime-header'); + windowForAuth.className = 'auth-window'; + windowForAuth.id = 'auth-window' + windowForAuth.innerHTML = `

Авторизация

+

Логин :   

+
+

Пароль :

+ + `; + posts.appendChild(windowForAuth); + } + + function cancelEditing() { + let edWindow = document.getElementById('ed-window'); + let posts = document.getElementById('anime-header'); + posts.removeChild(edWindow); + } + + function cancelAdding() { + let adWindow = document.getElementById('add-window'); + let posts = document.getElementById('anime-header'); + posts.removeChild(adWindow); + } + + function createEditPostDomWindow(edButtonId) { + let windowForEditing = document.createElement('div'); + let posts = document.getElementById('anime-header'); + windowForEditing.className = 'ed-window'; + windowForEditing.id = 'ed-window'; + var submitButtonId = edButtonId.replace('e', ''); + submitButtonId = 's' + submitButtonId; + windowForEditing.innerHTML = `

${userName}

+
+
+

Путь к изображению:

+

Описание:

+
+ `; + + posts.appendChild(windowForEditing); + } + + function createAddPostWindow() { + let windowForEditing = document.createElement('div'); + let posts = document.getElementById('anime-header'); + windowForEditing.className = 'ed-window'; + windowForEditing.id = 'add-window' + + windowForEditing.innerHTML = `

${userName}

+
+
+

Путь к изображению:

+

Описание:

+
+ `; + + posts.appendChild(windowForEditing); + } + + function finishAdding() { + let descriptionEd = document.getElementById('description-for-adding').value; + let imageEd = document.getElementById('image-for-adding').value; + var idOfPost = '' + (photoPosts.length + 1); + var newPhotoPost = { + id: idOfPost, + description: descriptionEd, + createdAt: new Date(), + author: userName, + photoLink: imageEd, + postVisibility: true, + hashTags: [''], + likes: [''] + }; + mainBlockOfFunc.addPhotoPost(newPhotoPost); + var addWindow = document.getElementById('add-window'); + let posts = document.getElementById('anime-header'); + posts.removeChild(addWindow); + } + + function finishEditing(idOfPost) { + let descriptionEd = document.getElementById('description-for-editing').value; + let imageEd = document.getElementById('image-for-editing').value; + var post = {description: descriptionEd, photoLink: imageEd}; + mainBlockOfFunc.editPhotoPost(idOfPost.replace('s', ''), post); + var edWindow = document.getElementById('ed-window'); + let posts = document.getElementById('anime-header'); + posts.removeChild(edWindow); + } + + function finishAuth() { + let authWindow = document.getElementById('auth-window'); + let posts = document.getElementById('anime-header'); + let authBlock = document.getElementById('auth-block'); + let loginValue = document.getElementById('login-field').value; + posts.removeChild(authWindow); + posts.removeChild(authBlock); + let loggedUser = document.createElement('div'); + loggedUser.className = 'logged-user'; + loggedUser.innerHTML = `
${loginValue}
`; + posts.appendChild(loggedUser); + var allPhotoPosts = mainBlockOfFunc.getPhotoPosts(0, photoPosts.length); + userName = loginValue; + //addCurrentUserToLocalStorage(userName); + if(userName){ + let addPostButton = document.getElementById('add-post-button'); + addPostButton.style.visibility = 'visible'; + } + for (var i = 0; i < photoPosts.length; i++) { + activateButtons(allPhotoPosts[i].id); + } + + } + + function activateButtons(idOfPost) { + if(userName){ + let likeButton = document.getElementById('l' + idOfPost); + likeButton.style.visibility = 'visible'; + } + if (document.getElementById(idOfPost) && mainBlockOfFunc.getPhotoPost(idOfPost).author===userName) { + let deleteButton = document.getElementById('del' + idOfPost); + let editButton = document.getElementById('e' + idOfPost); + + deleteButton.style.visibility = 'visible'; + editButton.style.visibility = 'visible'; + } + } + + function cancelAuth() { + let authWindow = document.getElementById('auth-window'); + let posts = document.getElementById('anime-header'); + posts.removeChild(authWindow); + let authButton = document.getElementById('a-button'); + authButton.style.pointerEvents = ''; + authButton.style.cursor = ''; + } + + function deletePostDom(idOfButton) { + var idOfPost = idOfButton.replace('del', ''); + mainBlockOfFunc.removePhotoPost(idOfPost); + removePostFromLocalStorage(idOfPost); + + } + + function addPhotoPostDom(post) { + if (post.postVisibility) { + let cards = document.getElementById('posts'); + let photoPost = document.createElement('div'); + photoPost.className = 'cards-content'; + photoPost.id = post.id; + photoPost.innerHTML = createDomHTML(post); + + cards.appendChild(photoPost); + localStorage.setItem(post.id, JSON.stringify(post)); + } + } + + function addNewPhotoPostDom(post) { + addPhotoPostDom(post) + activateButtons(post.id); + } + + function removePhotoPostDom(idOfPost) { + let photoPost = document.getElementById(idOfPost); + let cards = document.getElementById('posts'); + cards.removeChild(photoPost); + } + + function createDomHTML(post) { + + var idOfDeleteButton = 'del'; + var idOfLikeButton = 'l'; + var idOfEditButton = 'e'; + var imageId = 'im'; + idOfDeleteButton += post.id; + idOfLikeButton += post.id; + idOfEditButton += post.id; + imageId += post.id; + var dateOfCreation = new Date(post.createdAt); + return `
+ Delete +
${post.hashTags}
+ Edit +
+
+ +
+
+
${post.description}
+
+
+
${dateOfCreation.getDate()}.${dateOfCreation.getMonth()}.${dateOfCreation.getFullYear()}
+
${post.author}
+ `; + } + + function likePostDom(idOfPost){ + var imageLike = document.getElementById('im'+idOfPost.replace('l','')); + if(imageLike.src === 'img/like.svg'){ + imageLike.src = 'img/liked.svg'; + } + else{ + imageLike.src = 'img/like.svg'; + } + } + + function editPhotoPostDom(idOfPost, editedPost) { + let photoPost = document.getElementById(idOfPost); + let cards = document.getElementById('posts'); + photoPost.innerHTML = createDomHTML(editedPost); + localStorage.setItem(editedPost.id, JSON.stringify(editedPost)); + activateButtons(idOfPost); + } + + function filterWindow() { + var filterParam = {createdAt: '', author: '', hashTags: ['']}; + var checkBoxAuthor = document.getElementById('cb-author').checked; + if (checkBoxAuthor) { + var valueOfAuthorFilter = document.getElementById('text-field-filter-author').value; + filterParam.author = valueOfAuthorFilter; + } + var checkBoxDate = document.getElementById('cb-date').checked; + if (checkBoxDate) { + var valueOfDateFilter = document.getElementById('text-field-filter-date').value; + filterParam.createdAt = new Date(valueOfDateFilter); + } + var checkBoxHashTags = document.getElementById('cb-hashtag').checked; + if (checkBoxHashTags) { + var valueOfHashTagsFilter = document.getElementById('text-field-filter-hashtags').value; + filterParam.hashTags[0] = valueOfHashTagsFilter; + } + var sortedArrOfPosts = mainBlockOfFunc.getPhotoPosts(0,photoPosts.length,filterParam); + var posts = document.getElementById('posts'); + while(posts.firstChild){ + posts.removeChild(posts.firstChild); + } + for(var i=0;i0) { + photoPosts[i-counter] = JSON.parse(localStorage.getItem(keys[i-counter])); + counter--; + } + for(var k=0;k photoPosts.length || postStart < 0) { + console.log('Нельзя вывести столько постов. Промежуток вывода не совпадает с количеством постов'); + return null; + } + else { + var sortedArrOfPosts = photoPosts; + if(typeof filterConfig !== 'undefined'){ + if (filterConfig.author) { + sortedArrOfPosts = sortedArrOfPosts.filter(function (post) { + return post.author === filterConfig.author; + }); + } + if (filterConfig.createdAt) { + sortedArrOfPosts = sortedArrOfPosts.filter(function (post) { + return post.createdAt === filterConfig.createdAt; + }); + } + if (filterConfig.hashTags) { + sortedArrOfPosts = sortedArrOfPosts.filter(function (post) { + for (let hashTagsOfPost of post.hashTags) { + for (let hashTagsOfFilter of [].concat(filterConfig.hashTags)) { + if (hashTagsOfPost.search(hashTagsOfFilter) !== -1) { + return true; + } + } + } + }); + } + } + sortedArrOfPosts = sortedArrOfPosts.sort(dateComparator).slice(postStart, number + postStart); + + return sortedArrOfPosts; + } + } + + function dateComparator(post1, post2) { + return post1.createdAt - post2.createdAt; + } + + function getPhotoPost(idOfPost) { + return photoPosts.find(function findPost(post) { + return post.id === idOfPost; + }); + } + + function validatePhotoPost(postForCheck) { + if (typeof postForCheck.id !== 'string' || postForCheck.id === '') { + console.log('Пустое поле id'); + return false; + } + + if (photoPosts.some(function checkUniqueness(post) { + return postForCheck.id === post.id; + })) { + console.log('id не уникальный'); + return false; + } + + if (typeof postForCheck.description !== 'string' || postForCheck.description.length > 200 || postForCheck.description === '') { + console.log('Неверный description'); + return false; + } + if (typeof postForCheck.author !== 'string' || postForCheck.author === '') { + console.log('Поле author пустое'); + return false; + } + if (!(postForCheck.createdAt instanceof Date) || ((postForCheck.createdAt).toString() === 'Invalid Date')) { + console.log('Поле даты создания не введено, либо имеет неправильную структуру'); + return false; + } + if (typeof postForCheck.photoLink !== 'string' || postForCheck.photoLink === '') { + console.log('Поле photoLink пустое'); + return false; + } + if (!(postForCheck.hashTags instanceof Array)) { + console.log('Структура поля hashTags не верна'); + return false; + } + return true; + } + + function validateForEditing(postForCheck) { + if (typeof postForCheck.description !== 'string' || postForCheck.description.length > 200 || postForCheck.description === '') { + console.log('Неверный description'); + + return false; + } + if (typeof postForCheck.author !== 'string' || postForCheck.author === '') { + console.log('Поле author пустое'); + return false; + } + if (!(postForCheck.createdAt instanceof Date) || ((postForCheck.createdAt).toString() === 'Invalid Date')) { + console.log('Поле даты создания не введено, либо имеет неправильную структуру'); + alert(postForCheck.createdAt); + return false; + } + if (typeof postForCheck.photoLink !== 'string' || postForCheck.photoLink === '') { + console.log('Поле photoLink пустое'); + return false; + } + if (!(postForCheck.hashTags instanceof Array)) { + console.log('Структура поля hashTags не верна'); + return false; + } + return true; + } + + function addPhotoPost(newPost) { + if (!validatePhotoPost(newPost)) { + return false; + } + else { + photoPosts.push(newPost); + domBlockOfFunc.addNewPhotoPostDom(newPost); + return true; + } + } + + function editPhotoPost(idForEd, postForEd) { + var postOfId = getPhotoPost(idForEd); + if (!postOfId) { + return false; + } + var postCopy = JSON.parse(JSON.stringify(postOfId)); + if (postForEd.description) { + postCopy.description = postForEd.description; + } + if (postForEd.author) { + postCopy.author = postForEd.author; + } + if (postForEd.photoLink) { + postCopy.photoLink = postForEd.photoLink; + } + if (postForEd.hashTags) { + postCopy.hashTags = postForEd.hashTags; + } + postCopy.createdAt = new Date(); + if (validateForEditing(postCopy)) { + changePostData(postOfId, postCopy); + domBlockOfFunc.editPhotoPostDom(idForEd, postCopy); + return true; + } + return false; + } + + function changePostData(post1, post2) { + post1.description = post2.description; + + post1.author = post2.author; + + post1.createdAt = post2.createdAt; + + post1.photoLink = post2.photoLink; + + post1.hashTags = post2.hashTags; + } + + function removePhotoPost(idForRem) { + var postOfId = getPhotoPost(idForRem); + if (postOfId == null) { + console.log('Пост для удаления не найден'); + return false; + } + else { + postOfId.postVisibility = false; + domBlockOfFunc.removePhotoPostDom(idForRem); + return true; + } + } + + return { + addPhotoPost, + removePhotoPost, + getPhotoPosts, + editPhotoPost, + getPhotoPost + } +}()); + diff --git a/task5/mainPage.html b/task5/mainPage.html new file mode 100644 index 0000000..d6baa6f --- /dev/null +++ b/task5/mainPage.html @@ -0,0 +1,86 @@ + + + + + + Title + + + +
+
+
+ +
+
+
+ +
+
+
+ +
+
+ + + + + + +