javascript - Add the date on the top of each group of chats like in what's app -


i'm trying add date on top of messages sent , receive on particular day in chat app. instance:

-----yesterday-----  mike: hello  jan: hi  -----today----  eunice: help! i've been trying day  fid: me too. lets ask help. 

i have written js calculate date , tried append top of messages sent daily. here i've done:

  • add day of week classname messages sent on day
  • use jquery select first element classname (day of week). firbase bomb yes sure i'm still learning though
  • append html tag e.g today first div

here js

last10comments.on('child_added', function (snapshot) { var comment = snapshot.val(); var newdiv = $("<div/>").addclass("comment ").attr("id",snapshot.name()).appendto("#comments");   fb.api("/" + comment.userid, function(userdata) {     comment.name = userdata.name;     newdiv.html(mustache.to_html($('#template').html(), comment));   }); var outputtime = $("<span/>").addclass("timespan "+ te.getdayname() +"").attr("id",yiu).appendto("#comments").text(timeformat());  var tim = $('.'+ te.getdayname() +'')[0]; $('#'+tim+'').prepend( "<p>test</p>" ); }) 

this js gets first element. probelem is, prepend text based on number of element same class. i.e if 5 divs contain same classname, prepends 5 times. e.g wednesday wednesday wednesday wednesday wednesday

i have no way try out, guessing here, try this:

last10comments.on('child_added', function (snapshot) {   (function (te) {     var comment = snapshot.val();     var newdiv = $("<div/>").addclass("comment ").attr("id", snapshot.name()).appendto("#comments");     fb.api("/" + comment.userid, function (userdata) {       comment.name = userdata.name;       newdiv.html(mustache.to_html($('#template').html(), comment));     });     var outputtime = $("<span/>").addclass("timespan " + te.getdayname() + "").attr("id", yiu).appendto("#comments").text(timeformat());      var tim = $('.' + te.getdayname() + '')[0];     $('#' + tim + '').prepend("<p>test</p>");   })(te); }) 

let me know if works. if fixes problem, explain in comments.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -