-
Notifications
You must be signed in to change notification settings - Fork 175
/
modal.js
30 lines (28 loc) · 1.12 KB
/
modal.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Modal Extension
// ===============================
$('.modal-dialog').attr( {'role' : 'document'})
var modalhide = $.fn.modal.Constructor.prototype.hide
$.fn.modal.Constructor.prototype.hide = function(){
modalhide.apply(this, arguments)
$(document).off('keydown.bs.modal')
}
var modalfocus = $.fn.modal.Constructor.prototype.enforceFocus
$.fn.modal.Constructor.prototype.enforceFocus = function(){
var $content = this.$element.find(".modal-content")
var focEls = $content.find(":tabbable")
, $lastEl = $(focEls[focEls.length-1])
, $firstEl = $(focEls[0])
$lastEl.on('keydown.bs.modal', $.proxy(function (ev) {
if(ev.keyCode === 9 && !(ev.shiftKey | ev.ctrlKey | ev.metaKey | ev.altKey)) { // TAB pressed
ev.preventDefault();
$firstEl.focus();
}
}, this))
$firstEl.on('keydown.bs.modal', $.proxy(function (ev) {
if(ev.keyCode === 9 && ev.shiftKey) { // SHIFT-TAB pressed
ev.preventDefault();
$lastEl.focus();
}
}, this))
modalfocus.apply(this, arguments)
}