Created
December 31, 2017 02:38
-
-
Save bennettscience/79fe1b569c4b0f6f14eb390240518aeb to your computer and use it in GitHub Desktop.
Push a comment to a firebase database from a static HTML page
This file contains 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
$(function() { | |
var ref = new Firebase("https://nodes-commenting.firebaseio.com/"), | |
postRef = ref.child(window.location.pathname); | |
postRef.on("child_added", function(snapshot) { | |
var newPost = snapshot.val(); | |
if(newPost.moderated) { | |
$("#comment-list").prepend('<div class="comment">' + | |
'<h4>' + escapeHtml(newPost.name) + '</h4>' + | |
'<div class="profile-image"><img src="http://www.gravatar.com/avatar/' + escapeHtml(newPost.md5Email) + '?s=100&d=retro"/></div> ' + | |
'<span class="date">' + moment(newPost.postedAt).fromNow() + '</span><p>' + escapeHtml(newPost.message) + '</p></div>'); | |
} | |
}); | |
$("#comment").submit(function() { | |
var a = postRef.push(); | |
a.set({ | |
name: $("#name").val(), | |
message: $("#message").val(), | |
md5Email: md5($("#email").val()), | |
postedAt: Firebase.ServerValue.TIMESTAMP, | |
moderated: false | |
}); | |
$("input[type=text], input[type=email], textarea").val(""); | |
$("#toast").removeClass("hide"); | |
setTimeout(function() { | |
$("#toast").addClass("hide"); | |
}, 3000); | |
return false; | |
}); | |
}) |
How this comment.js is use in html with firebase .
I did not store the value of comments in firebase ..
Please help
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi