-
Notifications
You must be signed in to change notification settings - Fork 223
Posts and Comments - ReReddit #232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
j-emitch
wants to merge
3
commits into
projectshft:master
Choose a base branch
from
j-emitch:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <title>ReReddit</title> | ||
| <link | ||
| href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" | ||
| rel="stylesheet" | ||
| /> | ||
| </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();"> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be in the js file |
||
| <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> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,167 @@ | ||||||
| function randomNumber () { | ||||||
| return Math.floor(Math.random()*90000) + 10000; | ||||||
| }; | ||||||
|
|
||||||
| function createRemoveLink () { | ||||||
| var newRemoveLink = document.createElement('a'); | ||||||
| newRemoveLink.href = '#'; | ||||||
| newRemoveLink.textContent = 'remove'; | ||||||
|
|
||||||
| return newRemoveLink; | ||||||
| }; | ||||||
|
|
||||||
| function createCommentLink () { | ||||||
| var newCommentLink = document.createElement('a'); | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| newCommentLink.href = '#'; | ||||||
| newCommentLink.textContent = 'comments'; | ||||||
|
|
||||||
| return newCommentLink; | ||||||
| }; | ||||||
|
|
||||||
| function removePost(id) { | ||||||
| var postToRemove = document.getElementById(id); | ||||||
| postToRemove.remove(); | ||||||
| }; | ||||||
|
|
||||||
| function createCommentsSection () { | ||||||
| var uniqueId = randomNumber(); | ||||||
| var nameInputId = 'comment-name-' + uniqueId; | ||||||
| var commentTextareaId = 'comment-text-' + uniqueId; | ||||||
|
|
||||||
| var form = document.createElement('form'); | ||||||
| form.style.marginTop = '10px'; | ||||||
|
|
||||||
| var commentTextDiv = document.createElement('div'); | ||||||
| commentTextDiv.className = 'form-group'; | ||||||
| var textarea = document.createElement('textarea'); | ||||||
| textarea.id = commentTextareaId; // Unique ID | ||||||
| textarea.className = 'form-control'; | ||||||
| textarea.placeholder = 'Comment Text'; | ||||||
| commentTextDiv.appendChild(textarea); | ||||||
|
|
||||||
| var nameDiv = document.createElement('div'); | ||||||
| nameDiv.className = 'form-group'; | ||||||
| var nameInput = document.createElement('input'); | ||||||
| nameInput.id = nameInputId; // Unique ID | ||||||
| nameInput.type = 'text'; | ||||||
| nameInput.className = 'form-control'; | ||||||
| nameInput.placeholder = 'Your Name'; | ||||||
| nameDiv.appendChild(nameInput); | ||||||
|
|
||||||
| var submitButton = document.createElement('button'); | ||||||
| submitButton.className = 'btn btn-primary'; | ||||||
| submitButton.textContent = 'Submit Comment'; | ||||||
|
|
||||||
| submitButton.addEventListener('click', function (event) { | ||||||
| event.preventDefault(); | ||||||
|
|
||||||
| var commentText = document.getElementById(commentTextareaId).value; | ||||||
| var commentName = document.getElementById(nameInputId).value; | ||||||
|
|
||||||
| var newComment = document.createElement('div'); | ||||||
| var newCommentTextP = document.createElement('p'); | ||||||
|
|
||||||
| var newCommentTextNode = document.createTextNode(' ' + commentText + ' - Comment By: ' + commentName); | ||||||
|
|
||||||
| var removeLink = createRemoveLink(); | ||||||
|
|
||||||
| newCommentTextP.appendChild(removeLink); | ||||||
| newCommentTextP.append(' '); | ||||||
| newCommentTextP.appendChild(newCommentTextNode); | ||||||
|
|
||||||
| newComment.appendChild(newCommentTextP); | ||||||
|
|
||||||
| var commentsList = form.parentNode.querySelector('.comments-list'); | ||||||
| commentsList.appendChild(newComment); | ||||||
|
|
||||||
| removeLink.addEventListener('click', function (event) { | ||||||
| event.preventDefault(); | ||||||
|
|
||||||
| newComment.remove(); | ||||||
| }); | ||||||
|
|
||||||
| document.getElementById(commentTextareaId).value = ''; | ||||||
| document.getElementById(nameInputId).value = ''; | ||||||
| }); | ||||||
|
|
||||||
| var newCommentHR = document.createElement('hr'); | ||||||
|
|
||||||
| form.appendChild(commentTextDiv); | ||||||
| form.appendChild(nameDiv); | ||||||
| form.appendChild(submitButton); | ||||||
| form.appendChild(newCommentHR); | ||||||
|
|
||||||
| return form; | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
| function createPost () { | ||||||
| var name = document.getElementById('name').value; | ||||||
| var text = document.getElementById('message').value; | ||||||
|
|
||||||
| var newPostDivContainer = document.createElement('div'); | ||||||
| newPostDivContainer.className = 'post-container'; | ||||||
| newPostDivContainer.id = randomNumber(); | ||||||
|
|
||||||
| var newPostDiv = document.createElement('div'); | ||||||
| newPostDiv.className = 'post'; | ||||||
|
|
||||||
| var newPostTextP = document.createElement('p'); | ||||||
|
|
||||||
| var removeLink = createRemoveLink(); | ||||||
|
|
||||||
| removeLink.addEventListener('click', function (event) { | ||||||
| event.preventDefault(); | ||||||
|
|
||||||
| removePost(newPostDivContainer.id); | ||||||
| }); | ||||||
|
|
||||||
|
|
||||||
| var commentsContainer = document.createElement('div'); | ||||||
| commentsContainer.style.display = 'none'; | ||||||
|
|
||||||
| var commentsList = document.createElement('div'); | ||||||
| commentsList.className = 'comments-list'; | ||||||
| commentsContainer.appendChild(commentsList); | ||||||
|
|
||||||
| var commentForm = createCommentsSection(); | ||||||
| commentsContainer.appendChild(commentForm); | ||||||
|
|
||||||
| var commentLink = createCommentLink(); | ||||||
|
|
||||||
| commentLink.addEventListener('click', function (event) { | ||||||
| event.preventDefault(); | ||||||
| commentsContainer.style.display = | ||||||
| commentsContainer.style.display === 'none' ? 'block' : 'none'; | ||||||
| }); | ||||||
|
|
||||||
| var newPostTextNode = document.createTextNode(' ' + text + ' - Posted By: ' + name); | ||||||
|
|
||||||
| newPostTextP.appendChild(removeLink); | ||||||
| newPostTextP.append(' '); | ||||||
| newPostTextP.appendChild(commentLink); | ||||||
| newPostTextP.appendChild(newPostTextNode); | ||||||
|
|
||||||
| var newPostHR = document.createElement('hr'); | ||||||
|
|
||||||
| newPostDiv.appendChild(newPostTextP); | ||||||
| newPostDiv.appendChild(newPostHR); | ||||||
|
|
||||||
| newPostDivContainer.appendChild(newPostDiv); | ||||||
| newPostDivContainer.appendChild(commentsContainer); | ||||||
|
|
||||||
| return newPostDivContainer; | ||||||
| }; | ||||||
|
|
||||||
|
|
||||||
| document.getElementById('submit').addEventListener('click', function (event){ | ||||||
| event.preventDefault(); | ||||||
|
|
||||||
| var newPost = createPost(); | ||||||
|
|
||||||
| var postsDiv = document.querySelector('.posts'); | ||||||
| postsDiv.append(newPost); | ||||||
|
|
||||||
| document.getElementById('message').value = ''; | ||||||
| document.getElementById('name').value = ''; | ||||||
| }); | ||||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bootstrap 3.2.0 is outdated