0

I would like to extend the pause function in slick. https://github.com/kenwheeler/slick/blob/master/slick/slick.js#L1590

Here is what I have so far, but I am unable to access the pause function with $.fn.slick.prototype.pause;

(function ($) {
  var _original = $.fn.slick.prototype.pause;

  function trigger(target, name, relatedTarget) {
    target.trigger($.Event(name, { relatedTarget: relatedTarget }));
  }

  $.extend($.fn.slick.Constructor.prototype, {
    pause: function () {
      console.log("bleh")
    }
  });
})(jQuery);

Anyway I could do this?

Steven
  • 817
  • 1
  • 8
  • 25

1 Answers1

1

If you look at the end of the source code, you'll see that the JQuery exposed function isn't actually the Slick object, but a function using it.

As far as my understanding of this goes, I'd say what you want to extend is enclosed in an inaccessible closure, which renders answers such as this one unfeasible.

Community
  • 1
  • 1
Antoine Combes
  • 1,444
  • 8
  • 13
  • arg, okay thanks! Any reasons plugins do this? I get they want to protect their plugin, but let me do what I want with it...like bootstrap lets us mess with it. – Steven Oct 26 '16 at 15:23
  • I wouldn't be so bold as to presume of the reason that led them to design their plugin this way :) You could always try asking the creator yourself: https://github.com/kenwheeler. If you end up getting a solution to your problem, you could post it as the accepted answer here. – Antoine Combes Oct 26 '16 at 15:25
  • Can you explain a bit more the jQuery exposed function? I don't quite understand how to detect a plugin that let's us extend it. – Steven Oct 26 '16 at 15:28
  • 1
    At the very end of the source script, you'll see that `$.fn.slick` is defined, and that it is using the `Slick` prototype previously defined. This is why you won't have anything inside the `$.fn.slick` prototype. – Antoine Combes Oct 26 '16 at 15:31
  • got it, that's why right here in bootstrap it gives us acces to it with this line $.fn.alert.Constructor = Alert Thank you very much – Steven Oct 26 '16 at 15:34
  • You might be able to listen to the init and reInit events and accomplish something similar to your objective (find out if the carousel is paused) by saving the instance somewhere. Both of those pass the slick instance to the event listener and the paused and interrupted Booleans are both accessible. https://github.com/kenwheeler/slick#events Edit: Add link to docs. – Chris Ruskai Mar 25 '22 at 16:08