Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow automatic swapping in of img src from data-src when needed. #329

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions jquery.cycle2.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,20 @@ $.fn.cycle.API = {
}
return tx;
},

swapInDataSrc: function (opts, slideIndex) {
if (slideIndex < opts.slides.length) {
var $slideImg = $($(opts.slides[slideIndex]).find("img")[0]);

if ($slideImg) {
var dataSrc = $slideImg.data("src");
if (dataSrc) {
$slideImg.attr("src", dataSrc);
$slideImg.data("src", null); // don't swap it again
}
}
}
},

prepareTx: function( manual, fwd ) {
var opts = this.opts();
Expand Down Expand Up @@ -330,6 +344,8 @@ $.fn.cycle.API = {
if ( tx.before )
tx.before( slideOpts, curr, next, fwd );

opts.API.swapInDataSrc(slideOpts, slideOpts.nextSlide); // ensure the current slide is present

after = function() {
opts.busy = false;
// #76; bail if slideshow has been destroyed
Expand All @@ -338,6 +354,9 @@ $.fn.cycle.API = {

if (tx.after)
tx.after( slideOpts, curr, next, fwd );

opts.API.swapInDataSrc(slideOpts, slideOpts.nextSlide); // ensure the next slide is present

opts.API.trigger('cycle-after', [ slideOpts, curr, next, fwd ]);
opts.API.queueTransition( slideOpts);
opts.API.updateView( true );
Expand Down