diff options
| author | Chris Rebert <[email protected]> | 2014-06-23 11:07:18 -0700 |
|---|---|---|
| committer | Chris Rebert <[email protected]> | 2014-06-23 11:11:59 -0700 |
| commit | c2c19a4d2d45d8ccb5c84d293dea35a94148c9a4 (patch) | |
| tree | f12ed485a1a3f84ce60c6a195e8efca27f418042 /js/modal.js | |
| parent | bc895a4b43ecfd2ad8c3793fdd6d8bada9d93186 (diff) | |
| download | bootstrap-c2c19a4d2d45d8ccb5c84d293dea35a94148c9a4.tar.xz bootstrap-c2c19a4d2d45d8ccb5c84d293dea35a94148c9a4.zip | |
Revert UMD (#13772 & friends) for now, due to #13812.
Will hopefully revert this reversion and land a fully-working version of UMD in v3.3.0.
Revert "some changes from #13801 - add strict mode back and =="
This reverts commit 2b302f69eea416bc85e7827b7d7a74d49f879662.
Revert "Fix regression of #10038 introduced by #13772"
This reverts commit e9d6756a1ac76a9db31a41e8e03f663bedc41b70.
Revert "MD/CommonJS/Globals #12909"
This reverts commit 1c6fa9010daf0d0c21de9e20fe6ac4dba1788d90.
Revert "address #13811"
This reverts commit f347d7d955bbb17234b8e12c68efae7d516ce62c.
Conflicts:
js/carousel.js
js/collapse.js
js/dropdown.js
js/modal.js
js/tab.js
js/tooltip.js
Diffstat (limited to 'js/modal.js')
| -rw-r--r-- | js/modal.js | 410 |
1 files changed, 202 insertions, 208 deletions
diff --git a/js/modal.js b/js/modal.js index 359e1fc67..edbb6c1c9 100644 --- a/js/modal.js +++ b/js/modal.js @@ -7,280 +7,274 @@ * ======================================================================== */ -+function () { 'use strict'; - - (function (o_o) { - typeof define == 'function' && define.amd ? define(['jquery'], o_o) : - typeof exports == 'object' ? o_o(require('jquery')) : o_o(jQuery) - })(function ($) { - - // MODAL CLASS DEFINITION - // ====================== - - var Modal = function (element, options) { - this.options = options - this.$body = $(document.body) - this.$element = $(element) - this.$backdrop = - this.isShown = null - this.scrollbarWidth = 0 - - if (this.options.remote) { - this.$element - .find('.modal-content') - .load(this.options.remote, $.proxy(function () { - this.$element.trigger('loaded.bs.modal') - }, this)) - } - } ++function ($) { + 'use strict'; - Modal.VERSION = '3.1.1' + // MODAL CLASS DEFINITION + // ====================== - Modal.DEFAULTS = { - backdrop: true, - keyboard: true, - show: true - } + var Modal = function (element, options) { + this.options = options + this.$body = $(document.body) + this.$element = $(element) + this.$backdrop = + this.isShown = null + this.scrollbarWidth = 0 - Modal.prototype.toggle = function (_relatedTarget) { - return this.isShown ? this.hide() : this.show(_relatedTarget) + if (this.options.remote) { + this.$element + .find('.modal-content') + .load(this.options.remote, $.proxy(function () { + this.$element.trigger('loaded.bs.modal') + }, this)) } + } - Modal.prototype.show = function (_relatedTarget) { - var that = this - var e = $.Event('show.bs.modal', { relatedTarget: _relatedTarget }) + Modal.VERSION = '3.1.1' - this.$element.trigger(e) + Modal.DEFAULTS = { + backdrop: true, + keyboard: true, + show: true + } - if (this.isShown || e.isDefaultPrevented()) return + Modal.prototype.toggle = function (_relatedTarget) { + return this.isShown ? this.hide() : this.show(_relatedTarget) + } - this.isShown = true + Modal.prototype.show = function (_relatedTarget) { + var that = this + var e = $.Event('show.bs.modal', { relatedTarget: _relatedTarget }) - this.checkScrollbar() - this.$body.addClass('modal-open') + this.$element.trigger(e) - this.setScrollbar() - this.escape() + if (this.isShown || e.isDefaultPrevented()) return - this.$element.on('click.dismiss.bs.modal', '[data-dismiss="modal"]', $.proxy(this.hide, this)) + this.isShown = true - this.backdrop(function () { - var transition = $.support.transition && that.$element.hasClass('fade') + this.checkScrollbar() + this.$body.addClass('modal-open') - if (!that.$element.parent().length) { - that.$element.appendTo(that.$body) // don't move modals dom position - } + this.setScrollbar() + this.escape() - that.$element - .show() - .scrollTop(0) + this.$element.on('click.dismiss.bs.modal', '[data-dismiss="modal"]', $.proxy(this.hide, this)) - if (transition) { - that.$element[0].offsetWidth // force reflow - } + this.backdrop(function () { + var transition = $.support.transition && that.$element.hasClass('fade') - that.$element - .addClass('in') - .attr('aria-hidden', false) + if (!that.$element.parent().length) { + that.$element.appendTo(that.$body) // don't move modals dom position + } - that.enforceFocus() + that.$element + .show() + .scrollTop(0) - var e = $.Event('shown.bs.modal', { relatedTarget: _relatedTarget }) + if (transition) { + that.$element[0].offsetWidth // force reflow + } - transition ? - that.$element.find('.modal-dialog') // wait for modal to slide in - .one('bsTransitionEnd', function () { - that.$element.trigger('focus').trigger(e) - }) - .emulateTransitionEnd(300) : - that.$element.trigger('focus').trigger(e) - }) - } + that.$element + .addClass('in') + .attr('aria-hidden', false) - Modal.prototype.hide = function (e) { - if (e) e.preventDefault() + that.enforceFocus() - e = $.Event('hide.bs.modal') + var e = $.Event('shown.bs.modal', { relatedTarget: _relatedTarget }) - this.$element.trigger(e) + transition ? + that.$element.find('.modal-dialog') // wait for modal to slide in + .one('bsTransitionEnd', function () { + that.$element.trigger('focus').trigger(e) + }) + .emulateTransitionEnd(300) : + that.$element.trigger('focus').trigger(e) + }) + } - if (!this.isShown || e.isDefaultPrevented()) return + Modal.prototype.hide = function (e) { + if (e) e.preventDefault() - this.isShown = false + e = $.Event('hide.bs.modal') - this.$body.removeClass('modal-open') + this.$element.trigger(e) - this.resetScrollbar() - this.escape() + if (!this.isShown || e.isDefaultPrevented()) return - $(document).off('focusin.bs.modal') + this.isShown = false - this.$element - .removeClass('in') - .attr('aria-hidden', true) - .off('click.dismiss.bs.modal') + this.$body.removeClass('modal-open') - $.support.transition && this.$element.hasClass('fade') ? - this.$element - .one('bsTransitionEnd', $.proxy(this.hideModal, this)) - .emulateTransitionEnd(300) : - this.hideModal() - } + this.resetScrollbar() + this.escape() - Modal.prototype.enforceFocus = function () { - $(document) - .off('focusin.bs.modal') // guard against infinite focus loop - .on('focusin.bs.modal', $.proxy(function (e) { - if (this.$element[0] !== e.target && !this.$element.has(e.target).length) { - this.$element.trigger('focus') - } - }, this)) - } + $(document).off('focusin.bs.modal') - Modal.prototype.escape = function () { - if (this.isShown && this.options.keyboard) { - this.$element.on('keyup.dismiss.bs.modal', $.proxy(function (e) { - e.which == 27 && this.hide() - }, this)) - } else if (!this.isShown) { - this.$element.off('keyup.dismiss.bs.modal') - } - } + this.$element + .removeClass('in') + .attr('aria-hidden', true) + .off('click.dismiss.bs.modal') - Modal.prototype.hideModal = function () { - var that = this - this.$element.hide() - this.backdrop(function () { - that.$element.trigger('hidden.bs.modal') - }) + $.support.transition && this.$element.hasClass('fade') ? + this.$element + .one('bsTransitionEnd', $.proxy(this.hideModal, this)) + .emulateTransitionEnd(300) : + this.hideModal() + } + + Modal.prototype.enforceFocus = function () { + $(document) + .off('focusin.bs.modal') // guard against infinite focus loop + .on('focusin.bs.modal', $.proxy(function (e) { + if (this.$element[0] !== e.target && !this.$element.has(e.target).length) { + this.$element.trigger('focus') + } + }, this)) + } + + Modal.prototype.escape = function () { + if (this.isShown && this.options.keyboard) { + this.$element.on('keyup.dismiss.bs.modal', $.proxy(function (e) { + e.which == 27 && this.hide() + }, this)) + } else if (!this.isShown) { + this.$element.off('keyup.dismiss.bs.modal') } + } - Modal.prototype.removeBackdrop = function () { - this.$backdrop && this.$backdrop.remove() - this.$backdrop = null - } + Modal.prototype.hideModal = function () { + var that = this + this.$element.hide() + this.backdrop(function () { + that.$element.trigger('hidden.bs.modal') + }) + } - Modal.prototype.backdrop = function (callback) { - var that = this - var animate = this.$element.hasClass('fade') ? 'fade' : '' + Modal.prototype.removeBackdrop = function () { + this.$backdrop && this.$backdrop.remove() + this.$backdrop = null + } - if (this.isShown && this.options.backdrop) { - var doAnimate = $.support.transition && animate + Modal.prototype.backdrop = function (callback) { + var that = this + var animate = this.$element.hasClass('fade') ? 'fade' : '' - this.$backdrop = $('<div class="modal-backdrop ' + animate + '" />') - .appendTo(this.$body) + if (this.isShown && this.options.backdrop) { + var doAnimate = $.support.transition && animate - this.$element.on('click.dismiss.bs.modal', $.proxy(function (e) { - if (e.target !== e.currentTarget) return - this.options.backdrop == 'static' - ? this.$element[0].focus.call(this.$element[0]) - : this.hide.call(this) - }, this)) + this.$backdrop = $('<div class="modal-backdrop ' + animate + '" />') + .appendTo(this.$body) - if (doAnimate) this.$backdrop[0].offsetWidth // force reflow + this.$element.on('click.dismiss.bs.modal', $.proxy(function (e) { + if (e.target !== e.currentTarget) return + this.options.backdrop == 'static' + ? this.$element[0].focus.call(this.$element[0]) + : this.hide.call(this) + }, this)) - this.$backdrop.addClass('in') + if (doAnimate) this.$backdrop[0].offsetWidth // force reflow - if (!callback) return + this.$backdrop.addClass('in') - doAnimate ? - this.$backdrop - .one('bsTransitionEnd', callback) - .emulateTransitionEnd(150) : - callback() + if (!callback) return - } else if (!this.isShown && this.$backdrop) { - this.$backdrop.removeClass('in') + doAnimate ? + this.$backdrop + .one('bsTransitionEnd', callback) + .emulateTransitionEnd(150) : + callback() - var callbackRemove = function () { - that.removeBackdrop() - callback && callback() - } - $.support.transition && this.$element.hasClass('fade') ? - this.$backdrop - .one('bsTransitionEnd', callbackRemove) - .emulateTransitionEnd(150) : - callbackRemove() + } else if (!this.isShown && this.$backdrop) { + this.$backdrop.removeClass('in') - } else if (callback) { - callback() + var callbackRemove = function () { + that.removeBackdrop() + callback && callback() } - } + $.support.transition && this.$element.hasClass('fade') ? + this.$backdrop + .one('bsTransitionEnd', callbackRemove) + .emulateTransitionEnd(150) : + callbackRemove() - Modal.prototype.checkScrollbar = function () { - if (document.body.clientWidth >= window.innerWidth) return - this.scrollbarWidth = this.scrollbarWidth || this.measureScrollbar() + } else if (callback) { + callback() } + } - Modal.prototype.setScrollbar = function () { - var bodyPad = parseInt((this.$body.css('padding-right') || 0), 10) - if (this.scrollbarWidth) this.$body.css('padding-right', bodyPad + this.scrollbarWidth) - } + Modal.prototype.checkScrollbar = function () { + if (document.body.clientWidth >= window.innerWidth) return + this.scrollbarWidth = this.scrollbarWidth || this.measureScrollbar() + } - Modal.prototype.resetScrollbar = function () { - this.$body.css('padding-right', '') - } + Modal.prototype.setScrollbar = function () { + var bodyPad = parseInt((this.$body.css('padding-right') || 0), 10) + if (this.scrollbarWidth) this.$body.css('padding-right', bodyPad + this.scrollbarWidth) + } - Modal.prototype.measureScrollbar = function () { // thx walsh - var scrollDiv = document.createElement('div') - scrollDiv.className = 'modal-scrollbar-measure' - this.$body.append(scrollDiv) - var scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth - this.$body[0].removeChild(scrollDiv) - return scrollbarWidth - } + Modal.prototype.resetScrollbar = function () { + this.$body.css('padding-right', '') + } + Modal.prototype.measureScrollbar = function () { // thx walsh + var scrollDiv = document.createElement('div') + scrollDiv.className = 'modal-scrollbar-measure' + this.$body.append(scrollDiv) + var scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth + this.$body[0].removeChild(scrollDiv) + return scrollbarWidth + } - // MODAL PLUGIN DEFINITION - // ======================= - function Plugin(option, _relatedTarget) { - return this.each(function () { - var $this = $(this) - var data = $this.data('bs.modal') - var options = $.extend({}, Modal.DEFAULTS, $this.data(), typeof option == 'object' && option) + // MODAL PLUGIN DEFINITION + // ======================= - if (!data) $this.data('bs.modal', (data = new Modal(this, options))) - if (typeof option == 'string') data[option](_relatedTarget) - else if (options.show) data.show(_relatedTarget) - }) - } + function Plugin(option, _relatedTarget) { + return this.each(function () { + var $this = $(this) + var data = $this.data('bs.modal') + var options = $.extend({}, Modal.DEFAULTS, $this.data(), typeof option == 'object' && option) - var old = $.fn.modal + if (!data) $this.data('bs.modal', (data = new Modal(this, options))) + if (typeof option == 'string') data[option](_relatedTarget) + else if (options.show) data.show(_relatedTarget) + }) + } - $.fn.modal = Plugin - $.fn.modal.Constructor = Modal + var old = $.fn.modal + $.fn.modal = Plugin + $.fn.modal.Constructor = Modal - // MODAL NO CONFLICT - // ================= - $.fn.modal.noConflict = function () { - $.fn.modal = old - return this - } + // MODAL NO CONFLICT + // ================= + $.fn.modal.noConflict = function () { + $.fn.modal = old + return this + } - // MODAL DATA-API - // ============== - $(document).on('click.bs.modal.data-api', '[data-toggle="modal"]', function (e) { - var $this = $(this) - var href = $this.attr('href') - var $target = $($this.attr('data-target') || (href && href.replace(/.*(?=#[^\s]+$)/, ''))) // strip for ie7 - var option = $target.data('bs.modal') ? 'toggle' : $.extend({ remote: !/#/.test(href) && href }, $target.data(), $this.data()) + // MODAL DATA-API + // ============== - if ($this.is('a')) e.preventDefault() + $(document).on('click.bs.modal.data-api', '[data-toggle="modal"]', function (e) { + var $this = $(this) + var href = $this.attr('href') + var $target = $($this.attr('data-target') || (href && href.replace(/.*(?=#[^\s]+$)/, ''))) // strip for ie7 + var option = $target.data('bs.modal') ? 'toggle' : $.extend({ remote: !/#/.test(href) && href }, $target.data(), $this.data()) - $target.one('show.bs.modal', function (showEvent) { - if (showEvent.isDefaultPrevented()) return // only register focus restorer if modal will actually get shown - $target.one('hidden.bs.modal', function () { - $this.is(':visible') && $this.trigger('focus') - }) + if ($this.is('a')) e.preventDefault() + + $target.one('show.bs.modal', function (showEvent) { + if (showEvent.isDefaultPrevented()) return // only register focus restorer if modal will actually get shown + $target.one('hidden.bs.modal', function () { + $this.is(':visible') && $this.trigger('focus') }) - Plugin.call($target, option, this) }) - + Plugin.call($target, option, this) }) -}(); +}(jQuery); |
