diff options
| author | Jules Laplace <jules@okfoc.us> | 2015-09-06 10:40:33 -0400 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2015-09-06 10:40:33 -0400 |
| commit | f496fe34ecebd92b7c43b2beface68893adcae97 (patch) | |
| tree | e09b02c91454541c4fef33bbae56a328a9304534 | |
| parent | 8e25a37aced0399ad13e2c184c618119ec3da16d (diff) | |
port several formatting functions from bucky
| -rw-r--r-- | public/assets/css/bucky.css | 20 | ||||
| -rw-r--r-- | public/assets/js/lib/views/index/hootbox.js | 4 | ||||
| -rw-r--r-- | public/assets/js/lib/views/index/index.js | 4 | ||||
| -rw-r--r-- | public/assets/js/lib/views/index/threadbox.js | 37 | ||||
| -rw-r--r-- | public/assets/js/util/format.js | 132 | ||||
| -rw-r--r-- | views/partials/scripts.ejs | 3 |
6 files changed, 146 insertions, 54 deletions
diff --git a/public/assets/css/bucky.css b/public/assets/css/bucky.css index c73af3d..67521f7 100644 --- a/public/assets/css/bucky.css +++ b/public/assets/css/bucky.css @@ -29,6 +29,9 @@ button { color: #040a0a; background-color: #d8ece0; } +.hidden { + visibility: hidden; +} .head a:link { color: #000;} @@ -60,8 +63,12 @@ hr { border-color: #000; } +#sidebar, #content { + float: left; +} #sidebar { width: 300px; + margin-right: 10px; } #searchbox.bluebox { @@ -114,3 +121,16 @@ hr { } #hoots tr:nth-child(odd) td:nth-child(2) { background-color: #f3f1f2; } #hoots tr:nth-child(even) td:nth-child(2) { background-color: #e3e8e3; } + +.threads td { + text-align: right; +} +.threads td:nth-child(2) { + text-align: left; + font-family: Georgia, serif; + font-size: 120%; +} +.threads tr:nth-child(odd) td:nth-child(2) { +} +.threads tr:nth-child(even) td:nth-child(2) { +}
\ No newline at end of file diff --git a/public/assets/js/lib/views/index/hootbox.js b/public/assets/js/lib/views/index/hootbox.js index 048c017..15de06b 100644 --- a/public/assets/js/lib/views/index/hootbox.js +++ b/public/assets/js/lib/views/index/hootbox.js @@ -1,4 +1,4 @@ -var HootboxView = FormView.extend({ +var HootBox = FormView.extend({ el: "#hootbox", @@ -17,7 +17,7 @@ var HootboxView = FormView.extend({ parse: function(comment){ var t = this.template.replace(/{{username}}/g, comment.username) - .replace(/{{comment}}/g, comment.comment) + .replace(/{{comment}}/g, comment.comment) return t }, diff --git a/public/assets/js/lib/views/index/index.js b/public/assets/js/lib/views/index/index.js index cb648fa..473df38 100644 --- a/public/assets/js/lib/views/index/index.js +++ b/public/assets/js/lib/views/index/index.js @@ -7,7 +7,8 @@ var IndexView = View.extend({ initialize: function(opt){ // opt.parent = parent - this.hootbox = new HootboxView ({ parent: this }) + this.hootbox = new HootBox ({ parent: this }) + this.threadbox = new ThreadBox ({ parent: this }) this.load() }, @@ -17,6 +18,7 @@ var IndexView = View.extend({ populate: function(data){ this.hootbox.load(data.hootbox) + this.threadbox.load(data.threads) }, success: function(){ diff --git a/public/assets/js/lib/views/index/threadbox.js b/public/assets/js/lib/views/index/threadbox.js index 951b025..defeaff 100644 --- a/public/assets/js/lib/views/index/threadbox.js +++ b/public/assets/js/lib/views/index/threadbox.js @@ -17,31 +17,44 @@ var ThreadBox = View.extend({ this.template = this.$(".template").html() }, - load: function(comments){ - comments.forEach(this.appendComment.bind(this)) + load: function(threads){ + threads.forEach(this.appendThread.bind(this)) }, parse: function(thread){ + console.log(thread) + var views = hush_views(thread.viewed) + var size = thread.file_count == 0 ? ["hidden", 0] : 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 t = this.template .replace(/{{id}}/g, thread.id) .replace(/{{username}}/g, thread.username) + .replace(/{{privacy_dot}}/g, dot) .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) ) + .replace(/{{age_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(/{{size_class}}/g, size[0] ) return t }, - prependComment: function(comment){ - var $el = $( this.parse(comment) ) - this.$hoots.prepend($el) + prependThread: function(thread){ + var $row = $( this.parse(thread) ) + this.$el.prepend($row) }, - appendComment: function(comment){ - var $el = $( this.parse(comment) ) - this.$hoots.append($el) + appendThread: function(thread){ + var $row = $( this.parse(thread) ) + this.$el.append($row) }, }) diff --git a/public/assets/js/util/format.js b/public/assets/js/util/format.js index 21b1f68..7c773d4 100644 --- a/public/assets/js/util/format.js +++ b/public/assets/js/util/format.js @@ -1,69 +1,62 @@ function commatize (n) { - var nums, i, counter = 0 + var nums = [], i, counter = 0, r = Math.floor if (n > 1024) { - n /= 1024; - nums.unshift((n * 10) % 10) + n /= 1024 + nums.unshift(r((n * 10) % 10)) nums.unshift(".") } - do { i = n % 10 - n = Math.floor(number / 10) - if (n && !(++counter % 3)) - { i = ' ' + i } - nums.unshift(i) + n = r(n / 10) + if (n && ! (++counter % 3)) + { i = ' ' + r(i) } + nums.unshift(r(i)) } - while (n); - + while (n) return nums.join("") } -function get_age (d){ -} -function get_size (d){ + +function privacy_dot (p) { + if (! p) return "·" + else return "·:" } + function carbon_date (date, no_bold) { - var span = (+new Date() - date * 1000); + var span = (+new Date() - date * 1000) if (! no_bold && span < 86400) // modified today - { color = "new"; } + { color = "new" } else if (span < 604800) // modifed this week - { color = "recent"; } + { color = "recent" } else if (span < 1209600) // modifed 2 weeks ago - { color = "med"; } + { color = "med" } else if (span < 3024000) // modifed 5 weeks ago - { color = "old"; } + { color = "old" } else if (span < 12315200) // modifed 6 months ago - { color = "older"; } + { color = "older" } else - { color = "quiet"; } - return color; + { color = "quiet" } + return color } -function hushview (n, bias, no_bold) { +function hush_views (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."] } + if (n < 30) { 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) +function hush_size (n, bias, nobold) { + var txt = commatize(Math.floor(n / 1024)) bias = 1 || bias n = n || 0 if (n < 1024) { - return ["quiet", "0 b."] + return ["quiet", txt + " b."] } if (n < 1024*1024) { return ["quiet", txt + " kb."] @@ -84,3 +77,64 @@ function hushsize (n, bias, nobold) { return ["new", txt + " mb."] } } + +function hush_null (n, unit, no_bold) { + var s = unit ? n + " " + unit + "." : n + if (n < 3) { + return ["quiet", s] + } + else if (n < 6) { + return ["older", s] + } + else if (n < 10) { + return ["old", s] + } + else if (n < 16) { + return ["med", s] + } + else if (no_bold || n < 21) { + return ["recent", s] + } + else { + return ["new", s] + } +} + +function courtesy_s (n, s) { return v == 1 ? "" : (s || "s") } + +var revision_letters = "z a b c d f g h j k l m n p q r s t v w x y".split(" ") +function get_revision (thread) { + if (! thread.revision) return "" + var rev = thread.revision + var n = 0 + var digits = "" + do { + n = rev % 21 + rev = Math.floor(rev / 21) + digits = revision_letters[n] + digits + } + while (rev !== 0) + return digits +} + +function get_age (t) { + var age = Math.abs( Date.now()/1000 - t) + var r = Math.floor + var m + if (age < 5) { return "now" } + if (age < 60) { return r(age) + "s" } + age /= 60 + if (age < 60) { return r(age) + "m" } + m = r(age % 60) + age /= 60 + if (m > 0 && age < 2) { return m + "m" + r(age) + "h" } + if (age < 24) { return r(age) + "h" } + age /= 24 + if (age < 7) { return r(age) + "d" } + age /= 7 + if (age < 12) { return r(age) + "w" } + age /= 4 + if (age < 12) { return r(age) + "m" } + age /= 12 + return r(age) + "y" +}
\ No newline at end of file diff --git a/views/partials/scripts.ejs b/views/partials/scripts.ejs index 297f198..fa03f2b 100644 --- a/views/partials/scripts.ejs +++ b/views/partials/scripts.ejs @@ -10,10 +10,13 @@ <script src="/assets/js/lib/router.js"></script> +<script src="/assets/js/util/format.js"></script> + <script src="/assets/js/lib/views/login/login.js"></script> <script src="/assets/js/lib/views/index/index.js"></script> <script src="/assets/js/lib/views/index/hootbox.js"></script> +<script src="/assets/js/lib/views/index/threadbox.js"></script> <script src="/assets/js/index.js"></script> |
