Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
bootstrap
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
bootstrap
Commits
f026cfb8
Commit
f026cfb8
authored
Jul 31, 2014
by
Chris Rebert
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #14069 from twbs/fix-13818
Use more robust "find next carousel item" logic
parents
d38fd028
cbba8e53
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
3 deletions
+35
-3
js/carousel.js
js/carousel.js
+9
-2
js/tests/unit/carousel.js
js/tests/unit/carousel.js
+26
-1
No files found.
js/carousel.js
View file @
f026cfb8
...
@@ -63,6 +63,13 @@
...
@@ -63,6 +63,13 @@
return
this
.
$items
.
index
(
item
||
this
.
$active
)
return
this
.
$items
.
index
(
item
||
this
.
$active
)
}
}
Carousel
.
prototype
.
getItemForDirection
=
function
(
direction
,
active
)
{
var
delta
=
direction
==
'
prev
'
?
-
1
:
1
var
activeIndex
=
this
.
getItemIndex
(
active
)
var
itemIndex
=
(
activeIndex
+
delta
)
%
this
.
$items
.
length
return
this
.
$items
.
eq
(
itemIndex
)
}
Carousel
.
prototype
.
to
=
function
(
pos
)
{
Carousel
.
prototype
.
to
=
function
(
pos
)
{
var
that
=
this
var
that
=
this
var
activeIndex
=
this
.
getItemIndex
(
this
.
$active
=
this
.
$element
.
find
(
'
.item.active
'
))
var
activeIndex
=
this
.
getItemIndex
(
this
.
$active
=
this
.
$element
.
find
(
'
.item.active
'
))
...
@@ -72,7 +79,7 @@
...
@@ -72,7 +79,7 @@
if
(
this
.
sliding
)
return
this
.
$element
.
one
(
'
slid.bs.carousel
'
,
function
()
{
that
.
to
(
pos
)
})
// yes, "slid"
if
(
this
.
sliding
)
return
this
.
$element
.
one
(
'
slid.bs.carousel
'
,
function
()
{
that
.
to
(
pos
)
})
// yes, "slid"
if
(
activeIndex
==
pos
)
return
this
.
pause
().
cycle
()
if
(
activeIndex
==
pos
)
return
this
.
pause
().
cycle
()
return
this
.
slide
(
pos
>
activeIndex
?
'
next
'
:
'
prev
'
,
$
(
this
.
$items
[
pos
]
))
return
this
.
slide
(
pos
>
activeIndex
?
'
next
'
:
'
prev
'
,
this
.
$items
.
eq
(
pos
))
}
}
Carousel
.
prototype
.
pause
=
function
(
e
)
{
Carousel
.
prototype
.
pause
=
function
(
e
)
{
...
@@ -100,7 +107,7 @@
...
@@ -100,7 +107,7 @@
Carousel
.
prototype
.
slide
=
function
(
type
,
next
)
{
Carousel
.
prototype
.
slide
=
function
(
type
,
next
)
{
var
$active
=
this
.
$element
.
find
(
'
.item.active
'
)
var
$active
=
this
.
$element
.
find
(
'
.item.active
'
)
var
$next
=
next
||
$active
[
type
](
)
var
$next
=
next
||
this
.
getItemForDirection
(
type
,
$active
)
var
isCycling
=
this
.
interval
var
isCycling
=
this
.
interval
var
direction
=
type
==
'
next
'
?
'
left
'
:
'
right
'
var
direction
=
type
==
'
next
'
?
'
left
'
:
'
right
'
var
fallback
=
type
==
'
next
'
?
'
first
'
:
'
last
'
var
fallback
=
type
==
'
next
'
?
'
first
'
:
'
last
'
...
...
js/tests/unit/carousel.js
View file @
f026cfb8
...
@@ -349,7 +349,7 @@ $(function () {
...
@@ -349,7 +349,7 @@ $(function () {
$carousel
.
remove
()
$carousel
.
remove
()
})
})
test
(
'
should skip over non-items
'
,
function
()
{
test
(
'
should skip over non-items
when using item indices
'
,
function
()
{
var
templateHTML
=
'
<div id="myCarousel" class="carousel" data-interval="1814">
'
var
templateHTML
=
'
<div id="myCarousel" class="carousel" data-interval="1814">
'
+
'
<div class="carousel-inner">
'
+
'
<div class="carousel-inner">
'
+
'
<div class="item active">
'
+
'
<div class="item active">
'
...
@@ -373,4 +373,29 @@ $(function () {
...
@@ -373,4 +373,29 @@ $(function () {
strictEqual
(
$template
.
find
(
'
.item
'
)[
1
],
$template
.
find
(
'
.active
'
)[
0
],
'
second item active
'
)
strictEqual
(
$template
.
find
(
'
.item
'
)[
1
],
$template
.
find
(
'
.active
'
)[
0
],
'
second item active
'
)
})
})
test
(
'
should skip over non-items when using next/prev methods
'
,
function
()
{
var
templateHTML
=
'
<div id="myCarousel" class="carousel" data-interval="1814">
'
+
'
<div class="carousel-inner">
'
+
'
<div class="item active">
'
+
'
<img alt="">
'
+
'
</div>
'
+
'
<script type="text/x-metamorph" id="thingy"/>
'
+
'
<div class="item">
'
+
'
<img alt="">
'
+
'
</div>
'
+
'
<div class="item">
'
+
'
</div>
'
+
'
</div>
'
+
'
</div>
'
var
$template
=
$
(
templateHTML
)
$template
.
bootstrapCarousel
()
strictEqual
(
$template
.
find
(
'
.item
'
)[
0
],
$template
.
find
(
'
.active
'
)[
0
],
'
first item active
'
)
$template
.
bootstrapCarousel
(
'
next
'
)
strictEqual
(
$template
.
find
(
'
.item
'
)[
1
],
$template
.
find
(
'
.active
'
)[
0
],
'
second item active
'
)
})
})
})
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment