app/assets/javascripts/twitter/bootstrap/modal.js in bootstrap-sass-rails-2.3.2.1 vs app/assets/javascripts/twitter/bootstrap/modal.js in bootstrap-sass-rails-3.0.0.0.rc1

- old
+ new

@@ -1,9 +1,9 @@ -/* ========================================================= - * bootstrap-modal.js v2.3.2 - * http://twitter.github.com/bootstrap/javascript.html#modals - * ========================================================= +/* ======================================================================== + * Bootstrap: modal.js v3.0.0 + * http://twbs.github.com/bootstrap/javascript.html#modals + * ======================================================================== * Copyright 2012 Twitter, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,235 +13,229 @@ * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * ========================================================= */ + * ======================================================================== */ -!function ($) { ++function ($) { "use strict"; - "use strict"; // jshint ;_; + // MODAL CLASS DEFINITION + // ====================== + var Modal = function (element, options) { + this.options = options + this.$element = $(element).on('click.dismiss.modal', '[data-dismiss="modal"]', $.proxy(this.hide, this)) + this.$backdrop = + this.isShown = null - /* MODAL CLASS DEFINITION - * ====================== */ + if (this.options.remote) this.$element.find('.modal-body').load(this.options.remote) + } - var Modal = function (element, options) { - this.options = options - this.$element = $(element) - .delegate('[data-dismiss="modal"]', 'click.dismiss.modal', $.proxy(this.hide, this)) - this.options.remote && this.$element.find('.modal-body').load(this.options.remote) + Modal.DEFAULTS = { + backdrop: true + , keyboard: true + , show: true } - Modal.prototype = { + Modal.prototype.toggle = function () { + return this[!this.isShown ? 'show' : 'hide']() + } - constructor: Modal + Modal.prototype.show = function () { + var that = this + var e = $.Event('show.bs.modal') - , toggle: function () { - return this[!this.isShown ? 'show' : 'hide']() - } + this.$element.trigger(e) - , show: function () { - var that = this - , e = $.Event('show') + if (this.isShown || e.isDefaultPrevented()) return - this.$element.trigger(e) + this.isShown = true - if (this.isShown || e.isDefaultPrevented()) return + this.escape() - this.isShown = true + this.backdrop(function () { + var transition = $.support.transition && that.$element.hasClass('fade') - this.escape() + if (!that.$element.parent().length) { + that.$element.appendTo(document.body) // don't move modals dom position + } - this.backdrop(function () { - var transition = $.support.transition && that.$element.hasClass('fade') + that.$element.show() - if (!that.$element.parent().length) { - that.$element.appendTo(document.body) //don't move modals dom position - } - - that.$element.show() - - if (transition) { - that.$element[0].offsetWidth // force reflow - } - - that.$element - .addClass('in') - .attr('aria-hidden', false) - - that.enforceFocus() - - transition ? - that.$element.one($.support.transition.end, function () { that.$element.focus().trigger('shown') }) : - that.$element.focus().trigger('shown') - - }) + if (transition) { + that.$element[0].offsetWidth // force reflow } - , hide: function (e) { - e && e.preventDefault() + that.$element + .addClass('in') + .attr('aria-hidden', false) - var that = this + that.enforceFocus() - e = $.Event('hide') + transition ? + that.$element + .one($.support.transition.end, function () { + that.$element.focus().trigger('shown.bs.modal') + }) + .emulateTransitionEnd(300) : + that.$element.focus().trigger('shown.bs.modal') + }) + } - this.$element.trigger(e) + Modal.prototype.hide = function (e) { + if (e) e.preventDefault() - if (!this.isShown || e.isDefaultPrevented()) return + e = $.Event('hide.bs.modal') - this.isShown = false + this.$element.trigger(e) - this.escape() + if (!this.isShown || e.isDefaultPrevented()) return - $(document).off('focusin.modal') + this.isShown = false - this.$element - .removeClass('in') - .attr('aria-hidden', true) + this.escape() - $.support.transition && this.$element.hasClass('fade') ? - this.hideWithTransition() : - this.hideModal() - } + $(document).off('focusin.bs.modal') - , enforceFocus: function () { - var that = this - $(document).on('focusin.modal', function (e) { - if (that.$element[0] !== e.target && !that.$element.has(e.target).length) { - that.$element.focus() - } - }) - } + this.$element + .removeClass('in') + .attr('aria-hidden', true) - , escape: function () { - var that = this - if (this.isShown && this.options.keyboard) { - this.$element.on('keyup.dismiss.modal', function ( e ) { - e.which == 27 && that.hide() - }) - } else if (!this.isShown) { - this.$element.off('keyup.dismiss.modal') + $.support.transition && this.$element.hasClass('fade') ? + this.$element + .one($.support.transition.end, $.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.focus() } - } + }, this)) + } - , hideWithTransition: function () { - var that = this - , timeout = setTimeout(function () { - that.$element.off($.support.transition.end) - that.hideModal() - }, 500) + 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.one($.support.transition.end, function () { - clearTimeout(timeout) - that.hideModal() - }) - } + Modal.prototype.hideModal = function () { + var that = this + this.$element.hide() + this.backdrop(function () { + that.removeBackdrop() + that.$element.trigger('hidden.bs.modal') + }) + } - , hideModal: function () { - var that = this - this.$element.hide() - this.backdrop(function () { - that.removeBackdrop() - that.$element.trigger('hidden') - }) - } + Modal.prototype.removeBackdrop = function () { + this.$backdrop && this.$backdrop.remove() + this.$backdrop = null + } - , removeBackdrop: function () { - this.$backdrop && this.$backdrop.remove() - this.$backdrop = null - } + Modal.prototype.backdrop = function (callback) { + var that = this + var animate = this.$element.hasClass('fade') ? 'fade' : '' - , backdrop: function (callback) { - var that = this - , animate = this.$element.hasClass('fade') ? 'fade' : '' + if (this.isShown && this.options.backdrop) { + var doAnimate = $.support.transition && animate - if (this.isShown && this.options.backdrop) { - var doAnimate = $.support.transition && animate + this.$backdrop = $('<div class="modal-backdrop ' + animate + '" />') + .appendTo(document.body) - this.$backdrop = $('<div class="modal-backdrop ' + animate + '" />') - .appendTo(document.body) + this.$element.on('click', $.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.click( - this.options.backdrop == 'static' ? - $.proxy(this.$element[0].focus, this.$element[0]) - : $.proxy(this.hide, this) - ) + if (doAnimate) this.$backdrop[0].offsetWidth // force reflow - if (doAnimate) this.$backdrop[0].offsetWidth // force reflow + this.$backdrop.addClass('in') - this.$backdrop.addClass('in') + if (!callback) return - if (!callback) return + doAnimate ? + this.$backdrop + .one($.support.transition.end, callback) + .emulateTransitionEnd(150) : + callback() - doAnimate ? - this.$backdrop.one($.support.transition.end, callback) : - callback() + } else if (!this.isShown && this.$backdrop) { + this.$backdrop.removeClass('in') - } else if (!this.isShown && this.$backdrop) { - this.$backdrop.removeClass('in') + $.support.transition && this.$element.hasClass('fade')? + this.$backdrop + .one($.support.transition.end, callback) + .emulateTransitionEnd(150) : + callback() - $.support.transition && this.$element.hasClass('fade')? - this.$backdrop.one($.support.transition.end, callback) : - callback() - - } else if (callback) { - callback() - } - } + } else if (callback) { + callback() + } } - /* MODAL PLUGIN DEFINITION - * ======================= */ + // MODAL PLUGIN DEFINITION + // ======================= var old = $.fn.modal $.fn.modal = function (option) { return this.each(function () { - var $this = $(this) - , data = $this.data('modal') - , options = $.extend({}, $.fn.modal.defaults, $this.data(), typeof option == 'object' && option) - if (!data) $this.data('modal', (data = new Modal(this, options))) + var $this = $(this) + var data = $this.data('bs.modal') + var options = $.extend({}, Modal.DEFAULTS, $this.data(), typeof option == 'object' && option) + + if (!data) $this.data('bs.modal', (data = new Modal(this, options))) if (typeof option == 'string') data[option]() else if (options.show) data.show() }) } - $.fn.modal.defaults = { - backdrop: true - , keyboard: true - , show: true - } - $.fn.modal.Constructor = Modal - /* MODAL NO CONFLICT - * ================= */ + // MODAL NO CONFLICT + // ================= $.fn.modal.noConflict = function () { $.fn.modal = old return this } - /* MODAL DATA-API - * ============== */ + // MODAL DATA-API + // ============== - $(document).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()) + $(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('modal') ? 'toggle' : $.extend({ remote:!/#/.test(href) && href }, $target.data(), $this.data()) e.preventDefault() $target .modal(option) .one('hide', function () { - $this.focus() + $this.is(':visible') && $this.focus() }) }) + + var $body = $(document.body) + .on('shown.bs.modal', '.modal', function () { $body.addClass('modal-open') }) + .on('hidden.bs.modal', '.modal', function () { $body.removeClass('modal-open') }) }(window.jQuery);