summaryrefslogtreecommitdiff
path: root/public/assets/js
diff options
context:
space:
mode:
Diffstat (limited to 'public/assets/js')
-rw-r--r--public/assets/js/lib/views/index/threadbox.js47
-rw-r--r--public/assets/js/util/format.js86
2 files changed, 133 insertions, 0 deletions
diff --git a/public/assets/js/lib/views/index/threadbox.js b/public/assets/js/lib/views/index/threadbox.js
new file mode 100644
index 0000000..951b025
--- /dev/null
+++ b/public/assets/js/lib/views/index/threadbox.js
@@ -0,0 +1,47 @@
+/*
+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(comments){
+ comments.forEach(this.appendComment.bind(this))
+ },
+
+ parse: function(thread){
+ var t = this.template
+ .replace(/{{id}}/g, thread.id)
+ .replace(/{{username}}/g, thread.username)
+ .replace(/{{title}}/g, thread.title)
+ .replace(/{{age}}/g, get_age(thread.lastmodified) )
+ .replace(/{{views}}/g, thread.views + " v.")
+ .replace(/{{comments}}/g, thread.comments + " c.")
+ .replace(/{{files}}/g, thread.files + " c.")
+ .replace(/{{size}}/g, get_size(thread.size) )
+ return t
+ },
+
+ prependComment: function(comment){
+ var $el = $( this.parse(comment) )
+ this.$hoots.prepend($el)
+ },
+
+ appendComment: function(comment){
+ var $el = $( this.parse(comment) )
+ this.$hoots.append($el)
+ },
+
+})
diff --git a/public/assets/js/util/format.js b/public/assets/js/util/format.js
new file mode 100644
index 0000000..21b1f68
--- /dev/null
+++ b/public/assets/js/util/format.js
@@ -0,0 +1,86 @@
+function commatize (n) {
+ var nums, i, counter = 0
+ if (n > 1024) {
+ n /= 1024;
+ nums.unshift((n * 10) % 10)
+ nums.unshift(".")
+ }
+
+ do {
+ i = n % 10
+ n = Math.floor(number / 10)
+ if (n && !(++counter % 3))
+ { i = ' ' + i }
+ nums.unshift(i)
+ }
+ while (n);
+
+ return nums.join("")
+}
+function get_age (d){
+}
+function get_size (d){
+}
+function carbon_date (date, no_bold) {
+ var span = (+new Date() - date * 1000);
+ if (! no_bold && span < 86400) // modified today
+ { color = "new"; }
+ else if (span < 604800) // modifed this week
+ { color = "recent"; }
+ else if (span < 1209600) // modifed 2 weeks ago
+ { color = "med"; }
+ else if (span < 3024000) // modifed 5 weeks ago
+ { color = "old"; }
+ else if (span < 12315200) // modifed 6 months ago
+ { color = "older"; }
+ else
+ { color = "quiet"; }
+ return color;
+}
+
+function hushview (n, bias, no_bold) {
+ var txt = commatize(n)
+ bias = bias || 1
+ n = n || 0
+ if (n < 30) {
+ n = 0 if (!n); return["quiet", n + " v."] }
+ if (n < 200) {
+ return ["quiet", txt + " v."] }
+ else if (n < 500) {
+ return ["quiet", txt + " v."] }
+ else if (n < 1000) {
+ return ["old", txt + " v."] }
+ else if (n < 5000) {
+ return ["med", txt + " kv."] }
+ else if (nobold || n < 10000) {
+ return ["recent", txt + " kv."] }
+ else {
+ return ["new", txt + " kv."] }
+}
+
+function hushsize (n, bias, nobold) {
+ var txt = commatize(n / 1024)
+ bias = 1 || bias
+ n = n || 0
+ if (n < 1024) {
+ return ["quiet", "0 b."]
+ }
+ if (n < 1024*1024) {
+ return ["quiet", txt + " kb."]
+ }
+ else if (n < (20000000/bias)) {
+ return ["quiet", txt + " mb."]
+ }
+ else if (n < (50000000/bias)) {
+ return ["old", txt + " mb."]
+ }
+ else if (n < (80000000/bias)) {
+ return ["med", txt + " mb."]
+ }
+ else if (nobold || n < (170000000/bias)) {
+ return ["recent", txt + " mb."]
+ }
+ else {
+ return ["new", txt + " mb."]
+ }
+}