diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2018-05-31 23:15:32 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2018-05-31 23:15:32 +0200 |
| commit | dd31a7b9a3af167808b04ffe2af3a66af8b17c33 (patch) | |
| tree | d99bc1be5d382d330a844a1c7bcb7b3fb44eda3e /public/bundle.js | |
| parent | fe399143527972050534b3262c94dfbf291ddb41 (diff) | |
nice size functions from bucky :)
Diffstat (limited to 'public/bundle.js')
| -rw-r--r-- | public/bundle.js | 212 |
1 files changed, 168 insertions, 44 deletions
diff --git a/public/bundle.js b/public/bundle.js index 0ad4bf3..c3fcabb 100644 --- a/public/bundle.js +++ b/public/bundle.js @@ -391,7 +391,7 @@ exports.actions = exports.parser = exports.util = undefined; var _crud = __webpack_require__(/*! ./crud.actions */ "./app/client/api/crud.actions.js"); -var _util = __webpack_require__(/*! ./util */ "./app/client/api/util.js"); +var _util = __webpack_require__(/*! ../util */ "./app/client/util.js"); var util = _interopRequireWildcard(_util); @@ -781,39 +781,6 @@ function parseTumblrPost(media_list, post) { /***/ }), -/***/ "./app/client/api/util.js": -/*!********************************!*\ - !*** ./app/client/api/util.js ***! - \********************************/ -/*! no static exports found */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - - -Object.defineProperty(exports, "__esModule", { - value: true -}); -var is_iphone = exports.is_iphone = !!(navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPod/i)); -var is_ipad = exports.is_ipad = !!navigator.userAgent.match(/iPad/i); -var is_android = exports.is_android = !!navigator.userAgent.match(/Android/i); -var is_mobile = exports.is_mobile = is_iphone || is_ipad || is_android; -var is_desktop = exports.is_desktop = !is_mobile; - -var htmlClassList = document.body.parentNode.classList; -htmlClassList.add(is_desktop ? 'desktop' : 'mobile'); -htmlClassList.remove('loading'); - -// window.debug = false - -function randint(n) { - return Math.floor(Math.random() * n); -} - -document.body.style.backgroundImage = 'linear-gradient(' + (randint(40) + 40) + 'deg, #fde, #ffe)'; - -/***/ }), - /***/ "./app/client/common/button.component.js": /*!***********************************************!*\ !*** ./app/client/common/button.component.js ***! @@ -948,6 +915,8 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } +var defaultFields = new Set(['date', 'size']); + var FileList = function (_Component) { _inherits(FileList, _Component); @@ -967,7 +936,9 @@ var FileList = function (_Component) { linkFiles = _props.linkFiles, _onClick = _props.onClick; + var fields = this.props.fields || defaultFields; var fileList = files.map(function (file) { + var size = util.hush_size(file.size); return (0, _preact.h)( 'div', { 'class': 'row file', key: file.name }, @@ -986,27 +957,31 @@ var FileList = function (_Component) { file.name || file.url ) ), - (0, _preact.h)( + fields.has('date') && (0, _preact.h)( + 'div', + { className: "date " + util.carbon_date(file.created_at) }, + (0, _moment2.default)(file.created_at).format("YYYY-MM-DD") + ), + fields.has('datetime') && (0, _preact.h)( 'div', - { className: 'date' }, + { className: "datetime " + util.carbon_date(file.created_at) }, (0, _moment2.default)(file.created_at).format("YYYY-MM-DD h:mm a") ), - (0, _preact.h)( + fields.has('size') && (0, _preact.h)( 'div', - { className: 'size' }, - file.size ? (file.size / 1024 / 1024).toFixed(1) + ' mb.' : '' + { className: "size " + size[0] }, + size[1] ), - (0, _preact.h)( + fields.has('epoch') && (0, _preact.h)( 'div', { className: 'epoch' }, file.epoch > 0 ? 'epoch ' + file.epoch : ' ' ), - (0, _preact.h)( + (fields.has('activity') || fields.has('module')) && (0, _preact.h)( 'div', { className: 'activity' }, - file.activity || '', - ' ', - file.module || '' + fields.has('activity') && file.activity, + fields.has('module') && file.module ), _this2.props.options && _this2.props.options(file) ); @@ -5948,12 +5923,161 @@ Object.defineProperty(exports, "__esModule", { }); exports.timeInSeconds = timeInSeconds; exports.gerund = gerund; +exports.commatize = commatize; +exports.carbon_date = carbon_date; +exports.hush_views = hush_views; +exports.hush_threads = hush_threads; +exports.hush_size = hush_size; +exports.hush_null = hush_null; +exports.courtesy_s = courtesy_s; +var is_iphone = exports.is_iphone = !!(navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPod/i)); +var is_ipad = exports.is_ipad = !!navigator.userAgent.match(/iPad/i); +var is_android = exports.is_android = !!navigator.userAgent.match(/Android/i); +var is_mobile = exports.is_mobile = is_iphone || is_ipad || is_android; +var is_desktop = exports.is_desktop = !is_mobile; + +var htmlClassList = document.body.parentNode.classList; +htmlClassList.add(is_desktop ? 'desktop' : 'mobile'); +htmlClassList.remove('loading'); + +// window.debug = false + +function randint(n) { + return Math.floor(Math.random() * n); +} + +document.body.style.backgroundImage = 'linear-gradient(' + (randint(40) + 40) + 'deg, #fde, #ffe)'; + function timeInSeconds(n) { return (n / 10).toFixed(1) + ' s.'; } function gerund(s) { return s.replace(/e?$/, 'ing'); } +function commatize(n, radix) { + radix = radix || 1024; + var nums = [], + i, + counter = 0, + r = Math.floor; + if (n > radix) { + n /= radix; + nums.unshift(r(n * 10 % 10)); + nums.unshift("."); + } + do { + i = n % 10; + n = r(n / 10); + if (n && !(++counter % 3)) { + i = ' ' + r(i); + } + nums.unshift(r(i)); + } while (n); + return nums.join(""); +} +function carbon_date(date, no_bold) { + var span = (+new Date() - new Date(date)) / 1000, + color; + 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 hush_views(n, bias, no_bold) { + var txt = commatize(n, 1000); + bias = bias || 1; + n = n || 0; + 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 (no_bold || n < 10000) { + return ["recent", txt + " kv."]; + } else { + return ["new", txt + " kv."]; + } +} +function hush_threads(n, bias, no_bold) { + var txt = commatize(n, 1000); + bias = bias || 1; + n = n || 0; + if (n < 10) { + return ["quiet", n + " t."]; + } else if (n < 25) { + return ["old", txt + " t."]; + } else if (n < 50) { + return ["med", txt + " t."]; + } else if (no_bold || n < 100) { + return ["recent", txt + " t."]; + } else { + return ["new", txt + " t."]; + } +} +function hush_size(n, bias, no_bold) { + var txt = commatize(Math.floor(n / 1024)); + bias = 1 || bias; + n = n || 0; + if (!n) { + return ['', '']; + } + if (n < 1024) { + return ["quiet", n + " 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 (no_bold || n < 170000000 / bias) { + return ["recent", txt + " mb."]; + } else { + 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 n == 1 ? "" : s || "s"; +} /***/ }), |
