• Resolved Alex Kladov

    (@prowebassist)


    Hi,

    I have a problem with your plugin, where it’s throwing Uncaught TypeError: $(...).stickThis is not a function.

    I have skimmed through the support threads and you suggest that it’s a jQuery duplication issue. Which is not the case in my scenario, I am definitely loading 1 instance of the latest stable jQuery release v3.5.1 (maybe that’s the problem? cos WP loads a very outdated jQuery by default, which I have disabled due to security concerns).

    So it has to be something else..

    Just to let you know, everything on my website is minified & combined, some things are also deferred. Except for jQuery – it loads independently, without any delay or deferral.

    And every other plugin is happy with that setup. So not sure what’s going on here.

    Is there a simple solution to this?

    On a related note, I was wondering if you could add a new option to your plugin’s Advanced tab, where a user could specify a custom JS Event trigger for stickThis function?

    For example, on my site I’ve created my own custom on “ready” event, which simply uses vanilla JS to wait, until jQuery is actually loaded/ready and then triggers my custom “actuallyReady” event.

    So all of my custom independent scripts are triggered by that event. So, for example, instead of the typical:

    
    (function($, document) {
      $(document).ready(function($) {});
    })(jQuery);
    

    I call this instead:

    
    (function($, document) {
      $(document).on('actuallyReady', function() {});
    })(jQuery);
    

    It’s really handy, because my “actuallyReady” does some other logic sometimes, like wait for Oxygen Builder or Divi Builder to finish loading, if I am on a builder page (or not trigger the event at all, if I am on a page, which will break if JS is instantiated).

    So it could be very useful for advanced users to have the ability to trigger your stickThis using a custom JS Event. And in this case, it will also prevent the race condition for jQuery, where stickThis clearly doesn’t wait long enough, before launching itself and then complains that jQuery is not ready yet.

    Regards,
    Alex

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter Alex Kladov

    (@prowebassist)

    Also, I am pretty sure I found a few minor errors in your JS scripts. Not sure how important they are or if they even have an impact on anything..

    But here they are.

    stickThis.js should be wrapped with:

    (function($, document) {
    })(jQuery, document);
    

    instead of this:

    (function($) {
    }(jQuery));
    

    jq-sticky-anything.js should be wrapped with:

    (function($, window, document) {
    })(jQuery, window, document);
    

    instead of this:

    (function($) {
    }(jQuery));
    

    Most important change is using })(jQuery);, instead of }(jQuery)); at the end of each file. It might be causing a problem, since you are not passing jQuery as $ variable to the function properly, because of incorrect position of the closing brackets. Maybe that’s why it’s complaining about jQuery not existing in a lot of cases.

    Cheers,
    Alex

    • This reply was modified 4 years, 9 months ago by Alex Kladov.

    @prowebassist If You do that on your side, does it solve the issue? For me it seems more that the system cannot find the element that You specify to stick…

    Thread Starter Alex Kladov

    (@prowebassist)

    @manuelrocha88 I haven’t tried it, to be honest. I will, once I’ll have some free time and will get back to you on that.

    You are right though, it’s possible that those small JS changes won’t make any difference. I just found it to be a strange/non-standard way of enclosing jQuery in a wrapper function. Not sure if there are any consequences to doing it your way.

    As for not having elements, that is true as well. I only have sticky element on 2 pages. But even on pages, where we have a sticky element, stickThis doesn’t work.

    Also, related to the above situation, how can I dequeue your JS/CSS everywhere on the site, except for a select # of pages (or the other way around – only enqueue it on X pages)? Is there a developer hook I can tap into?

    Regards,
    Alex

    @prowebassist we don’t have a developer hook for that but you can make use of wp_dequeue_script and dequeue de stickyAnythingLib and stickThis scripts.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘stickThis is not a function’ is closed to new replies.