Skip to content

Instantly share code, notes, and snippets.

@rjcorwin
Created December 27, 2011 03:11
Show Gist options
  • Save rjcorwin/1522618 to your computer and use it in GitHub Desktop.
Save rjcorwin/1522618 to your computer and use it in GitHub Desktop.
Turn lists of images into jCarousels.
$(function() {
var contentArea = '#content-area';
// Look at all unordered lists and label them as allImages if appropriate
$(contentArea + ' ul').each(function(index) {
var list = this;
$(this).children('li').each(function(index) {
// @todo Someone could make this test more bullet proof.
if($(this).html().substr(0, 4) != "<img") {
list.isNotCarousel = true;
}
});
if(list.isNotCarousel == null) {
$(this).wrapAll("<div class='jCarouselLite-" + index + "' />");
$(this).before("<button class='prev-" + index + "'><<</button>");
$(this).after("<button class='next-" + index + "'>>></button>");
// Transform those lists into jCarousels
$(".jCarouselLite-" + index).jCarouselLite({
btnNext: ".next-" + index,
btnPrev: ".prev-" + index
});
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment