Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2020
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. function solve(){
  2. const crBtn = document.querySelector('.btn.create');
  3. const sect = document.querySelector('main section');
  4. const arcList = document.querySelector('.archive-section ul');
  5. arcList.innerHTML = '';
  6. crBtn.addEventListener('click',handle);
  7.  
  8. function handle(e){
  9. e.preventDefault();
  10. const data = document.querySelectorAll('form p input');
  11. const wrapArt = getElement('article',undefined,undefined);
  12. wrapArt.appendChild(getElement('h1',undefined,data[1].value));
  13. const p1 = getElement('p',undefined,'Category:');
  14. p1.appendChild(getElement('strong',undefined,data[2].value));
  15. wrapArt.appendChild(p1);
  16. const p2 = getElement('p',undefined,'Creator:');
  17. p2.appendChild(getElement('strong',undefined,data[0].value));
  18. wrapArt.appendChild(p2);
  19. const ctn = document.querySelector('#content').value;
  20. wrapArt.appendChild(getElement('p',undefined,ctn));
  21.  
  22. const divSec = getElement('div',[{k:'class',v:'buttons'}],undefined);
  23. const delBtn = getElement('button',[{k:'class',v:'btn delete'}],'Delete');
  24. const arcBtn = getElement('button',[{k:'class',v:'btn archive'}],'Archive');
  25. divSec.appendChild(delBtn);
  26. divSec.appendChild(arcBtn);
  27. wrapArt.appendChild(divSec);
  28. sect.appendChild(wrapArt);
  29.  
  30. delBtn.addEventListener('click',delHandler);
  31. arcBtn.addEventListener('click',arcHandler);
  32.  
  33. function delHandler(){
  34. sect.removeChild(wrapArt);
  35. }
  36. function arcHandler(){
  37. sect.removeChild(wrapArt);
  38. const title = wrapArt.querySelector('h1').textContent;
  39. arcList.appendChild(getElement('li',undefined,title));
  40. let sArcData = [...arcList.querySelectorAll('li')].map(x=>x.textContent)
  41. .sort((a,b) => a.localeCompare(b));
  42. arcList.innerHTML = '';
  43. sArcData.map(x=>arcList.appendChild(getElement('li',undefined,x)));
  44. }
  45. }
  46.  
  47. function getElement(a,b,c){
  48. let el = document.createElement(a);
  49. if (b !== undefined) b.map(x=>el.setAttribute(x.k, x.v));
  50. if (c !== undefined) el.textContent = c;
  51. return el;
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement