$(function () { 'use strict'; module('carousel plugin') test('should be defined on jQuery object', function () { ok($(document.body).carousel, 'carousel method is defined') }) module('carousel', { setup: function () { // Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode $.fn.bootstrapCarousel = $.fn.carousel.noConflict() }, teardown: function () { $.fn.carousel = $.fn.bootstrapCarousel delete $.fn.bootstrapCarousel } }) test('should provide no conflict', function () { ok(!$.fn.carousel, 'carousel was set back to undefined (orig value)') }) test('should return element', function () { ok($(document.body).bootstrapCarousel()[0] == document.body, 'document.body returned') }) test('should not fire slide when slide is prevented', function () { $.support.transition = false stop() $('
') .on('slide.bs.carousel', function (e) { e.preventDefault() ok(true) start() }) .on('slid.bs.carousel', function () { ok(false) }) .bootstrapCarousel('next') }) test('should reset when slide is prevented', function () { var template = ' ' var $carousel = $(template) $.support.transition = false stop() $carousel.one('slide.bs.carousel', function (e) { e.preventDefault() setTimeout(function () { ok($carousel.find('.item:eq(0)').is('.active')) ok($carousel.find('.carousel-indicators li:eq(0)').is('.active')) $carousel.bootstrapCarousel('next') }, 1) }) $carousel.one('slid.bs.carousel', function () { setTimeout(function () { ok($carousel.find('.item:eq(1)').is('.active')) ok($carousel.find('.carousel-indicators li:eq(1)').is('.active')) start() }, 1) }) $carousel.bootstrapCarousel('next') }) test('should fire slide event with direction', function () { var template = ' ' $.support.transition = false stop() $(template).on('slide.bs.carousel', function (e) { e.preventDefault() ok(e.direction) ok(e.direction === 'right' || e.direction === 'left') start() }).bootstrapCarousel('next') }) test('should fire slid event with direction', function () { var template = ' ' $.support.transition = false stop() $(template).on('slid.bs.carousel', function (e) { e.preventDefault() ok(e.direction) ok(e.direction === 'right' || e.direction === 'left') start() }).bootstrapCarousel('next') }) test('should fire slide event with relatedTarget', function () { var template = ' ' $.support.transition = false stop() $(template) .on('slide.bs.carousel', function (e) { e.preventDefault() ok(e.relatedTarget) ok($(e.relatedTarget).hasClass('item')) start() }) .bootstrapCarousel('next') }) test('should fire slid event with relatedTarget', function () { var template = ' ' $.support.transition = false stop() $(template) .on('slid.bs.carousel', function (e) { e.preventDefault() ok(e.relatedTarget) ok($(e.relatedTarget).hasClass('item')) start() }) .bootstrapCarousel('next') }) test('should set interval from data attribute', 4, function () { var template = $(' ') template.attr('data-interval', 1814) template.appendTo('body') $('[data-slide]').first().click() ok($('#myCarousel').data('bs.carousel').options.interval == 1814) $('#myCarousel').remove() template.appendTo('body').attr('data-modal', 'foobar') $('[data-slide]').first().click() ok($('#myCarousel').data('bs.carousel').options.interval == 1814, 'even if there is an data-modal attribute set') $('#myCarousel').remove() template.appendTo('body') $('[data-slide]').first().click() $('#myCarousel').attr('data-interval', 1860) $('[data-slide]').first().click() ok($('#myCarousel').data('bs.carousel').options.interval == 1814, 'attributes should be read only on initialization') $('#myCarousel').remove() template.attr('data-interval', false) template.appendTo('body') $('#myCarousel').bootstrapCarousel(1) ok($('#myCarousel').data('bs.carousel').options.interval === false, 'data attribute has higher priority than default options') $('#myCarousel').remove() }) test('should skip over non-items', function () { $.support.transition = false var $template = $( '