source: trip-planner-front/node_modules/bootstrap/js/modal.js@ fa375fe

Last change on this file since fa375fe was fa375fe, checked in by Ema <ema_spirova@…>, 3 years ago

adding new components

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