Skip to content

Instantly share code, notes, and snippets.

@bennettscience
Created December 31, 2017 02:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bennettscience/79fe1b569c4b0f6f14eb390240518aeb to your computer and use it in GitHub Desktop.
Save bennettscience/79fe1b569c4b0f6f14eb390240518aeb to your computer and use it in GitHub Desktop.
Push a comment to a firebase database from a static HTML page
$(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;
});
})
@sabreengithub
Copy link

Hi

@Manish-Attry
Copy link

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