Sha256: 0233665e772eeccf64b459cfebff1665822dc9b30edcdcde8ac4cc9003d670ed

Contents?: true

Size: 1.06 KB

Versions: 7

Compression:

Stored size: 1.06 KB

Contents

/*global timeago, gts*/
this.gts = this.gts || {};

/**
 * Replace content of <abbr> elements with a casual representation of the
 * ISO8601 date in its title attribute.
 */
this.gts.timeago = (function (ta) {
    function timeago(el, time) {
        var date = ta.parse(time || el.title);
        if (isNaN(date.getTime())) { return el; }
        var text = el.innerHTML.trim() || el.title;
        el.innerHTML = ta.relative(date);
        el.title = text;
        return el;
    };

    var cache = {};

    timeago.periodic = function (timeout) {
        if (!cache[timeout]) {
            cache[timeout] = [];
            setInterval(function () {
                for (var i = 0, l = cache[timeout].length, item; i < l; ++i) {
                    item = cache[timeout][i];
                    gts.timeago(item.element, item.time);
                }
            }, timeout);
        }

        return function (el) {
            cache[timeout].push({ element: el, time: el.title });
            return timeago(el, el.title);
        };
    };

    return timeago;
}(timeago));

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
dolt-0.29.0 vendor/ui/js/src/components/timeago.js
dolt-0.28.1 vendor/ui/js/src/components/timeago.js
dolt-0.28.0 vendor/ui/js/src/components/timeago.js
dolt-0.27.0 vendor/ui/js/src/components/timeago.js
dolt-0.26.0 vendor/ui/js/src/components/timeago.js
dolt-0.25.0 vendor/ui/js/src/components/timeago.js
dolt-0.24.0 vendor/ui/js/src/components/timeago.js