Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<html>
<head>
<title>ReReddit</title>
<link
href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

outdated version

rel="stylesheet"
/>
<link rel="stylesheet" href="style.css" />
</head>

<body>
<div class="row">
<div class="col-md-6 col-md-offset-3">
<div class="page-header">
<h1>ReReddit</h1>
</div>

<div class="posts"></div>

<form style="margin-top: 30px" onsubmit="event.preventDefault();">
<div class="form-group">
<textarea
id="message"
type="text"
class="form-control"
placeholder="Post Text"
></textarea>
</div>

<div class="form-group">
<input
id="name"
type="text"
class="form-control"
placeholder="Your Name"
/>
</div>

<button id="submit" class="btn btn-primary">Post</button>
</form>
</div>
</div>

<script src="main.js"></script>
</body>
</html>
104 changes: 104 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@

document.getElementById('submit').addEventListener('click', function () {
var name = document.getElementById('name').value;
var text = document.getElementById('message').value;

var postsDiv = document.querySelector('.posts');

/*creating a new post */
var newPostDiv = document.createElement('div');

var newPostTextP = document.createElement('p');
var newPostTextNode = document.createTextNode(text);
newPostTextP.appendChild(newPostTextNode);

var newPostNameP = document.createElement('p');
var newPostNameNode = document.createTextNode('Posted By: ' + name);
newPostNameP.appendChild(newPostNameNode);

var newPostHR = document.createElement('hr');

/* Remove post Button */
var removeLink = document.createElement('a');
removeLink.href = "#";
removeLink.textContent = "Remove";
removeLink.className = "remove-link";

removeLink.addEventListener('click', function(){
newPostDiv.remove();
});

/* Comment Button */
var commentLink = document.createElement('a');
commentLink.href = "#";
commentLink.textContent = "Comment";
commentLink.className = "comment-link";

commentLink.addEventListener('click', function () {

/*Find the comment input*/
var commentInputContainer = newPostDiv.querySelector('.comment-input-container');

if (!commentInputContainer) {

commentInputContainer = document.createElement('div');
commentInputContainer.className = 'form-group comment-input-container';

var commentInput = document.createElement('textarea');
commentInput.className = 'form-control comment-input';
commentInput.placeholder = 'Comment Here';
commentInput.style.marginBottom = '15px'

var commentName = document.createElement('input');
commentName.className = 'form-control comment-name';
commentName.placeholder = 'Name';
commentName.style.marginBottom = '15px'


var submitComment = document.createElement('button');
submitComment.className = 'btn btn-primary';
submitComment.textContent = 'Submit Comment';

submitComment.addEventListener('click', function () {
var commentText = commentInput.value;
var commentNameText = commentName.value;
var newCommentP = document.createElement('p');
newCommentP.textContent = commentNameText + ": " + commentText;

/* Remove Comment Button */
var removeCommentLink = document.createElement('a');
removeCommentLink.href = "#";
removeCommentLink.textContent = " x ";
removeCommentLink.className = "remove-link";

removeCommentLink.addEventListener('click', function () {
newCommentP.remove();
});

newCommentP.appendChild(removeCommentLink);
newPostDiv.appendChild(newCommentP);
commentInputContainer.classList.remove('visible');
});

commentInputContainer.appendChild(commentInput);
commentInputContainer.appendChild(commentName);
commentInputContainer.appendChild(submitComment);

newPostDiv.appendChild(commentInputContainer);
} else {
if (commentInputContainer.classList.contains('visible')) {
commentInputContainer.classList.remove('visible');
} else {
commentInputContainer.classList.add('visible');
}
}
});

newPostDiv.appendChild(removeLink);
newPostDiv.appendChild(commentLink);
newPostDiv.appendChild(newPostTextP);
newPostDiv.appendChild(newPostNameP);
newPostDiv.appendChild(newPostHR);

postsDiv.appendChild(newPostDiv);
});
16 changes: 16 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
body {
background-color: #eaebe7;
}
.remove-link {
margin-right: 10px;
}
.remove-link:hover {
color: red;
}

.comment-input-container {
display: none;
}
.comment-input-container.visible {
display: block;
}