Skip to content
Open
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
72 changes: 45 additions & 27 deletions js/bootstrap-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
* limitations under the License.
* ========================================================== */


!function ($) {

"use strict"; // jshint ;_;
Expand All @@ -37,8 +36,7 @@

this.options = options;

this.$element = $(element)
.delegate('[data-dismiss="modal"]', 'click.dismiss.modal', $.proxy(this.hide, this));
this.$element = $(element);

this.options.remote && this.$element.find('.modal-body').load(this.options.remote, function () {
var e = $.Event('loaded');
Expand Down Expand Up @@ -81,6 +79,10 @@

this.$element.trigger(e);

if (this.options.onHide !== null) {
eval(this.options.onHide);
}

if (!this.isShown || e.isDefaultPrevented()) return (this.isShown = false);

this.isShown = false;
Expand Down Expand Up @@ -136,7 +138,7 @@
}

var modalOverflow = $(window).height() - 10 < this.$element.height();

if (modalOverflow || this.options.modalOverflow) {
this.$element
.css('margin-top', 0)
Expand All @@ -153,13 +155,13 @@

if (this.isShown && this.options.consumeTab) {
this.$element.on('keydown.tabindex.modal', '[data-tabindex]', function (e) {
if (e.keyCode && e.keyCode == 9){
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 = $next.data('tabindex') < $(this).data('tabindex') ?
$next = $(this) :
$rollover = $(this);
} else {
Expand All @@ -185,11 +187,17 @@
if (this.isShown && this.options.keyboard) {
if (!this.$element.attr('tabindex')) this.$element.attr('tabindex', -1);

this.$element.on('keyup.dismiss.modal', function (e) {
e.which == 27 && that.hide();
});
this.$element
.on('keyup.dismiss.modal', function (e) {
if (e.which === 27) {
e.preventDefault();
e.stopPropagation();

that.hide();
}
});
} else if (!this.isShown) {
this.$element.off('keyup.dismiss.modal')
this.$element.off('keyup.dismiss.modal');
}
},

Expand Down Expand Up @@ -265,15 +273,15 @@
focus: function () {
var $focusElem = this.$element.find(this.options.focusOn);

$focusElem = $focusElem.length ? $focusElem : this.$element;
$focusElem = $focusElem.length > 0 ? $focusElem[0] : this.$element[0];

$focusElem.focus();
},

attention: function (){
attention: function () {
// NOTE: transitionEnd with keyframes causes odd behaviour

if (this.options.attentionAnimation){
if (this.options.attentionAnimation) {
this.$element
.removeClass('animated')
.removeClass(this.options.attentionAnimation);
Expand All @@ -287,7 +295,6 @@
}, 0);
}


this.focus();
},

Expand Down Expand Up @@ -346,6 +353,7 @@
modalOverflow: false,
consumeTab: true,
focusOn: null,
onHide : null,
replace: false,
resize: false,
attentionAnimation: 'shake',
Expand All @@ -361,19 +369,29 @@
* ============== */

$(function () {
$(document).off('click.modal').on('click.modal.data-api', '[data-toggle="modal"]', function ( e ) {
var $this = $(this),
href = $this.attr('href'),
$target = $($this.attr('data-target') || (href && href.replace(/.*(?=#[^\s]+$)/, ''))), //strip for ie7
option = $target.data('modal') ? 'toggle' : $.extend({ remote: !/#/.test(href) && href }, $target.data(), $this.data());

e.preventDefault();
$target
.modal(option)
.one('hide', function () {
$this.focus();
})
});
$(document)
.off('click.modal')
.on('click.modal.data-api', '[data-dismiss="modal"]', function ( e ) {
e.preventDefault();

$(this)
.parents(".modal:first")
.modal("hide");
})
.on('click.modal.data-api', '[data-toggle="modal"]', function ( e ) {
var $this = $(this),
href = $this.attr('href'),
$target = $($this.attr('data-target') || (href && href.replace(/.*(?=#[^\s]+$)/, ''))), //strip for ie7
option = $target.data('modal') ? 'toggle' : $.extend({ remote: !/#/.test(href) && href }, $target.data(), $this.data());

e.preventDefault();

$target
.modal(option)
.one('hide', function () {
$this.focus();
})
});
});

}(window.jQuery);