Skip to content
Snippets Groups Projects
plugin.js 1.07 KiB
Newer Older
William Warriner's avatar
William Warriner committed
window.rStackFix = function () {
  return {
    id: "rStackFix",
    init: function (deck) {
      console.log("Custom plugin initialized!");
      // Automatically load the initial fragment on a slide if the fragment
      // has been defined with the 'preload' class
      deck.on("slidechanged", function (event) {
        console.log("slidechanged");
        if (
          event.currentSlide.querySelectorAll(
            '.preload[data-fragment-index="0"]'
          ).length > 0
        ) {
          deck.nextFragment();
        }
      });

      // If the initial fragment on a slide has been defined with a 'preload' class
      // then transition to the previous slide if the fragment is hidden
      deck.on("fragmenthidden", function (event) {
        console.log("fragmenthidden");
        if (
          event.fragment.hasAttribute("data-fragment-index") &&
          event.fragment.classList.contains("preload")
        ) {
          if (event.fragment.attributes["data-fragment-index"].value == "0") {
            deck.prev();
          }
        }
      });
    },
  };
};