info@54
|
1 |
$(function () {
|
info@54
|
2 |
|
info@54
|
3 |
module("carousel")
|
info@54
|
4 |
|
info@54
|
5 |
test("should provide no conflict", function () {
|
info@54
|
6 |
var carousel = $.fn.carousel.noConflict()
|
info@54
|
7 |
ok(!$.fn.carousel, 'carousel was set back to undefined (org value)')
|
info@54
|
8 |
$.fn.carousel = carousel
|
info@54
|
9 |
})
|
info@54
|
10 |
|
info@54
|
11 |
test("should be defined on jquery object", function () {
|
info@54
|
12 |
ok($(document.body).carousel, 'carousel method is defined')
|
info@54
|
13 |
})
|
info@54
|
14 |
|
info@54
|
15 |
test("should return element", function () {
|
info@54
|
16 |
ok($(document.body).carousel()[0] == document.body, 'document.body returned')
|
info@54
|
17 |
})
|
info@54
|
18 |
|
info@54
|
19 |
test("should not fire sliden when slide is prevented", function () {
|
info@54
|
20 |
$.support.transition = false
|
info@54
|
21 |
stop()
|
info@54
|
22 |
$('<div class="carousel"/>')
|
info@54
|
23 |
.on('slide.bs.carousel', function (e) {
|
info@54
|
24 |
e.preventDefault();
|
info@54
|
25 |
ok(true);
|
info@54
|
26 |
start();
|
info@54
|
27 |
})
|
info@54
|
28 |
.on('slid.bs.carousel', function () {
|
info@54
|
29 |
ok(false);
|
info@54
|
30 |
})
|
info@54
|
31 |
.carousel('next')
|
info@54
|
32 |
})
|
info@54
|
33 |
|
info@54
|
34 |
test("should fire slide event with direction", function () {
|
info@54
|
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">‹</a><a class="right carousel-control" href="#myCarousel" data-slide="next">›</a></div>'
|
info@54
|
36 |
$.support.transition = false
|
info@54
|
37 |
stop()
|
info@54
|
38 |
$(template).on('slide.bs.carousel', function (e) {
|
info@54
|
39 |
e.preventDefault()
|
info@54
|
40 |
ok(e.direction)
|
info@54
|
41 |
ok(e.direction === 'right' || e.direction === 'left')
|
info@54
|
42 |
start()
|
info@54
|
43 |
}).carousel('next')
|
info@54
|
44 |
})
|
info@54
|
45 |
|
info@54
|
46 |
test("should fire slide event with relatedTarget", function () {
|
info@54
|
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">‹</a><a class="right carousel-control" href="#myCarousel" data-slide="next">›</a></div>'
|
info@54
|
48 |
$.support.transition = false
|
info@54
|
49 |
stop()
|
info@54
|
50 |
$(template)
|
info@54
|
51 |
.on('slide.bs.carousel', function (e) {
|
info@54
|
52 |
e.preventDefault();
|
info@54
|
53 |
ok(e.relatedTarget);
|
info@54
|
54 |
ok($(e.relatedTarget).hasClass('item'));
|
info@54
|
55 |
start();
|
info@54
|
56 |
})
|
info@54
|
57 |
.carousel('next')
|
info@54
|
58 |
})
|
info@54
|
59 |
|
info@54
|
60 |
test("should set interval from data attribute", 4, function () {
|
info@54
|
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">‹</a> <a class="right carousel-control" href="#myCarousel" data-slide="next">›</a> </div>');
|
info@54
|
62 |
template.attr("data-interval", 1814);
|
info@54
|
63 |
|
info@54
|
64 |
template.appendTo("body");
|
info@54
|
65 |
$('[data-slide]').first().click();
|
info@54
|
66 |
ok($('#myCarousel').data('bs.carousel').options.interval == 1814);
|
info@54
|
67 |
$('#myCarousel').remove();
|
info@54
|
68 |
|
info@54
|
69 |
template.appendTo("body").attr("data-modal", "foobar");
|
info@54
|
70 |
$('[data-slide]').first().click();
|
info@54
|
71 |
ok($('#myCarousel').data('bs.carousel').options.interval == 1814, "even if there is an data-modal attribute set");
|
info@54
|
72 |
$('#myCarousel').remove();
|
info@54
|
73 |
|
info@54
|
74 |
template.appendTo("body");
|
info@54
|
75 |
$('[data-slide]').first().click();
|
info@54
|
76 |
$('#myCarousel').attr('data-interval', 1860);
|
info@54
|
77 |
$('[data-slide]').first().click();
|
info@54
|
78 |
ok($('#myCarousel').data('bs.carousel').options.interval == 1814, "attributes should be read only on intitialization");
|
info@54
|
79 |
$('#myCarousel').remove();
|
info@54
|
80 |
|
info@54
|
81 |
template.attr("data-interval", false);
|
info@54
|
82 |
template.appendTo("body");
|
info@54
|
83 |
$('#myCarousel').carousel(1);
|
info@54
|
84 |
ok($('#myCarousel').data('bs.carousel').options.interval === false, "data attribute has higher priority than default options");
|
info@54
|
85 |
$('#myCarousel').remove();
|
info@54
|
86 |
})
|
info@54
|
87 |
})
|