File indexing completed on 2024-12-22 05:33:16
0001 /* ========================================================= 0002 * bootstrap-modal.js v2.0.4 0003 * http://twitter.github.com/bootstrap/javascript.html#modals 0004 * ========================================================= 0005 * Copyright 2012 Twitter, Inc. 0006 * 0007 * Licensed under the Apache License, Version 2.0 (the "License"); 0008 * you may not use this file except in compliance with the License. 0009 * You may obtain a copy of the License at 0010 * 0011 * http://www.apache.org/licenses/LICENSE-2.0 0012 * 0013 * Unless required by applicable law or agreed to in writing, software 0014 * distributed under the License is distributed on an "AS IS" BASIS, 0015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 0016 * See the License for the specific language governing permissions and 0017 * limitations under the License. 0018 * ========================================================= */ 0019 0020 0021 !function ($) { 0022 0023 "use strict"; // jshint ;_; 0024 0025 0026 /* MODAL CLASS DEFINITION 0027 * ====================== */ 0028 0029 var Modal = function (content, options) { 0030 this.options = options 0031 this.$element = $(content) 0032 .delegate('[data-dismiss="modal"]', 'click.dismiss.modal', $.proxy(this.hide, this)) 0033 } 0034 0035 Modal.prototype = { 0036 0037 constructor: Modal 0038 0039 , toggle: function () { 0040 return this[!this.isShown ? 'show' : 'hide']() 0041 } 0042 0043 , show: function () { 0044 var that = this 0045 , e = $.Event('show') 0046 0047 this.$element.trigger(e) 0048 0049 if (this.isShown || e.isDefaultPrevented()) return 0050 0051 $('body').addClass('modal-open') 0052 0053 this.isShown = true 0054 0055 escape.call(this) 0056 backdrop.call(this, function () { 0057 var transition = $.support.transition && that.$element.hasClass('fade') 0058 0059 if (!that.$element.parent().length) { 0060 that.$element.appendTo(document.body) //don't move modals dom position 0061 } 0062 0063 that.$element 0064 .show() 0065 0066 if (transition) { 0067 that.$element[0].offsetWidth // force reflow 0068 } 0069 0070 that.$element.addClass('in') 0071 0072 transition ? 0073 that.$element.one($.support.transition.end, function () { that.$element.trigger('shown') }) : 0074 that.$element.trigger('shown') 0075 0076 }) 0077 } 0078 0079 , hide: function (e) { 0080 e && e.preventDefault() 0081 0082 var that = this 0083 0084 e = $.Event('hide') 0085 0086 this.$element.trigger(e) 0087 0088 if (!this.isShown || e.isDefaultPrevented()) return 0089 0090 this.isShown = false 0091 0092 $('body').removeClass('modal-open') 0093 0094 escape.call(this) 0095 0096 this.$element.removeClass('in') 0097 0098 $.support.transition && this.$element.hasClass('fade') ? 0099 hideWithTransition.call(this) : 0100 hideModal.call(this) 0101 } 0102 0103 } 0104 0105 0106 /* MODAL PRIVATE METHODS 0107 * ===================== */ 0108 0109 function hideWithTransition() { 0110 var that = this 0111 , timeout = setTimeout(function () { 0112 that.$element.off($.support.transition.end) 0113 hideModal.call(that) 0114 }, 500) 0115 0116 this.$element.one($.support.transition.end, function () { 0117 clearTimeout(timeout) 0118 hideModal.call(that) 0119 }) 0120 } 0121 0122 function hideModal(that) { 0123 this.$element 0124 .hide() 0125 .trigger('hidden') 0126 0127 backdrop.call(this) 0128 } 0129 0130 function backdrop(callback) { 0131 var that = this 0132 , animate = this.$element.hasClass('fade') ? 'fade' : '' 0133 0134 if (this.isShown && this.options.backdrop) { 0135 var doAnimate = $.support.transition && animate 0136 0137 this.$backdrop = $('<div class="modal-backdrop ' + animate + '" />') 0138 .appendTo(document.body) 0139 0140 if (this.options.backdrop != 'static') { 0141 this.$backdrop.click($.proxy(this.hide, this)) 0142 } 0143 0144 if (doAnimate) this.$backdrop[0].offsetWidth // force reflow 0145 0146 this.$backdrop.addClass('in') 0147 0148 doAnimate ? 0149 this.$backdrop.one($.support.transition.end, callback) : 0150 callback() 0151 0152 } else if (!this.isShown && this.$backdrop) { 0153 this.$backdrop.removeClass('in') 0154 0155 $.support.transition && this.$element.hasClass('fade')? 0156 this.$backdrop.one($.support.transition.end, $.proxy(removeBackdrop, this)) : 0157 removeBackdrop.call(this) 0158 0159 } else if (callback) { 0160 callback() 0161 } 0162 } 0163 0164 function removeBackdrop() { 0165 this.$backdrop.remove() 0166 this.$backdrop = null 0167 } 0168 0169 function escape() { 0170 var that = this 0171 if (this.isShown && this.options.keyboard) { 0172 $(document).on('keyup.dismiss.modal', function ( e ) { 0173 e.which == 27 && that.hide() 0174 }) 0175 } else if (!this.isShown) { 0176 $(document).off('keyup.dismiss.modal') 0177 } 0178 } 0179 0180 0181 /* MODAL PLUGIN DEFINITION 0182 * ======================= */ 0183 0184 $.fn.modal = function (option) { 0185 return this.each(function () { 0186 var $this = $(this) 0187 , data = $this.data('modal') 0188 , options = $.extend({}, $.fn.modal.defaults, $this.data(), typeof option == 'object' && option) 0189 if (!data) $this.data('modal', (data = new Modal(this, options))) 0190 if (typeof option == 'string') data[option]() 0191 else if (options.show) data.show() 0192 }) 0193 } 0194 0195 $.fn.modal.defaults = { 0196 backdrop: true 0197 , keyboard: true 0198 , show: true 0199 } 0200 0201 $.fn.modal.Constructor = Modal 0202 0203 0204 /* MODAL DATA-API 0205 * ============== */ 0206 0207 $(function () { 0208 $('body').on('click.modal.data-api', '[data-toggle="modal"]', function ( e ) { 0209 var $this = $(this), href 0210 , $target = $($this.attr('data-target') || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7 0211 , option = $target.data('modal') ? 'toggle' : $.extend({}, $target.data(), $this.data()) 0212 0213 e.preventDefault() 0214 $target.modal(option) 0215 }) 0216 }) 0217 0218 }(window.jQuery);