Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #13185 - keyboard support for carousel #13787

Merged
merged 1 commit into from
Jun 11, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions js/carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// =========================

var Carousel = function (element, options) {
this.$element = $(element)
this.$element = $(element).on('keydown.bs.carousel', $.proxy(this.keydown, this))
this.$indicators = this.$element.find('.carousel-indicators')
this.options = options
this.paused =
Expand All @@ -28,8 +28,8 @@
this.$items = null

this.options.pause == 'hover' && this.$element
.on('mouseenter', $.proxy(this.pause, this))
.on('mouseleave', $.proxy(this.cycle, this))
.on('mouseenter.bs.carousel', $.proxy(this.pause, this))
.on('mouseleave.bs.carousel', $.proxy(this.cycle, this))
}

Carousel.VERSION = '3.1.1'
Expand All @@ -40,6 +40,16 @@
wrap: true
}

Carousel.prototype.keydown = function (e) {
switch (e.which) {
case 37: this.prev(); break
case 39: this.next(); break
default: return
}

e.preventDefault()
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems more fitting 😄

Carousel.prototype.keydown = function (e) {
  if (!/37|39/.test(e.which)) return

  this[e.which == 37 ? 'prev' : 'next']()

  e.preventDefault()
}

Also, ref

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah it was a switch statement because mark and i were going back and forth with adding a first/last option

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also think the switch is a bit more elegant in this case - only one condition, etc

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but the semicolons aren't that elegant.


Carousel.prototype.cycle = function (e) {
e || (this.paused = false)

Expand Down