Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function mySolution() {
  2.  
  3.     let textArea = document.querySelector('#inputSection textarea');
  4.     let username = document.querySelector('#inputSection div input');
  5.     let sendButton = document.querySelector('#inputSection div button');
  6.     let pendQuestions = document.querySelector('#pendingQuestions h3');
  7.     let openQuestions = document.querySelector('#openQuestions h3');
  8.  
  9.     sendButton.addEventListener("click", (e) => {
  10.         let div = document.createElement("div");
  11.         div.className = "pendingQuestion";
  12.         pendQuestions.appendChild(div);
  13.         //1
  14.         let img = document.createElement('img');
  15.         img.src = './images/user.png';
  16.         img.width = '32';
  17.         img.height = '32';
  18.         div.appendChild(img);
  19.         //2
  20.         let span = document.createElement("span");
  21.         if (username.value.length > 0) {
  22.             span.textContent = username.value;
  23.         } else {
  24.             span.textContent = "Anonymous";
  25.         }
  26.         div.appendChild(span);
  27.         //3
  28.         let p = document.createElement('p');
  29.         p.textContent = textArea.value;
  30.         div.appendChild(p);
  31.         //4
  32.         let newDiv = document.createElement('div');
  33.         newDiv.className = 'actions';
  34.         div.appendChild(newDiv);
  35.         //newDiv buttons
  36.         let archiveButton = document.createElement('button');
  37.         archiveButton.className = 'archive';
  38.         archiveButton.textContent = 'Archive';
  39.         newDiv.appendChild(archiveButton);
  40.         let openButton = document.createElement('button');
  41.         openButton.className = 'open';
  42.         openButton.textContent = 'Open';
  43.         newDiv.appendChild(openButton);
  44.  
  45.         textArea.value = "";
  46.         username.value = "";
  47.  
  48.         archiveButton.addEventListener("click", (e) => {
  49.             div.remove();
  50.         });
  51.  
  52.         openButton.addEventListener("click", (e) => {
  53.  
  54.             let openDiv = document.createElement("div");
  55.             openDiv.className = "openQuestion";
  56.             openQuestions.appendChild(openDiv);
  57.             //1
  58.             let openImg = document.createElement('img');
  59.             openImg.src = './images/user.png';
  60.             openImg.width = '32';
  61.             openImg.height = '32';
  62.             openDiv.appendChild(openImg);
  63.             //2
  64.             let openSpan = document.createElement("span");
  65.             openSpan.textContent = span.textContent;
  66.             openDiv.appendChild(openSpan);
  67.             //3
  68.             let openP = document.createElement('p');
  69.             openP.textContent = p.textContent;
  70.             openDiv.appendChild(openP);
  71.             //4
  72.             let openNewDiv = document.createElement('div');
  73.             openNewDiv.className = 'actions';
  74.             openDiv.appendChild(openNewDiv);
  75.             //openNewDiv buttons
  76.             let replyButton = document.createElement('button');
  77.             replyButton.className = 'reply';
  78.             replyButton.textContent = 'Reply';
  79.             openNewDiv.appendChild(replyButton);
  80.             //5
  81.             let openNewDiv2 = document.createElement('div');
  82.             openNewDiv2.className = 'replySection';
  83.             openNewDiv2.style.display = 'none';
  84.             openDiv.appendChild(openNewDiv2);
  85.             //openNewDiv2 childs
  86.             let openInput = document.createElement('input');
  87.             openInput.className = 'replyInput';
  88.             openInput.type = "text";
  89.             openInput.placeholder = 'Reply to this question here...';
  90.             openNewDiv2.appendChild(openInput);
  91.  
  92.             let innerButton = document.createElement('button');
  93.             innerButton.className = 'replyButton';
  94.             innerButton.textContent = 'Send';
  95.             openNewDiv2.appendChild(innerButton);
  96.  
  97.             let ol = document.createElement('ol');
  98.             ol.className = "reply";
  99.             ol.type = '1';
  100.             openNewDiv2.appendChild(ol);
  101.  
  102.             replyButton.addEventListener("click", (e) => {
  103.                 if (e.target.textContent === "Reply") {
  104.                     openNewDiv2.style.display = "block";
  105.                     replyButton.textContent = "Back";
  106.  
  107.                     innerButton.addEventListener("click", (e) => {
  108.                         if (openInput.value.length > 0) {
  109.                             let li = document.createElement('li');
  110.                             li.textContent = openInput.value;
  111.                             ol.appendChild(li);
  112.                         }
  113.                         openInput.value = "";
  114.                     });
  115.                 } else {
  116.                     openNewDiv2.style.display = "none";
  117.                     replyButton.textContent = "Reply";
  118.                 }
  119.             });
  120.  
  121.             div.style.display = "none";
  122.         });
  123.     });
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement