Skip to content

Commit

Permalink
Merge pull request #124 from montrezorro/master
Browse files Browse the repository at this point in the history
rewrote tab function
  • Loading branch information
Jordan Schroter committed May 22, 2014
2 parents cb80f1c + 7f87d1c commit 6f85220
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions js/bootstrap-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,24 +154,25 @@
if (this.isShown && this.options.consumeTab) {
this.$element.on('keydown.tabindex.modal', '[data-tabindex]', function (e) {
if (e.keyCode && e.keyCode == 9){
var $next = $(this),
$rollover = $(this);

that.$element.find('[data-tabindex]:enabled:not([readonly])').each(function (e) {
if (!e.shiftKey){
$next = $next.data('tabindex') < $(this).data('tabindex') ?
$next = $(this) :
$rollover = $(this);
var elements = [],
tabindex = Number($(this).data('tabindex'));

that.$element.find('[data-tabindex]:enabled:visible:not([readonly])').each(function (ev) {
elements.push(Number($(this).data('tabindex')));
});
elements.sort(function(a,b){return a-b});

var arrayPos = $.inArray(tabindex, elements);
if (!e.shiftKey){
arrayPos < elements.length-1 ?
that.$element.find('[data-tabindex='+elements[arrayPos+1]+']').focus() :
that.$element.find('[data-tabindex='+elements[0]+']').focus();
} else {
$next = $next.data('tabindex') > $(this).data('tabindex') ?
$next = $(this) :
$rollover = $(this);
arrayPos == 0 ?
that.$element.find('[data-tabindex='+elements[elements.length-1]+']').focus() :
that.$element.find('[data-tabindex='+elements[arrayPos-1]+']').focus();
}
});

$next[0] !== $(this)[0] ?
$next.focus() : $rollover.focus();


e.preventDefault();
}
});
Expand Down

0 comments on commit 6f85220

Please sign in to comment.