my-portfolio/dist/editor/js/editor.js

1 line
24 KiB
JavaScript
Raw Normal View History

let dateOptions={month:"short",year:"numeric"},textareaLoaded=!1,editors={},posts=null;function goToPage(e){document.querySelectorAll(".editor section").forEach((t=>{t.style.display="none",t.id===e&&(t.style.display="flex")}))}function addActiveClass(e){document.querySelectorAll("nav.sideNav ul li a").forEach((t=>{t.classList.remove("active"),t.id===e&&t.classList.add("active")}))}function editProjectItem(e){document.querySelector(`#projectItem${e}`).classList.toggle("editing"),document.querySelector(`#title${e}proj`).toggleAttribute("disabled"),document.querySelector(`#info${e}proj`).toggleAttribute("disabled")}function createEditors(...e){e.forEach((e=>{ClassicEditor.create(document.querySelector(`#${e}`),{placeholder:"Write something amazing...",simpleUpload:{uploadUrl:"/api/blog/uploadPostImage",headers:{Authorization:"Bearer "+localStorage.getItem("token")}}}).then((t=>{editors[e]=t})).catch((e=>{console.error("Oops, something went wrong!"),console.error("Please, report the following error on https://github.com/ckeditor/ckeditor5/issues with the build id and the error stack trace:"),console.warn("Build id: 1eo8ioyje2om-vgar4aghypdm"),console.error(e)}))}))}function editPostItem(e){posts.forEach((t=>{t.ID===e&&(document.querySelector("#editPostTitle").value=t.title,document.querySelector("#editIsFeatured").checked=1===t.featured,document.querySelector("#editPostCategories").value=t.categories,editors.CKEditorEditPost.setData(t.body),document.querySelector("#editPostForm input[type='submit']").id=e)}))}function showErrorMessage(e,t){document.querySelector(`#${t}Error`).classList.remove("hidden"),document.querySelector(`#${t}Error div`).innerText=e}function showSuccessMessage(e,t){document.querySelector(`#${t}Success`).classList.remove("hidden"),document.querySelector(`#${t}Success div`).innerText=e}function editCVItem(e){if(textareaLoaded=!1,document.querySelector(`#timelineItem${e}`).classList.toggle("editing"),e.includes("e"))return document.querySelector(`#grade${e}`).toggleAttribute("disabled"),void document.querySelector(`#course${e}`).toggleAttribute("disabled");document.querySelector(`#companyName${e}`).toggleAttribute("disabled"),document.querySelector(`#area${e}`).toggleAttribute("disabled"),document.querySelector(`#jobTitle${e}`).toggleAttribute("disabled")}function addEduData(e,t,o,r,n,d=!1){let a=e+"e",i=document.createElement("form");i.id="timelineItem"+a,i.classList.add("timelineItem"),i.onsubmit=t=>updateEduItem(e,t),i.innerHTML=`\n <div class="modifyBtnContainer">\n <button class="edit" type="button" id="edit${a}" onclick="editCVItem('${a}')"><i class="fa-solid fa-pen-to-square"></i></button>\n <button class="delete" type="button" id="delete${a}" onclick="deleteEduItem(${e})"><i class="fa-solid fa-trash"></i></button>\n </div>\n <div class="dateContainer formControl">\n <input type="date" name="dateFrom${a}" id="dateFrom${a}" onload="this.max = new Date().toISOString().split('T')[0]" value="${t}">\n -\n <input type="date" name="dateTo${a}" id="dateTo${a}" value="${o}">\n </div>\n <h3 class="timelineHeader" id="timelineHeader${a}">${new Date(t).toLocaleString("en-gb",dateOptions)} - ${new Date(o).toLocaleString("en-gb",dateOptions)}</h3>\n <div class="gradeContainer formControl">\n <label for="grade${a}">Grade:</label>\n <input type="text" name="grade${a}" id="grade${a}" value="${r}" disabled>\n </div>\n <div class="formControl">\n <textarea class="courseText" name="course${a}" id="course${a}" cols="10" rows="3" disabled>${n}</textarea>\n </div>\n \n <div class="error hidden" id="eduError${a}">\n <button class="close" type="button" onclick="this.parentElement.classList.toggle('hidden');">&times;</button>\n <div></div>\n </div>\n <input type="submit" value="Change">\n `,d?document.querySelector("#edu").prepend(i):document.getElementById("edu").appendChild(i)}function addWorkData(e,t,o,r,n,d,a=!1){let i=e+"w",c=document.createElement("form");c.id="timelineItem"+i,c.classList.add("timelineItem")