summaryrefslogtreecommitdiff
path: root/public/assets/js/lib/views/index/threadbox.js
blob: bcaacebd79bb36263ccefbefc797659c4e7aa887 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
age_class
views_class
comments_class
size_class
files_class
*/

var ThreadBox = View.extend({
  el: ".threads",
  
  events: {
  },
  
  initialize: function(){
    this.__super__.initialize.call(this)
    this.template = this.$(".template").html()
  },
  
  load: function(threads){
    threads.forEach(this.appendThread.bind(this))
  },
  
  parse: function(thread){
    var views = hush_views(thread.viewed)
    var size = hush_size(thread.size)
    var comments = hush_null(thread.comment_count, "c")
    var files = hush_null(thread.file_count, "f")
    var dot = privacy_dot(thread.private)
    var datetime = verbose_date(thread.lastmodified)
    var age = get_age(thread.lastmodified)
    var id = thread.id + get_revision(thread)

    var t = this.template
                .replace(/{{id}}/g, id)
                .replace(/{{username}}/g, thread.username)
                .replace(/{{privacy_dot}}/g, dot)
                .replace(/{{title}}/g, thread.title)
                .replace(/{{date}}/g, datetime[0])
                .replace(/{{time}}/g, datetime[1])
                .replace(/{{date_class}}/g, carbon_date(thread.lastmodified) )
                .replace(/{{views}}/g, views[1])
                .replace(/{{comments}}/g, comments[1])
                .replace(/{{files}}/g, files[1])
                .replace(/{{size}}/g, size[1] )
                .replace(/{{views_class}}/g, views[0])
                .replace(/{{comments_class}}/g, comments[0])
                .replace(/{{files_class}}/g, files[0])
                .replace(/{{show_files}}/g, thread.file_count == 0 ? "hidden" : "")
                .replace(/{{size_class}}/g, size[0] )
                .replace(/{{color}}/g, thread.color || "ivory" )
    return t
  },
  
  prependThread: function(thread){
    var $row = $( this.parse(thread) )
    this.$el.prepend($row)
  },

  appendThread: function(thread){
    var $row = $( this.parse(thread) )
    this.$el.append($row)
  },

})