Created
March 27, 2015 17:42
-
-
Save dschnare/5cdb63bb3baa0767866c to your computer and use it in GitHub Desktop.
Adds nesting support to Twitter Bootstrap carousels.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Augment the Bootstrap Carousel jQuery plugin so that .item.active | |
// queries use a direct descendent selector to find the active item. | |
// With this patch you can now arbitrarily nest carousels inside | |
// the .item elements of other carousels. | |
$.fn.carousel = (function (carousel) { | |
return function () { | |
var $carousel = carousel.apply(this, arguments); | |
var c = $carousel.data("bs.carousel"); | |
if (!c.$element.find.__overridden) { | |
// If the plugin changes from using $element.find(".item.active") | |
// to find active items then we will have to update this code. | |
c.$element.find = (function (find) { | |
var f = function (selector) { | |
if (selector === ".item.active") { | |
selector = "> .carousel-inner > " + selector; | |
} | |
return find.call(this, selector); | |
}; | |
// Flag to indicate that we've overridden the find() method. | |
f.__overridden = true; | |
return f; | |
} (c.$element.find)); | |
} | |
return $carousel; | |
}; | |
} ($.fn.carousel)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment