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
39 changes: 39 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<html>
<head>
<title>ReReddit</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.4.1/dist/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">

Choose a reason for hiding this comment

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

old version of bootstrap.

</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">
<input id="name" type="text"
class="form-control"
placeholder="Name"></input>
</div>

<div class="form-group">
<textarea id="message" type="text"
class="form-control"
placeholder="Message"></textarea>
</div>

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

</div>
</div>

<script src="main.js"></script>
</body>
</html>
130 changes: 130 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
// Handle new post submission
document.getElementById('submit').addEventListener('click', function () {
// Get and trim input values
const name = document.getElementById('name').value.trim();
const text = document.getElementById('message').value.trim();

// Clear inputs
document.getElementById('name').value = '';
document.getElementById('message').value = '';

// Validate input
if (!name || !text) {
alert("Please fill out both fields!");
return;
}

// Create post

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

// Post container
const postPanel = document.createElement('div');
postPanel.className = 'panel panel-default';

const postBody = document.createElement('div');
postBody.className = 'panel-body';

// Post content
const postText = document.createElement('p');
postText.textContent = `${text} - Posted By: ${name}`;
postText.style.marginTop = '10px';
postText.style.marginBottom = '15px';

// Action buttons
const removeButton = document.createElement('button');
removeButton.textContent = 'Remove Post';
removeButton.className = 'btn btn-danger btn-xs';

const commentButton = document.createElement('button');
commentButton.textContent = 'Comments';
commentButton.className = 'btn btn-default btn-xs';

//Create comment section

const commentsDiv = document.createElement('div');
commentsDiv.style.display = 'none';

const commentsList = document.createElement('div');
commentsList.style.marginTop = '10px';

const commentInput = document.createElement('input');
commentInput.className = 'form-control';
commentInput.placeholder = 'Comment';

const nameInput = document.createElement('input');
nameInput.className = 'form-control';
nameInput.placeholder = 'Your Name';

const postCommentButton = document.createElement('button');
postCommentButton.textContent = 'Post';
postCommentButton.className = 'btn btn-primary btn-sm';

// Assemble comment section
commentsDiv.appendChild(commentsList);
commentsDiv.appendChild(commentInput);
commentsDiv.appendChild(nameInput);
commentsDiv.appendChild(postCommentButton);

// Assemble post
postBody.appendChild(removeButton);
postBody.appendChild(commentButton);
postBody.appendChild(postText);
postBody.appendChild(commentsDiv);

postPanel.appendChild(postBody);
postsDiv.appendChild(postPanel);

// Buttons

// Remove entire post
removeButton.addEventListener('click', function () {
postPanel.remove();
});

// Toggle comment section
commentButton.addEventListener('click', function () {
commentsDiv.style.display = (commentsDiv.style.display === 'none') ? 'block' : 'none';
});

// Handle comment submission
postCommentButton.addEventListener('click', function () {
const commentText = commentInput.value.trim();
const commenterName = nameInput.value.trim();

// Validate comment input
if (!commentText || !commenterName) {
alert("Please fill out both fields!");
return;
}

// Add well for first comment
if (commentsList.children.length === 0) {
commentsList.className = 'well well-sm';
}

// Create comment element
const comment = document.createElement('p');
comment.textContent = `${commentText} - Posted By: ${commenterName}`;

// Create remove link for comment
const removeLink = document.createElement('a');
removeLink.href = '#';
removeLink.textContent = ' x';
removeLink.style.marginLeft = '10px';
removeLink.style.color = 'red';
removeLink.style.cursor = 'pointer';

removeLink.addEventListener('click', function (e) {
e.preventDefault();
comment.remove();
});

comment.appendChild(removeLink);
commentsList.appendChild(comment);

// Clear comment inputs
commentInput.value = '';
nameInput.value = '';
});
});
Empty file added style.css
Empty file.