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
038a63b0
Commit
038a63b0
authored
Sep 10, 2014
by
Heinrich Fenkart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add `keyboard` option to carousel
Also adds unit tests for keyboard events. Fixes #14468.
parent
e7b5c4c1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
90 additions
and
2 deletions
+90
-2
docs/_includes/js/carousel.html
docs/_includes/js/carousel.html
+6
-0
js/carousel.js
js/carousel.js
+5
-2
js/tests/unit/carousel.js
js/tests/unit/carousel.js
+79
-0
No files found.
docs/_includes/js/carousel.html
View file @
038a63b0
...
@@ -178,6 +178,12 @@ $('.carousel').carousel()
...
@@ -178,6 +178,12 @@ $('.carousel').carousel()
<td>
true
</td>
<td>
true
</td>
<td>
Whether the carousel should cycle continuously or have hard stops.
</td>
<td>
Whether the carousel should cycle continuously or have hard stops.
</td>
</tr>
</tr>
<tr>
<td>
keyboard
</td>
<td>
boolean
</td>
<td>
true
</td>
<td>
Whether the carousel should react to keyboard events.
</td>
</tr>
</tbody>
</tbody>
</table>
</table>
</div>
<!-- /.table-responsive -->
</div>
<!-- /.table-responsive -->
...
...
js/carousel.js
View file @
038a63b0
...
@@ -14,7 +14,7 @@
...
@@ -14,7 +14,7 @@
// =========================
// =========================
var
Carousel
=
function
(
element
,
options
)
{
var
Carousel
=
function
(
element
,
options
)
{
this
.
$element
=
$
(
element
)
.
on
(
'
keydown.bs.carousel
'
,
$
.
proxy
(
this
.
keydown
,
this
))
this
.
$element
=
$
(
element
)
this
.
$indicators
=
this
.
$element
.
find
(
'
.carousel-indicators
'
)
this
.
$indicators
=
this
.
$element
.
find
(
'
.carousel-indicators
'
)
this
.
options
=
options
this
.
options
=
options
this
.
paused
=
this
.
paused
=
...
@@ -23,6 +23,8 @@
...
@@ -23,6 +23,8 @@
this
.
$active
=
this
.
$active
=
this
.
$items
=
null
this
.
$items
=
null
this
.
options
.
keyboard
&&
this
.
$element
.
on
(
'
keydown.bs.carousel
'
,
$
.
proxy
(
this
.
keydown
,
this
))
this
.
options
.
pause
==
'
hover
'
&&
!
(
'
ontouchstart
'
in
document
.
documentElement
)
&&
this
.
$element
this
.
options
.
pause
==
'
hover
'
&&
!
(
'
ontouchstart
'
in
document
.
documentElement
)
&&
this
.
$element
.
on
(
'
mouseenter.bs.carousel
'
,
$
.
proxy
(
this
.
pause
,
this
))
.
on
(
'
mouseenter.bs.carousel
'
,
$
.
proxy
(
this
.
pause
,
this
))
.
on
(
'
mouseleave.bs.carousel
'
,
$
.
proxy
(
this
.
cycle
,
this
))
.
on
(
'
mouseleave.bs.carousel
'
,
$
.
proxy
(
this
.
cycle
,
this
))
...
@@ -35,7 +37,8 @@
...
@@ -35,7 +37,8 @@
Carousel
.
DEFAULTS
=
{
Carousel
.
DEFAULTS
=
{
interval
:
5000
,
interval
:
5000
,
pause
:
'
hover
'
,
pause
:
'
hover
'
,
wrap
:
true
wrap
:
true
,
keyboard
:
true
}
}
Carousel
.
prototype
.
keydown
=
function
(
e
)
{
Carousel
.
prototype
.
keydown
=
function
(
e
)
{
...
...
js/tests/unit/carousel.js
View file @
038a63b0
...
@@ -399,6 +399,85 @@ $(function () {
...
@@ -399,6 +399,85 @@ $(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 go to previous item if left arrow key is pressed
'
,
function
()
{
var
templateHTML
=
'
<div id="myCarousel" class="carousel" data-interval="false">
'
+
'
<div class="carousel-inner">
'
+
'
<div id="first" class="item">
'
+
'
<img alt="">
'
+
'
</div>
'
+
'
<div id="second" class="item active">
'
+
'
<img alt="">
'
+
'
</div>
'
+
'
<div id="third" class="item">
'
+
'
<img alt="">
'
+
'
</div>
'
+
'
</div>
'
+
'
</div>
'
var
$template
=
$
(
templateHTML
)
$template
.
bootstrapCarousel
()
strictEqual
(
$template
.
find
(
'
.item
'
)[
1
],
$template
.
find
(
'
.active
'
)[
0
],
'
second item active
'
)
$template
.
trigger
(
$
.
Event
(
'
keydown
'
,
{
which
:
37
}))
strictEqual
(
$template
.
find
(
'
.item
'
)[
0
],
$template
.
find
(
'
.active
'
)[
0
],
'
first item active
'
)
})
test
(
'
should go to next item if right arrow key is pressed
'
,
function
()
{
var
templateHTML
=
'
<div id="myCarousel" class="carousel" data-interval="false">
'
+
'
<div class="carousel-inner">
'
+
'
<div id="first" class="item active">
'
+
'
<img alt="">
'
+
'
</div>
'
+
'
<div id="second" class="item">
'
+
'
<img alt="">
'
+
'
</div>
'
+
'
<div id="third" class="item">
'
+
'
<img alt="">
'
+
'
</div>
'
+
'
</div>
'
+
'
</div>
'
var
$template
=
$
(
templateHTML
)
$template
.
bootstrapCarousel
()
strictEqual
(
$template
.
find
(
'
.item
'
)[
0
],
$template
.
find
(
'
.active
'
)[
0
],
'
first item active
'
)
$template
.
trigger
(
$
.
Event
(
'
keydown
'
,
{
which
:
39
}))
strictEqual
(
$template
.
find
(
'
.item
'
)[
1
],
$template
.
find
(
'
.active
'
)[
0
],
'
second item active
'
)
})
test
(
'
should support disabling the keyboard navigation
'
,
function
()
{
var
templateHTML
=
'
<div id="myCarousel" class="carousel" data-interval="false" data-keyboard="false">
'
+
'
<div class="carousel-inner">
'
+
'
<div id="first" class="item active">
'
+
'
<img alt="">
'
+
'
</div>
'
+
'
<div id="second" class="item">
'
+
'
<img alt="">
'
+
'
</div>
'
+
'
<div id="third" class="item">
'
+
'
<img alt="">
'
+
'
</div>
'
+
'
</div>
'
+
'
</div>
'
var
$template
=
$
(
templateHTML
)
$template
.
bootstrapCarousel
()
strictEqual
(
$template
.
find
(
'
.item
'
)[
0
],
$template
.
find
(
'
.active
'
)[
0
],
'
first item active
'
)
$template
.
trigger
(
$
.
Event
(
'
keydown
'
,
{
which
:
39
}))
strictEqual
(
$template
.
find
(
'
.item
'
)[
0
],
$template
.
find
(
'
.active
'
)[
0
],
'
first item still active after right arrow press
'
)
$template
.
trigger
(
$
.
Event
(
'
keydown
'
,
{
which
:
37
}))
strictEqual
(
$template
.
find
(
'
.item
'
)[
0
],
$template
.
find
(
'
.active
'
)[
0
],
'
first item still active after left arrow press
'
)
})
test
(
'
should only add mouseenter and mouseleave listeners when not on mobile
'
,
function
()
{
test
(
'
should only add mouseenter and mouseleave listeners when not on mobile
'
,
function
()
{
var
isMobile
=
'
ontouchstart
'
in
document
.
documentElement
var
isMobile
=
'
ontouchstart
'
in
document
.
documentElement
var
templateHTML
=
'
<div id="myCarousel" class="carousel" data-interval="false" data-pause="hover">
'
var
templateHTML
=
'
<div id="myCarousel" class="carousel" data-interval="false" data-pause="hover">
'
...
...
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