Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(){
- const crBtn = document.querySelector('.btn.create');
- const sect = document.querySelector('main section');
- const arcList = document.querySelector('.archive-section ul');
- arcList.innerHTML = '';
- crBtn.addEventListener('click',handle);
- function handle(e){
- e.preventDefault();
- const data = document.querySelectorAll('form p input');
- const wrapArt = getElement('article',undefined,undefined);
- wrapArt.appendChild(getElement('h1',undefined,data[1].value));
- const p1 = getElement('p',undefined,'Category:');
- p1.appendChild(getElement('strong',undefined,data[2].value));
- wrapArt.appendChild(p1);
- const p2 = getElement('p',undefined,'Creator:');
- p2.appendChild(getElement('strong',undefined,data[0].value));
- wrapArt.appendChild(p2);
- const ctn = document.querySelector('#content').value;
- wrapArt.appendChild(getElement('p',undefined,ctn));
- const divSec = getElement('div',[{k:'class',v:'buttons'}],undefined);
- const delBtn = getElement('button',[{k:'class',v:'btn delete'}],'Delete');
- const arcBtn = getElement('button',[{k:'class',v:'btn archive'}],'Archive');
- divSec.appendChild(delBtn);
- divSec.appendChild(arcBtn);
- wrapArt.appendChild(divSec);
- sect.appendChild(wrapArt);
- delBtn.addEventListener('click',delHandler);
- arcBtn.addEventListener('click',arcHandler);
- function delHandler(){
- sect.removeChild(wrapArt);
- }
- function arcHandler(){
- sect.removeChild(wrapArt);
- const title = wrapArt.querySelector('h1').textContent;
- arcList.appendChild(getElement('li',undefined,title));
- let sArcData = [...arcList.querySelectorAll('li')].map(x=>x.textContent)
- .sort((a,b) => a.localeCompare(b));
- arcList.innerHTML = '';
- sArcData.map(x=>arcList.appendChild(getElement('li',undefined,x)));
- }
- }
- function getElement(a,b,c){
- let el = document.createElement(a);
- if (b !== undefined) b.map(x=>el.setAttribute(x.k, x.v));
- if (c !== undefined) el.textContent = c;
- return el;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement