Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery TimeAgo plugin - Set Settings

I'm trying to "tweek" the TimeAgo plugin so that I can remove the suffix "ago" on a case by case basis.

Here's what I've tried

$("time.timeago-nosuffix").timeago({suffixAgo: ""});

and

$("time.timeago-nosuffix").timeago({ settings: { strings: { suffixAgo: null}} });

as well as

$(document).ready(function () {
    $("time.timeago").timeago();
    $("time.timeago-nosuffix").timeago(function () {
        suffixAgo: "" 
    });
});

with out any luck.

like image 483
Chase Florell Avatar asked Dec 21 '22 21:12

Chase Florell


1 Answers

Disclaimer: I'm the author of timeago.

Unfortunately, as PetersenDidIt pointed out, timeago doesn't currently support runtime options. There's been an open issue on GitHub to address this, but I haven't had the time to look into it. PetersenDidIt, Thanks for the pull-request. I'll take a look as soon as I can.

Meanwhile, here's one of several possible workarounds...

First, set the suffix to an empty string by default:

$.timeago.settings.strings.suffixAgo = "";

Next, run timeago like you normally would:

$("time.timeago").timeago()

Lastly, instead of adding a "nosuffix" qualifier, add a class to each timestamp for which you want a suffix and add the suffix to all of those timestamps once:

$("time.timeago.suffix").after(" ago")
like image 75
Ryan McGeary Avatar answered Jan 03 '23 10:01

Ryan McGeary