Forum Academy Marketplace Showcase Pricing Features

New Plugin: Relative Time with Moment.js

Did you ever add the diff function?

Hi @JayM , no I didn’t - not enough demand for it and like I stated previously, it’s not really a good fit for this plugin in my opinion. There are now a few other plugins based on moment.js - perhaps one of them includes this function.

1 Like

Hey @louisadekoya,

I just found out (after a whole day tracking down the issue) that your plugin, if placed on the same page, or even a Reusable Element on the same page as the Air Calendar Plugin it breaks it.

Any thoughts about why it would create such a conflict with it?

Trying to load moment twice can cause issues. It’s the backbone library for the plugin plus the calendar plugin you mentioned in the other forum post.

@ZeroqodeSupport couldnt you run a check prior to loading the moment scripts? Assuming that’s the issue. I could be way off base here but I’ve seen this before.

You can check for the existence of the <script>tag in question by selecting all of the <script>elements and checking their src attributes:

//get the number of `<script>` elements that have the correct `src` attribute
var len = $('script').filter(function () {
    return ($(this).attr('src') == '');

//if there are no scripts that match, the load it
if (len === 0) {
    $.getScript('<external JS>');

Check for the script ^^^

If not present, append it!

let myScript = document.createElement("script");
myScript.setAttribute("src", "");

I ran into this issue earlier today

@zavitac and @jared.gibb,

This came up before with one of the chart plugins that was also using moment.js and I ended up adding some code (if (!window.moment) …) to my plugin to only load moment if not already loaded. It seemed to work at the time for the people that had the issue and I assume it still does.

I think the other plugins using moment need to do something similar because if they attempt to load moment after my plugin has already done so, the conflict will occur regardless of what my plugin does.

By the way, @jared.gibb, if I’m not mistaken, your sample code will only match the particular version of moment.js that you’ve stated and won’t catch cases where a different version is used.

For reference, here’s where I found the method I adopted to test for moment.


Good point! I use the same version in Wagons. That’s great source that code from but I had originally grabbed it from stackoverflow.

Nice catch and thanks for the fix!

Ugh this is getting really close to DLL Hell. What happens if another (usually unmaintained) plugin pulls in an incompatible or older version missing key features? This won’t be such a big problem with Moment because it is effectively frozen. However I can see plugins knocking each other out with references to other more actively maintained modules.

1 Like

Hello, @jared.gibb
Thanks for mentioning us in this thread.

We’ve taken into consideration the possibility to improve the Air Calendar Plugin, and especially loading the Moment, for future updates. Thanks for that! :slightly_smiling_face:
Also, thank you for providing additional information regarding the scripts :pray:

We will notify all our users regarding the upgraded version of the plugin, where the mentioned point will be fixed.
Best regards,
Zeroqode Support Team