thread.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. (function (thread) {
  2. var collapsed = $.state.collapsedThreads().indexOf(thread.id) > -1
  3. , firstPost = thread.posts[0]
  4. , newPosts = $.util.getNewPosts(thread.id);
  5. var body = [ $.h(".threadCollapse",
  6. { onclick: $.emit(collapsed ? "expand" : "collapse", thread.id)},
  7. collapsed
  8. ? [ "[expand]"
  9. , newPosts > 0
  10. ? $.h("a.threadNewPosts",
  11. { onclick: $.util.scrollToFirstNewPost(thread.id) },
  12. String(newPosts))
  13. : null
  14. , $.h(".postDate",
  15. String(firstPost.time || ""))
  16. , $.h(".postUserName",
  17. firstPost.user || $.h("em", "onanimus"))
  18. , $.h(".postText",
  19. firstPost.text.slice(0, 50).concat(
  20. firstPost.text.length > 50 ? "..." : "")) ]
  21. : "[collapse]") ];
  22. if (!collapsed) {
  23. body = body
  24. .concat((thread.posts || []).map(post))
  25. .concat([ _.form(thread) ]);
  26. }
  27. return $.h(".thread", { id: "thread_" + thread.id }, body);
  28. function post (p, i) { return _.post(p, thread, i) }
  29. })