From: Jacob Thornton Date: Thu, 17 May 2012 02:09:57 +0000 (-0700) Subject: modal accessibility tab control X-Git-Tag: v2.1.0~2^2~351^2~4^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a404ac33bb9e78323b84d0840735445579634b9e;p=thirdparty%2Fbootstrap.git modal accessibility tab control --- diff --git a/docs/assets/js/bootstrap-modal.js b/docs/assets/js/bootstrap-modal.js index c831de6b64..f7ae39652b 100644 --- a/docs/assets/js/bootstrap-modal.js +++ b/docs/assets/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,102 @@ $('body').removeClass('modal-open') - escape.call(this) + this.escape() + this.relaxFocus() this.$element.removeClass('in') $.support.transition && this.$element.hasClass('fade') ? - hideWithTransition.call(this) : - hideModal.call(this) + this.hideWithTransition() : + this.hideModal() } - } - - - /* MODAL PRIVATE METHODS - * ===================== */ + , enforceFocus: function () { + var that = this + var console = window.console + console.log('attach'); + $(document).on('focusin.modal', function (e) { + console.log('triggered'); + if (that.$element[0] !== e.target && !that.$element.has(e.target).length) { + that.$element.focus() + } + }) + } - function hideWithTransition() { - var that = this - , timeout = setTimeout(function () { - that.$element.off($.support.transition.end) - hideModal.call(that) - }, 500) + , relaxFocus: function () { + $(document).off('focus.modal') + } - 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 = $('