Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/twbs/bootstrap.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorJacob Thornton <jacobthornton@gmail.com>2012-06-03 03:11:35 +0400
committerJacob Thornton <jacobthornton@gmail.com>2012-06-03 03:11:35 +0400
commit5e5965ca6fe719e83f5eb06222170b87dba78f02 (patch)
treefa6723ece71b5f733d608c6228521609a4adbd99 /js
parentebc69356637143c938c07904d10928c11e742196 (diff)
parentb1d7c34086ec95a2b0507c595e3a353cdc550b9b (diff)
Merge branch 'accessibility' into 2.1.0-wip
Conflicts: docs/assets/js/bootstrap.min.js docs/javascript.html docs/templates/pages/javascript.mustache
Diffstat (limited to 'js')
-rw-r--r--js/.jshintrc1
-rw-r--r--js/bootstrap-dropdown.js78
-rw-r--r--js/bootstrap-modal.js139
3 files changed, 139 insertions, 79 deletions
diff --git a/js/.jshintrc b/js/.jshintrc
index bbac349e8f..0f064a0b4e 100644
--- a/js/.jshintrc
+++ b/js/.jshintrc
@@ -4,6 +4,7 @@
"laxbreak" : true,
"browser" : true,
"debug" : true,
+ "devel" : true,
"boss" : true,
"expr" : true,
"asi" : true
diff --git a/js/bootstrap-dropdown.js b/js/bootstrap-dropdown.js
index 454a9684b5..d71a54292d 100644
--- a/js/bootstrap-dropdown.js
+++ b/js/bootstrap-dropdown.js
@@ -26,7 +26,7 @@
/* DROPDOWN CLASS DEFINITION
* ========================= */
- var toggle = '[data-toggle="dropdown"]'
+ var toggle = '[data-toggle=dropdown]'
, Dropdown = function (element) {
var $el = $(element).on('click.dropdown.data-api', this.toggle)
$('html').on('click.dropdown.data-api', function () {
@@ -41,34 +41,82 @@
, toggle: function (e) {
var $this = $(this)
, $parent
- , selector
, isActive
if ($this.is('.disabled, :disabled')) return
- selector = $this.attr('data-target')
+ $parent = getParent($this)
- if (!selector) {
- selector = $this.attr('href')
- selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7
+ isActive = $parent.hasClass('open')
+
+ clearMenus()
+
+ if (!isActive) {
+ $parent.toggleClass('open')
+ $this.focus()
}
- $parent = $(selector)
- $parent.length || ($parent = $this.parent())
+ return false
+ }
+
+ , keydown: function (e) {
+ var $this
+ , $items
+ , $active
+ , $parent
+ , isActive
+ , index
+
+ if (!/(38|40|27)/.test(e.keyCode)) return
+
+ $this = $(this)
+
+ e.preventDefault()
+ e.stopPropagation()
+
+ if ($this.is('.disabled, :disabled')) return
+
+ $parent = getParent($this)
isActive = $parent.hasClass('open')
- clearMenus()
+ if (!isActive || (isActive && e.keyCode == 27)) return $this.click()
- if (!isActive) $parent.toggleClass('open')
+ $items = $('[role=menu] li:not(.divider) a', $parent)
- return false
+ if (!$items.length) return
+
+ index = $items.index($items.filter(':focus'))
+
+ if (e.keyCode == 38 && index > 0) index-- // up
+ if (e.keyCode == 40 && index < $items.length - 1) index++ // down
+ if (!~index) index = 0
+
+ $items
+ .eq(index)
+ .focus()
}
}
function clearMenus() {
- $(toggle).parent().removeClass('open')
+ getParent($(toggle))
+ .removeClass('open')
+ }
+
+ function getParent($this) {
+ var selector = $this.attr('data-target')
+ , $parent
+
+ if (!selector) {
+ selector = $this.attr('href')
+ selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7
+ }
+
+ $parent = $(selector)
+ $parent.length || ($parent = $this.parent())
+
+ return $parent
}
@@ -91,10 +139,12 @@
* =================================== */
$(function () {
- $('html').on('click.dropdown.data-api', clearMenus)
+ $('html')
+ .on('click.dropdown.data-api', clearMenus)
$('body')
.on('click.dropdown', '.dropdown form', function (e) { e.stopPropagation() })
- .on('click.dropdown.data-api', toggle, Dropdown.prototype.toggle)
+ .on('click.dropdown.data-api' , toggle, Dropdown.prototype.toggle)
+ .on('keydown.dropdown.data-api', toggle + ', [role=menu]' , Dropdown.prototype.keydown)
})
}(window.jQuery); \ No newline at end of file
diff --git a/js/bootstrap-modal.js b/js/bootstrap-modal.js
index 38fd0c8468..fb5da75c3a 100644
--- a/js/bootstrap-modal.js
+++ b/js/bootstrap-modal.js
@@ -52,8 +52,9 @@
this.isShown = true
- escape.call(this)
- backdrop.call(this, function () {
+ this.escape()
+
+ this.backdrop(function () {
var transition = $.support.transition && that.$element.hasClass('fade')
if (!that.$element.parent().length) {
@@ -69,6 +70,8 @@
that.$element.addClass('in')
+ that.enforceFocus()
+
transition ?
that.$element.one($.support.transition.end, function () { that.$element.trigger('shown') }) :
that.$element.trigger('shown')
@@ -91,90 +94,96 @@
$('body').removeClass('modal-open')
- escape.call(this)
+ this.escape()
+
+ $(document).off('focusin.modal')
this.$element.removeClass('in')
$.support.transition && this.$element.hasClass('fade') ?
- hideWithTransition.call(this) :
- hideModal.call(this)
+ this.hideWithTransition() :
+ this.hideModal()
}
- }
-
-
- /* MODAL PRIVATE METHODS
- * ===================== */
-
- function hideWithTransition() {
- var that = this
- , timeout = setTimeout(function () {
- that.$element.off($.support.transition.end)
- hideModal.call(that)
- }, 500)
+ , enforceFocus: function () {
+ var that = this
+ $(document).on('focusin.modal', function (e) {
+ if (that.$element[0] !== e.target && !that.$element.has(e.target).length) {
+ that.$element.focus()
+ }
+ })
+ }
- this.$element.one($.support.transition.end, function () {
- clearTimeout(timeout)
- hideModal.call(that)
- })
- }
+ , escape: function () {
+ var that = this
+ if (this.isShown && this.options.keyboard) {
+ $(document).on('keyup.dismiss.modal', function ( e ) {
+ e.which == 27 && that.hide()
+ })
+ } else if (!this.isShown) {
+ $(document).off('keyup.dismiss.modal')
+ }
+ }
- function hideModal(that) {
- this.$element
- .hide()
- .trigger('hidden')
+ , hideWithTransition: function () {
+ var that = this
+ , timeout = setTimeout(function () {
+ that.$element.off($.support.transition.end)
+ that.hideModal()
+ }, 500)
+
+ this.$element.one($.support.transition.end, function () {
+ clearTimeout(timeout)
+ that.hideModal()
+ })
+ }
- backdrop.call(this)
- }
+ , hideModal: function (that) {
+ this.$element
+ .hide()
+ .trigger('hidden')
- function backdrop(callback) {
- var that = this
- , animate = this.$element.hasClass('fade') ? 'fade' : ''
+ this.backdrop()
+ }
- if (this.isShown && this.options.backdrop) {
- var doAnimate = $.support.transition && animate
+ , removeBackdrop: function () {
+ this.$backdrop.remove()
+ this.$backdrop = null
+ }
- this.$backdrop = $('<div class="modal-backdrop ' + animate + '" />')
- .appendTo(document.body)
+ , backdrop: function (callback) {
+ var that = this
+ , animate = this.$element.hasClass('fade') ? 'fade' : ''
- if (this.options.backdrop != 'static') {
- this.$backdrop.click($.proxy(this.hide, this))
- }
+ if (this.isShown && this.options.backdrop) {
+ var doAnimate = $.support.transition && animate
- if (doAnimate) this.$backdrop[0].offsetWidth // force reflow
+ this.$backdrop = $('<div class="modal-backdrop ' + animate + '" />')
+ .appendTo(document.body)
- this.$backdrop.addClass('in')
+ if (this.options.backdrop != 'static') {
+ this.$backdrop.click($.proxy(this.hide, this))
+ }
- doAnimate ?
- this.$backdrop.one($.support.transition.end, callback) :
- callback()
+ if (doAnimate) this.$backdrop[0].offsetWidth // force reflow
- } else if (!this.isShown && this.$backdrop) {
- this.$backdrop.removeClass('in')
+ this.$backdrop.addClass('in')
- $.support.transition && this.$element.hasClass('fade')?
- this.$backdrop.one($.support.transition.end, $.proxy(removeBackdrop, this)) :
- removeBackdrop.call(this)
+ doAnimate ?
+ this.$backdrop.one($.support.transition.end, callback) :
+ callback()
- } else if (callback) {
- callback()
- }
- }
+ } else if (!this.isShown && this.$backdrop) {
+ this.$backdrop.removeClass('in')
- function removeBackdrop() {
- this.$backdrop.remove()
- this.$backdrop = null
- }
+ $.support.transition && this.$element.hasClass('fade')?
+ this.$backdrop.one($.support.transition.end, $.proxy(this.removeBackdrop, this)) :
+ this.removeBackdrop()
- function escape() {
- var that = this
- if (this.isShown && this.options.keyboard) {
- $(document).on('keyup.dismiss.modal', function ( e ) {
- e.which == 27 && that.hide()
- })
- } else if (!this.isShown) {
- $(document).off('keyup.dismiss.modal')
- }
+ } else if (callback) {
+ callback()
+ }
+ }
}