vendor: 4,392 bytes, lines 1-145
1;(function ($) { 2 'use strict'; 3 4 // MODAL CLASS DEFINITION 5 // ====================== 6 7 var Modal = function (element, options) { 8 this.options = options 9 this.$body = $(document.body) 10 this.$element = $(element) 11 this.$dialog = this.$element.find('.modal-dialog') 12 this.$backdrop = null 13 this.isShown = null 14 this.originalBodyPad = null 15 this.scrollbarWidth = 0 16 this.ignoreBackdropClick = false 17 this.fixedContent = '.navbar-fixed-top, .navbar-fixed-bottom' 18 19 if (this.options.remote) { 20 this.$element 21 .find('.modal-content') 22 .load(this.options.remote, $.proxy(function () { 23 this.$element.trigger('loaded.bs.modal') 24 }, this)) 25 } 26 } 27 28 Modal.VERSION = '3.4.1' 29 30 Modal.TRANSITION_DURATION = 300 31 Modal.BACKDROP_TRANSITION_DURATION = 150 32 33 Modal.DEFAULTS = { 34 backdrop: true, 35 keyboard: true, 36 show: true 37 } 38 39 Modal.prototype.toggle = function (_relatedTarget) { 40 return this.isShown ? this.hide() : this.show(_relatedTarget) 41 } 42 43 Modal.prototype.show = function (_relatedTarget) { 44 var that = this 45 var e = $.Event('show.bs.modal', { relatedTarget: _relatedTarget }) 46 47 this.$element.trigger(e) 48 49 if (this.isShown || e.isDefaultPrevented()) return 50 51 this.isShown = true 52 53 this.checkScrollbar() 54 this.setScrollbar() 55 this.$body.addClass('modal-open') 56 57 this.escape() 58 this.resize() 59 60 this.$element.on('click.dismiss.bs.modal', '[data-dismiss="modal"]', $.proxy(this.hide, this)) 61 62 this.$dialog.on('mousedown.dismiss.bs.modal', function () { 63 that.$element.one('mouseup.dismiss.bs.modal', function (e) { 64 if ($(e.target).is(that.$element)) that.ignoreBackdropClick = true 65 }) 66 }) 67 68 this.backdrop(function () { 69 var transition = $.support.transition && that.$element.hasClass('fade') 70 71 if (!that.$element.parent().length) { 72 that.$element.appendTo(that.$body) // don't move modals dom position 73 } 74 75 that.$element 76 .show() 77 .scrollTop(0) 78 79 that.adjustDialog() 80 81 if (transition) { 82 that.$element[0].offsetWidth // force reflow 83 } 84 85 that.$element.addClass('in') 86 87 that.enforceFocus() 88 89 var e = $.Event('shown.bs.modal', { relatedTarget: _relatedTarget }) 90 91 transition ? 92 that.$dialog // wait for modal to slide in 93 .one('bsTransitionEnd', function () { 94 that.$element.trigger('focus').trigger(e) 95 }) 96 .emulateTransitionEnd(Modal.TRANSITION_DURATION) : 97 that.$element.trigger('focus').trigger(e) 98 }) 99 } 100 101 Modal.prototype.hide = function (e) { 102 if (e) e.preventDefault() 103 104 e = $.Event('hide.bs.modal') 105 106 this.$element.trigger(e) 107 108 if (!this.isShown || e.isDefaultPrevented()) return 109 110 this.isShown = false 111 112 this.escape() 113 this.resize() 114 115 $(document).off('focusin.bs.modal') 116 117 this.$element 118 .removeClass('in') 119 .off('click.dismiss.bs.modal') 120 .off('mouseup.dismiss.bs.modal') 121 122 this.$dialog.off('mousedown.dismiss.bs.modal') 123 124 $.support.transition && this.$element.hasClass('fade') ? 125 this.$element 126 .one('bsTransitionEnd', $.proxy(this.hideModal, this)) 127 .emulateTransitionEnd(Modal.TRANSITION_DURATION) : 128 this.hideModal() 129 } 130 131 Modal.prototype.enforceFocus = function () { 132 $(document) 133 .off('focusin.bs.modal') // guard against infinite focus loop 134 .on('focusin.bs.modal', $.proxy(function (e) { 135 if (document !== e.target && 136 this.$element[0] !== e.target && 137 !this.$element.has(e.target).length) { 138 this.$element.trigger('focus') 139 } 140 }, this)) 141 } 142 143 Modal.prototype.escape = function () { 144 if (this.isShown && this.options.keyboard) { 145 this.$element.on('keydown.dismiss.bs.modal', $.proxy(function (e) {
vendor: 7,256 bytes, lines 146-354
146 e.which == 27 && this.hide() 147 }, this)) 148 } else if (!this.isShown) { 149 this.$element.off('keydown.dismiss.bs.modal') 150 } 151 } 152 153 Modal.prototype.resize = function () { 154 if (this.isShown) { 155 $(window).on('resize.bs.modal', $.proxy(this.handleUpdate, this)) 156 } else { 157 $(window).off('resize.bs.modal') 158 } 159 } 160 161 Modal.prototype.hideModal = function () { 162 var that = this 163 this.$element.hide() 164 this.backdrop(function () { 165 that.$body.removeClass('modal-open') 166 that.resetAdjustments() 167 that.resetScrollbar() 168 that.$element.trigger('hidden.bs.modal') 169 }) 170 } 171 172 Modal.prototype.removeBackdrop = function () { 173 this.$backdrop && this.$backdrop.remove() 174 this.$backdrop = null 175 } 176 177 Modal.prototype.backdrop = function (callback) { 178 var that = this 179 var animate = this.$element.hasClass('fade') ? 'fade' : '' 180 181 if (this.isShown && this.options.backdrop) { 182 var doAnimate = $.support.transition && animate 183 184 this.$backdrop = $(document.createElement('div')) 185 .addClass('modal-backdrop ' + animate) 186 .appendTo(this.$body) 187 188 this.$element.on('click.dismiss.bs.modal', $.proxy(function (e) { 189 if (this.ignoreBackdropClick) { 190 this.ignoreBackdropClick = false 191 return 192 } 193 if (e.target !== e.currentTarget) return 194 this.options.backdrop == 'static' 195 ? this.$element[0].focus() 196 : this.hide() 197 }, this)) 198 199 if (doAnimate) this.$backdrop[0].offsetWidth // force reflow 200 201 this.$backdrop.addClass('in') 202 203 if (!callback) return 204 205 doAnimate ? 206 this.$backdrop 207 .one('bsTransitionEnd', callback) 208 .emulateTransitionEnd(Modal.BACKDROP_TRANSITION_DURATION) : 209 callback() 210 211 } else if (!this.isShown && this.$backdrop) { 212 this.$backdrop.removeClass('in') 213 214 var callbackRemove = function () { 215 that.removeBackdrop() 216 callback && callback() 217 } 218 $.support.transition && this.$element.hasClass('fade') ? 219 this.$backdrop 220 .one('bsTransitionEnd', callbackRemove) 221 .emulateTransitionEnd(Modal.BACKDROP_TRANSITION_DURATION) : 222 callbackRemove() 223 224 } else if (callback) { 225 callback() 226 } 227 } 228 229 // these following methods are used to handle overflowing modals 230 231 Modal.prototype.handleUpdate = function () { 232 this.adjustDialog() 233 } 234 235 Modal.prototype.adjustDialog = function () { 236 var modalIsOverflowing = this.$element[0].scrollHeight > document.documentElement.clientHeight 237 238 this.$element.css({ 239 paddingLeft: !this.bodyIsOverflowing && modalIsOverflowing ? this.scrollbarWidth : '', 240 paddingRight: this.bodyIsOverflowing && !modalIsOverflowing ? this.scrollbarWidth : '' 241 }) 242 } 243 244 Modal.prototype.resetAdjustments = function () { 245 this.$element.css({ 246 paddingLeft: '', 247 paddingRight: '' 248 }) 249 } 250 251 Modal.prototype.checkScrollbar = function () { 252 var fullWindowWidth = window.innerWidth 253 if (!fullWindowWidth) { // workaround for missing window.innerWidth in IE8 254 var documentElementRect = document.documentElement.getBoundingClientRect() 255 fullWindowWidth = documentElementRect.right - Math.abs(documentElementRect.left) 256 } 257 this.bodyIsOverflowing = document.body.clientWidth < fullWindowWidth 258 this.scrollbarWidth = this.measureScrollbar() 259 } 260 261 Modal.prototype.setScrollbar = function () { 262 var bodyPad = parseInt((this.$body.css('padding-right') || 0), 10) 263 this.originalBodyPad = document.body.style.paddingRight || '' 264 var scrollbarWidth = this.scrollbarWidth 265 if (this.bodyIsOverflowing) { 266 this.$body.css('padding-right', bodyPad + scrollbarWidth) 267 $(this.fixedContent).each(function (index, element) { 268 var actualPadding = element.style.paddingRight 269 var calculatedPadding = $(element).css('padding-right') 270 $(element) 271 .data('padding-right', actualPadding) 272 .css('padding-right', parseFloat(calculatedPadding) + scrollbarWidth + 'px') 273 }) 274 } 275 } 276 277 Modal.prototype.resetScrollbar = function () { 278 this.$body.css('padding-right', this.originalBodyPad) 279 $(this.fixedContent).each(function (index, element) { 280 var padding = $(element).data('padding-right') 281 $(element).removeData('padding-right') 282 element.style.paddingRight = padding ? padding : '' 283 }) 284 } 285 286 Modal.prototype.measureScrollbar = function () { // thx walsh 287 var scrollDiv = document.createElement('div') 288 scrollDiv.className = 'modal-scrollbar-measure' 289 this.$body.append(scrollDiv) 290 var scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth 291 this.$body[0].removeChild(scrollDiv) 292 return scrollbarWidth 293 } 294 295 296 // MODAL PLUGIN DEFINITION 297 // ======================= 298 299 function Plugin(option, _relatedTarget) { 300 return this.each(function () { 301 var $this = $(this) 302 var data = $this.data('bs.modal') 303 var options = $.extend({}, Modal.DEFAULTS, $this.data(), typeof option == 'object' && option) 304 305 if (!data) $this.data('bs.modal', (data = new Modal(this, options))) 306 if (typeof option == 'string') data[option](_relatedTarget) 307 else if (options.show) data.show(_relatedTarget) 308 }) 309 } 310 311 var old = $.fn.modal 312 313 $.fn.modal = Plugin 314 $.fn.modal.Constructor = Modal 315 316 317 // MODAL NO CONFLICT 318 // ================= 319 320 $.fn.modal.noConflict = function () { 321 $.fn.modal = old 322 return this 323 } 324 325 326 // MODAL DATA-API 327 // ============== 328 329 $(document).on('click.bs.modal.data-api', '[data-toggle="modal"]', function (e) { 330 var $this = $(this) 331 var href = $this.attr('href') 332 var target = $this.attr('data-target') || 333 (href && href.replace(/.*(?=#[^\s]+$)/, '')) // strip for ie7 334 335 var $target = $(document).find(target) 336 337 // var option = $target.data('bs.modal') ? 'toggle' : $.extend({ remote: !/#/.test(href) && href }, $target.data(), $this.data()) 338 var option = $target.data('bs.modal') ? 'toggle' : $.extend({ remote: false }, $target.data(), $this.data()) 339 340 341 if ($this.is('a')) e.preventDefault() 342 343 $target.one('show.bs.modal', function (showEvent) { 344 if (showEvent.isDefaultPrevented()) return // only register focus restorer if modal will actually get shown 345 $target.one('hidden.bs.modal', function () { 346 $this.is(':visible') && $this.trigger('focus') 347 }) 348 }) 349 350 351 Plugin.call($target, option, this) 352 }) 353 354}(jQuery));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.