Advertisement
knoteva

Untitled

Jul 27th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // NOTE: The comment sections inside the index.html file is an example of how suppose to be structured the current elements.
  2. //       - You can use them as an example when you create those elements, to check how they will be displayed, just uncomment them.
  3. //       - Also keep in mind that, the actual skeleton in judge does not have this comment sections. So do not be dependent on them!
  4. //       - Тhey are present in the skeleton just to help you!
  5.  
  6.  
  7. // This function will be invoked when the html is loaded. Check the console in the browser or index.html file.
  8. function mySolution(){
  9.  
  10.     let textarea = document.getElementsByTagName('textarea')[0];
  11.     let btn = document.getElementsByTagName('button')[0];
  12.     let pendingQuestions = document.getElementById('pendingQuestions');
  13.     let openQuestions = document.getElementById('openQuestions');
  14.     let username = document.getElementsByTagName('input')[0];
  15.  
  16.     btn.addEventListener('click', function(){
  17.  
  18.         if (textarea.value != '') {
  19.             let div1 = document.createElement('div');
  20.             div1.classList.add('pendingQuestion');
  21.             pendingQuestions.appendChild(div1);
  22.  
  23.             let img = document.createElement('img');
  24.             img.setAttribute('src', './images/user.png');
  25.                 img.width = "32";
  26.                 img.height = "32"
  27.             div1.appendChild(img);
  28.  
  29.             let span = document.createElement('span');
  30.             if (username.value != '') {
  31.                 span.textContent = username.value;
  32.             }
  33.             else {
  34.                 span.textContent = 'Anonymous'
  35.             }
  36.             div1.appendChild(span);
  37.  
  38.             let p = document.createElement('p');
  39.             p.textContent  = textarea.value;
  40.             div1.appendChild(p);
  41.  
  42.             // ---
  43.             let div2 = document.createElement('div');
  44.             div2.classList.add("actions");
  45.  
  46.             let btn1 = document.createElement('button');
  47.             btn1.classList.add("archive");
  48.             btn1.textContent = 'Archive'
  49.  
  50.             let btn2 = document.createElement('button');
  51.             btn2.className = 'open';
  52.             btn2.textContent = 'Open';
  53.  
  54.             div1.appendChild(div2);
  55.             div2.appendChild(btn1);
  56.             div2.appendChild(btn2);
  57.  
  58.             username.value = ''
  59.             textarea.value = '';
  60.  
  61.             btn1.addEventListener('click', function() {
  62.                 div1.remove()
  63.             })
  64.  
  65.             btn2.addEventListener('click', function() {
  66.  
  67.                 let div1open = document.createElement('div');
  68.                 div1open.classList.add('openQuestion');
  69.                 openQuestions.appendChild(div1open);
  70.  
  71.                 let imgOpen = document.createElement('img');
  72.                 imgOpen.setAttribute('src', './images/user.png');
  73.                 imgOpen.width = "32";
  74.                 imgOpen.height = "32"
  75.                 div1open.appendChild(imgOpen);
  76.    
  77.                 let spanOpen = document.createElement('span');
  78.                 if (span.textContent != '') {
  79.                     spanOpen.textContent = span.textContent;
  80.                 }
  81.                 else {
  82.                     spanOpen.textContent = 'Anonymous'
  83.                 }
  84.                 div1open.appendChild(spanOpen);
  85.    
  86.                 let pOpen = document.createElement('p');
  87.                 pOpen.textContent  = p.textContent;
  88.                 div1open.appendChild(pOpen);
  89.  
  90.                 div1.remove();
  91.  
  92.                 // ---
  93.  
  94.                 let div2Open = document.createElement('div');
  95.                 div2Open.classList.add("actions");
  96.    
  97.                 let btn1Open = document.createElement('button');
  98.                 btn1Open.classList.add("reply");
  99.                 btn1Open.textContent = 'Reply'
  100.  
  101.                 div1open.appendChild(div2Open);
  102.                 div2Open.appendChild(btn1Open);
  103.  
  104.                 // --
  105.  
  106.                 let div = document.createElement('div');
  107.                 div.classList.add("replySection");
  108.                 div1open.appendChild(div);
  109.  
  110.                 let inputReplay = document.createElement('input');
  111.                 inputReplay.classList.add("replyInput");
  112.                 inputReplay.type = "text";
  113.                 inputReplay.placeholder = "Reply to this question here...";
  114.                 div.appendChild(inputReplay);
  115.  
  116.                 let btnReplay = document.createElement('button');
  117.                 btnReplay.classList.add("replyButton");
  118.                 btnReplay.textContent = 'Send'
  119.                 div.appendChild(btnReplay);
  120.  
  121.                 let olReplay = document.createElement('ol');
  122.                 olReplay.classList.add("reply");
  123.                 olReplay.type = '1'
  124.                 div.appendChild(olReplay);
  125.  
  126.                 div.style.display = 'none';
  127.  
  128.                 btn1Open.addEventListener('click', () => {// Промяна
  129.                     btnReplay.addEventListener('click', function() {
  130.                         if (inputReplay.value!=''){
  131.                             let li = document.createElement('li');
  132.                             li.textContent = inputReplay.value;
  133.                             inputReplay.value = '';
  134.                             inputReplay.placeholder = "Reply to this question here...";
  135.                             olReplay.appendChild(li)
  136.                         }
  137.                     })
  138.                     switch (btn1Open.textContent) {
  139.                         case 'Reply':
  140.                             div.style.display = 'block';
  141.                             btn1Open.textContent = 'Back';
  142.                             break;
  143.                         case 'Back':
  144.                             btn1Open.textContent = 'Reply';
  145.                             div.style.display = 'none';
  146.                             break;
  147.                     }
  148.                 }); // Край промяна
  149.             })
  150.         }
  151.     })
  152.    
  153.  
  154. //  console.log("GOOD LUCK c(:");
  155. }
  156. // To check out your solution, just submit mySolution() function in judge system.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement