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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
var ThreadBox = View.extend({
el: "#threads",
events: {
},
initialize: function(){
this.__super__.initialize.call(this)
this.template = this.$(".template").html()
this.keywordTemplate = this.$(".keywordTemplate").html()
this.welcomeTemplate = this.$(".welcomeTemplate").html()
this.profileTemplate = this.$(".profileTemplate").html()
},
load: function(data){
if (this.options.welcome) {
this.appendWelcome()
}
if (data.keyword) {
this.appendKeyword(data.keyword)
this.appendThreads(data.threads)
}
else if (data.user) {
this.appendProfile(data.user)
this.appendThreads(data.threads)
}
else {
if (this.options.latest) {
var latest = data.threads.sort( (a,b) => {
return b.lastmodified - a.lastmodified
}).slice(0, 7)
this.appendThreads(latest)
data.threads = data.threads.filter((thread) => thread && !! thread.keyword)
}
var keywords = {}
data.threads.forEach((thread) => {
var keyword = thread.keyword || 'unsorted'
keywords[keyword] = keywords[keyword] || []
keywords[keyword].push(thread)
})
Object.keys(keywords).sort().forEach((keyword) => {
this.appendKeyword({ keyword })
this.appendThreads(keywords[keyword].sort( (a,b) => {
return a.title.localeCompare(b.title) // b.lastmodified - a.lastmodified
}))
})
}
if (is_mobile || window.innerWidth < 700) {
$('.ledger .keyword').each(function(){
$('td:nth-child(2)', this).prepend($("td:nth-child(1)", this).html())
})
}
},
parse: function(thread){
var views = hush_views(thread.viewed)
var size = hush_size(thread.size)
var comments = hush_null(thread.comment_count || 0, "c")
var files = hush_null(thread.file_count || 0, "f")
var dot = privacy_dot(thread.privacy)
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 || "blue" )
var $t = $(t)
if (app.debug) {
var $title = $t.find('.title a')
var href = $title.attr('href')
$title.attr('href', href + '?debug')
}
if (app.debug) {
$t.find('.date').append(' #' + thread.id)
}
return $t
},
parseKeyword: function(keyword){
var t = this.keywordTemplate
.replace(/{{keyword}}/g, keyword.keyword)
return t
},
prependThread: function(thread){
var $row = this.parse(thread)
this.$el.prepend($row)
},
appendThreads: function(threads){
if (threads.length) {
threads[0].first = true
threads[threads.length-1].last = true
threads.forEach(this.appendThread.bind(this))
threads[0].first = false
threads[threads.length-1].last = false
}
},
appendThread: function(thread){
thread.appended = true
var $row = this.parse(thread)
if (thread.first) $row.addClass('first')
if (thread.last) $row.addClass('last')
this.$el.append($row)
},
appendKeyword: function(keyword){
var $row = $( this.parseKeyword(keyword) )
this.$el.append($row)
},
appendWelcome: function(){
this.$el.append(this.welcomeTemplate)
},
appendProfile: function(user){
this.$el.append(this.profileTemplate.replace(/{{username}}/g, user.username))
},
})
|