summaryrefslogtreecommitdiff
path: root/public/assets/js/util
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2015-09-06 10:40:33 -0400
committerJules Laplace <jules@okfoc.us>2015-09-06 10:40:33 -0400
commitf496fe34ecebd92b7c43b2beface68893adcae97 (patch)
treee09b02c91454541c4fef33bbae56a328a9304534 /public/assets/js/util
parent8e25a37aced0399ad13e2c184c618119ec3da16d (diff)
port several formatting functions from bucky
Diffstat (limited to 'public/assets/js/util')
-rw-r--r--public/assets/js/util/format.js132
1 files changed, 93 insertions, 39 deletions
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 "&middot;"
+ else return "&middot;:"
}
+
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 + "&nbsp;" + 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