-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopup.js
More file actions
81 lines (66 loc) · 2.52 KB
/
popup.js
File metadata and controls
81 lines (66 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
let submitNote = document.querySelector('.submit');
let title = document.getElementById('box');
let note = document.getElementById('box2');
let link = document.getElementById('box3');
let articles_holder = document.getElementById('articles');
let displayForm = document.querySelector('#form');
let count = document.getElementById('word');
let removeForm = document.getElementById('form');
let cancelButton = document.getElementById('cancel');
let msg = document.querySelector('.msg');
let userList = document.querySelector('.toparticle');
function popup(){
//displaying the form after clicking the button
displayForm.style.display = "block";
title.focus(); //gives focus to the title textbox
}
function cancel(){
//undoes the display of the form that has poped up when used clicks the 'x' cancel button
removeForm.style.display = "none";
//clearInputs();
}
displayForm.addEventListener('submit', wordCount);
function wordCount(e){
e.preventDefault();
let postTitle = title.value;
let postContent = note.value;
let postLink = link.value;
let date = new Date();
if (postTitle === '' || postContent === ''){
msg.innerHTML = "Enter all fields please";
seetTimeout(() => msg.remove(), 3000);
} else {
let article = document.createElement('article');
article.id += 'article';
article.innerHTML = `<section class="top-text-content">
<h2 class="journal_title"><span class="date">${date.toLocaleDateString("en-GB")}:</span>${postTitle}</h2>
<p>
${postContent}
</p>
</section>
<div class="new-img-box">
<img src="${postLink}" alt="">
</div>`
articles_holder.prepend(article);
updateArticleCount();
//let articletop = document.createElement('h2');
//articletop.appendChild(document.createTextNode(`${postTitle}`));
//let articlebottom = document.createElement('p');
//articlebottom.appendChild(document.createTextNode(`${postContent}`));
//userList.appendChild(articletop);
//userList.appendChild(articlebottom);
//clearfields
postTitle = '';
postContent = '';
cancel();
}
}
count.textContent = '2 notes.';
function updateArticleCount() {
let a = articles_holder.childElementCount;
if (a === 0) {
count.textContent = '0 notes.';
} else {
count.textContent = `${a} notes.`
}
}