bootstrap-source/bootstrap-3.0.3/js/tests/unit/carousel.js
changeset 115 a9d04f5f5650
parent 54 0ded9d7748b7
equal deleted inserted replaced
114:6093dda9fe38 115:a9d04f5f5650
     1 $(function () {
       
     2 
       
     3     module("carousel")
       
     4 
       
     5       test("should provide no conflict", function () {
       
     6         var carousel = $.fn.carousel.noConflict()
       
     7         ok(!$.fn.carousel, 'carousel was set back to undefined (org value)')
       
     8         $.fn.carousel = carousel
       
     9       })
       
    10 
       
    11       test("should be defined on jquery object", function () {
       
    12         ok($(document.body).carousel, 'carousel method is defined')
       
    13       })
       
    14 
       
    15       test("should return element", function () {
       
    16         ok($(document.body).carousel()[0] == document.body, 'document.body returned')
       
    17       })
       
    18 
       
    19       test("should not fire sliden when slide is prevented", function () {
       
    20         $.support.transition = false
       
    21         stop()
       
    22         $('<div class="carousel"/>')
       
    23           .on('slide.bs.carousel', function (e) {
       
    24             e.preventDefault();
       
    25             ok(true);
       
    26             start();
       
    27           })
       
    28           .on('slid.bs.carousel', function () {
       
    29             ok(false);
       
    30           })
       
    31           .carousel('next')
       
    32       })
       
    33 
       
    34       test("should fire slide event with direction", function () {
       
    35         var template = '<div id="myCarousel" class="carousel slide"><div class="carousel-inner"><div class="item active"><img alt=""><div class="carousel-caption"><h4>{{_i}}First Thumbnail label{{/i}}</h4><p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p></div></div><div class="item"><img alt=""><div class="carousel-caption"><h4>{{_i}}Second Thumbnail label{{/i}}</h4><p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p></div></div><div class="item"><img alt=""><div class="carousel-caption"><h4>{{_i}}Third Thumbnail label{{/i}}</h4><p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p></div></div></div><a class="left carousel-control" href="#myCarousel" data-slide="prev">&lsaquo;</a><a class="right carousel-control" href="#myCarousel" data-slide="next">&rsaquo;</a></div>'
       
    36         $.support.transition = false
       
    37         stop()
       
    38         $(template).on('slide.bs.carousel', function (e) {
       
    39           e.preventDefault()
       
    40           ok(e.direction)
       
    41           ok(e.direction === 'right' || e.direction === 'left')
       
    42           start()
       
    43         }).carousel('next')
       
    44       })
       
    45 
       
    46       test("should fire slide event with relatedTarget", function () {
       
    47         var template = '<div id="myCarousel" class="carousel slide"><div class="carousel-inner"><div class="item active"><img alt=""><div class="carousel-caption"><h4>{{_i}}First Thumbnail label{{/i}}</h4><p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p></div></div><div class="item"><img alt=""><div class="carousel-caption"><h4>{{_i}}Second Thumbnail label{{/i}}</h4><p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p></div></div><div class="item"><img alt=""><div class="carousel-caption"><h4>{{_i}}Third Thumbnail label{{/i}}</h4><p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p></div></div></div><a class="left carousel-control" href="#myCarousel" data-slide="prev">&lsaquo;</a><a class="right carousel-control" href="#myCarousel" data-slide="next">&rsaquo;</a></div>'
       
    48         $.support.transition = false
       
    49         stop()
       
    50         $(template)
       
    51           .on('slide.bs.carousel', function (e) {
       
    52             e.preventDefault();
       
    53             ok(e.relatedTarget);
       
    54             ok($(e.relatedTarget).hasClass('item'));
       
    55             start();
       
    56           })
       
    57           .carousel('next')
       
    58       })
       
    59 
       
    60       test("should set interval from data attribute", 4, function () {
       
    61         var template = $('<div id="myCarousel" class="carousel slide"> <div class="carousel-inner"> <div class="item active"> <img alt=""> <div class="carousel-caption"> <h4>{{_i}}First Thumbnail label{{/i}}</h4> <p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p> </div> </div> <div class="item"> <img alt=""> <div class="carousel-caption"> <h4>{{_i}}Second Thumbnail label{{/i}}</h4> <p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p> </div> </div> <div class="item"> <img alt=""> <div class="carousel-caption"> <h4>{{_i}}Third Thumbnail label{{/i}}</h4> <p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p> </div> </div> </div> <a class="left carousel-control" href="#myCarousel" data-slide="prev">&lsaquo;</a> <a class="right carousel-control" href="#myCarousel" data-slide="next">&rsaquo;</a> </div>');
       
    62         template.attr("data-interval", 1814);
       
    63 
       
    64         template.appendTo("body");
       
    65         $('[data-slide]').first().click();
       
    66         ok($('#myCarousel').data('bs.carousel').options.interval == 1814);
       
    67         $('#myCarousel').remove();
       
    68 
       
    69         template.appendTo("body").attr("data-modal", "foobar");
       
    70         $('[data-slide]').first().click();
       
    71         ok($('#myCarousel').data('bs.carousel').options.interval == 1814, "even if there is an data-modal attribute set");
       
    72         $('#myCarousel').remove();
       
    73 
       
    74         template.appendTo("body");
       
    75         $('[data-slide]').first().click();
       
    76         $('#myCarousel').attr('data-interval', 1860);
       
    77         $('[data-slide]').first().click();
       
    78         ok($('#myCarousel').data('bs.carousel').options.interval == 1814, "attributes should be read only on intitialization");
       
    79         $('#myCarousel').remove();
       
    80 
       
    81         template.attr("data-interval", false);
       
    82         template.appendTo("body");
       
    83         $('#myCarousel').carousel(1);
       
    84         ok($('#myCarousel').data('bs.carousel').options.interval === false, "data attribute has higher priority than default options");
       
    85         $('#myCarousel').remove();
       
    86       })
       
    87 })
       
Impressum Datenschutzerklärung