malsup / cycle2

2nd gen cycling
899 stars 237 forks source link

No event after a transition's postInit #801

Closed helderco closed 2 years ago

helderco commented 7 years ago

There's no event after a transition's postInit function. The carousel transition appends and prepends extra elements with cloneNode, in postInit. The problem is that it's not cloning a custom .data('colorbox') config object.

    postInitSlideshow: function() {
        var opts = this.opts();
        opts.API.trigger('cycle-post-initialize', [ opts ]);
        var tx = $.fn.cycle.transitions[opts.fx];
        if (tx && $.isFunction(tx.postInit))
            tx.postInit( opts );
    },

Maybe just add this?

    postInitSlideshow: function() {
        var opts = this.opts();
        opts.API.trigger('cycle-post-initialize', [ opts ]);
        var tx = $.fn.cycle.transitions[opts.fx];
        if (tx && $.isFunction(tx.postInit)) {
            tx.postInit( opts );
            opts.API.trigger('cycle-tx-post-initialize', [opts]);
        }
    },

You can then check with opts.fx which transition it is.

For now, I've added this in custom code:

  $.fn.cycle.transitions.carousel.oldPostInit = $.fn.cycle.transitions.carousel.postInit;
  $.fn.cycle.transitions.carousel.postInit = function (opts) {
    this.oldPostInit(opts);
    opts.container.trigger('cycle-carousel-post-initialize', [opts]);
  };