Public/assets/scripts/edit-post.js
//Add textarea and submit button to form to change the description of the post
Add textarea and submit button to form to change the description of the post
Add textarea and submit button to form to change the description of the post
function editMode(event) {
  event.currentTarget.textContent = "Cancel";
  editButtons.forEach(editButton => {
    editButton.removeEventListener("click", editMode);
    editButton.classList.add("cancel");
  });
  event.currentTarget.addEventListener("click", quitEditMode);
  const description =
    event.currentTarget.parentNode.parentNode.nextElementSibling;
  description.classList.toggle("hide");
  const form = event.currentTarget.parentElement;
  form.classList.add("edit-mode");
  const textarea = document.createElement("textarea");
  textarea.classList.add("description-textarea");
  textarea.name = "description";
  textarea.maxLength = "255";
  textarea.textContent = description.childNodes[1].nodeValue;
  form.appendChild(textarea);
  const submitButton = document.createElement("button");
  submitButton.classList.add("save");
  submitButton.classList.add("button");
  submitButton.classList.add("smaller-button");
  submitButton.type = "submit";
  submitButton.textContent = "Save";
  form.appendChild(submitButton);
}
function editMode ( event ) { event . currentTarget . textContent = "Cancel" ; editButtons . forEach ( editButton => { editButton . removeEventListener ( "click" , editMode ) ; editButton . classList . add ( "cancel" ) ; } ) ; event . currentTarget . addEventListener ( "click" , quitEditMode ) ; const description = event . currentTarget . parentNode . parentNode . nextElementSibling ; description . classList . toggle ( "hide" ) ; const form = event . currentTarget . parentElement ; form . classList . add ( "edit-mode" ) ; const textarea = document . createElement ( "textarea" ) ; textarea . classList . add ( "description-textarea" ) ; textarea . name = "description" ; textarea . maxLength = "255" ; textarea . textContent = description . childNodes [ 1 ] . nodeValue ; form . appendChild ( textarea ) ; const submitButton = document . createElement ( "button" ) ; submitButton . classList . add ( "save" ) ; submitButton . classList . add ( "button" ) ; submitButton . classList . add ( "smaller-button" ) ; submitButton . type = "submit" ; submitButton . textContent = "Save" ; form . appendChild ( submitButton ) ; }
Add textarea and submit button to form to change the description of the post
Add textarea and submit button to form to change the description of the post
// Change edit-button to cancel-button and add quitEditMode function to eventlistener // Get the description paragraph nearest the current target and hide it when in edit mode //Get the form element that the current target is child of and add textarea and save-button