PluginProbe
Booking Calendar / 10.1.3
Booking Calendar v10.1.3
11.8.4 11.8.3 11.8.2 11.8.1 11.8 11.7 11.6.1 11.6 11.5 11.4.3 11.4.2 11.4.1 11.4 11.3 11.2.1 11.2 11.1 11.0 10.15.7 10.15.6 10.1.3 10.10 10.10.1 10.10.2 10.11 All 204 releases
booking / assets / libs / ui / _src / dropdown_modal.js

dropdown_modal.js in Booking Calendar 10.1.3, at assets/libs/ui/_src/dropdown_modal.js

512 lines 15.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /*!
2 * Generated using the Bootstrap Customizer (http://getbootstrap.com/customize/?id=f4b4c9cb85df757ca08c)
3 * Config saved to config.json and https://gist.github.com/f4b4c9cb85df757ca08c
4 */
5 if (typeof jQuery === 'undefined') {
6 throw new Error('Bootstrap\'s JavaScript requires jQuery')
7 }
8 +function ($) {
9 'use strict';
10 var version = $.fn.jquery.split(' ')[0].split('.')
11 if ((version[0] < 2 && version[1] < 9) || (version[0] == 1 && version[1] == 9 && version[2] < 1)) {
12 throw new Error('Bootstrap\'s JavaScript requires jQuery version 1.9.1 or higher')
13 }
14 }(jQuery);
15
16 /* ========================================================================
17 * Bootstrap: modal.js v3.3.5
18 * http://getbootstrap.com/javascript/#modals
19 * ========================================================================
20 * Copyright 2011-2015 Twitter, Inc.
21 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
22 * ======================================================================== */
23
24
25 +function ($) {
26 'use strict';
27
28 // MODAL CLASS DEFINITION
29 // ======================
30
31 var Modal = function (element, options) {
32 this.options = options
33 this.$body = $(document.body)
34 this.$element = $(element)
35 this.$dialog = this.$element.find('.modal-dialog')
36 this.$backdrop = null
37 this.isShown = null
38 this.originalBodyPad = null
39 this.scrollbarWidth = 0
40 this.ignoreBackdropClick = false
41
42 if (this.options.remote) {
43 this.$element
44 .find('.modal-content')
45 .load(this.options.remote, $.proxy(function () {
46 this.$element.trigger('loaded.wpbc.modal')
47 }, this))
48 }
49 }
50
51 Modal.VERSION = '3.3.5'
52
53 Modal.TRANSITION_DURATION = 300
54 Modal.BACKDROP_TRANSITION_DURATION = 150
55
56 Modal.DEFAULTS = {
57 backdrop: true,
58 keyboard: true,
59 show: true
60 }
61
62 Modal.prototype.toggle = function (_relatedTarget) {
63 return this.isShown ? this.hide() : this.show(_relatedTarget)
64 }
65
66 Modal.prototype.show = function (_relatedTarget) {
67 var that = this
68 var e = $.Event('show.wpbc.modal', { relatedTarget: _relatedTarget })
69
70 this.$element.trigger(e)
71
72 if (this.isShown || e.isDefaultPrevented()) return
73
74 this.isShown = true
75
76 this.checkScrollbar()
77 this.setScrollbar()
78 this.$body.addClass('modal-open')
79
80 this.escape()
81 this.resize()
82
83 this.$element.on('click.dismiss.wpbc.modal', '[data-dismiss="modal"]', $.proxy(this.hide, this))
84
85 this.$dialog.on('mousedown.dismiss.wpbc.modal', function () {
86 that.$element.one('mouseup.dismiss.wpbc.modal', function (e) {
87 if ($(e.target).is(that.$element)) that.ignoreBackdropClick = true
88 })
89 })
90
91 this.backdrop(function () {
92 var transition = $.support.transition && that.$element.hasClass('fade')
93
94 if (!that.$element.parent().length) {
95 that.$element.appendTo(that.$body) // don't move modals dom position
96 }
97
98 that.$element
99 .show()
100 .scrollTop(0)
101
102 that.adjustDialog()
103
104 if (transition) {
105 that.$element[0].offsetWidth // force reflow
106 }
107
108 that.$element.addClass('in')
109
110 that.enforceFocus()
111
112 var e = $.Event('shown.wpbc.modal', { relatedTarget: _relatedTarget })
113
114 transition ?
115 that.$dialog // wait for modal to slide in
116 .one('bsTransitionEnd', function () {
117 that.$element.trigger('focus').trigger(e)
118 })
119 .emulateTransitionEnd(Modal.TRANSITION_DURATION) :
120 that.$element.trigger('focus').trigger(e)
121 })
122 }
123
124 Modal.prototype.hide = function (e) {
125 if (e) e.preventDefault()
126
127 e = $.Event('hide.wpbc.modal')
128
129 this.$element.trigger(e)
130
131 if (!this.isShown || e.isDefaultPrevented()) return
132
133 this.isShown = false
134
135 this.escape()
136 this.resize()
137
138 $(document).off('focusin.wpbc.modal')
139
140 this.$element
141 .removeClass('in')
142 .off('click.dismiss.wpbc.modal')
143 .off('mouseup.dismiss.wpbc.modal')
144
145 this.$dialog.off('mousedown.dismiss.wpbc.modal')
146
147 $.support.transition && this.$element.hasClass('fade') ?
148 this.$element
149 .one('bsTransitionEnd', $.proxy(this.hideModal, this))
150 .emulateTransitionEnd(Modal.TRANSITION_DURATION) :
151 this.hideModal()
152 }
153
154 Modal.prototype.enforceFocus = function () {
155 $(document)
156 .off('focusin.wpbc.modal') // guard against infinite focus loop
157 .on('focusin.wpbc.modal', $.proxy(function (e) {
158 if (this.$element[0] !== e.target && !this.$element.has(e.target).length) {
159 this.$element.trigger('focus')
160 }
161 }, this))
162 }
163
164 Modal.prototype.escape = function () {
165 if (this.isShown && this.options.keyboard) {
166 this.$element.on('keydown.dismiss.wpbc.modal', $.proxy(function (e) {
167 e.which == 27 && this.hide()
168 }, this))
169 } else if (!this.isShown) {
170 this.$element.off('keydown.dismiss.wpbc.modal')
171 }
172 }
173
174 Modal.prototype.resize = function () {
175 if (this.isShown) {
176 $(window).on('resize.wpbc.modal', $.proxy(this.handleUpdate, this))
177 } else {
178 $(window).off('resize.wpbc.modal')
179 }
180 }
181
182 Modal.prototype.hideModal = function () {
183 var that = this
184 this.$element.hide()
185 this.backdrop(function () {
186 that.$body.removeClass('modal-open')
187 that.resetAdjustments()
188 that.resetScrollbar()
189 that.$element.trigger('hidden.wpbc.modal')
190 })
191 }
192
193 Modal.prototype.removeBackdrop = function () {
194 this.$backdrop && this.$backdrop.remove()
195 this.$backdrop = null
196 }
197
198 Modal.prototype.backdrop = function (callback) {
199 var that = this
200 var animate = this.$element.hasClass('fade') ? 'fade' : ''
201
202 if (this.isShown && this.options.backdrop) {
203 var doAnimate = $.support.transition && animate
204
205 this.$backdrop = $(document.createElement('div'))
206 .addClass('modal-backdrop ' + animate)
207 .appendTo(this.$body)
208
209 this.$element.on('click.dismiss.wpbc.modal', $.proxy(function (e) {
210 if (this.ignoreBackdropClick) {
211 this.ignoreBackdropClick = false
212 return
213 }
214 if (e.target !== e.currentTarget) return
215 this.options.backdrop == 'static'
216 ? this.$element[0].focus()
217 : this.hide()
218 }, this))
219
220 if (doAnimate) this.$backdrop[0].offsetWidth // force reflow
221
222 this.$backdrop.addClass('in')
223
224 if (!callback) return
225
226 doAnimate ?
227 this.$backdrop
228 .one('bsTransitionEnd', callback)
229 .emulateTransitionEnd(Modal.BACKDROP_TRANSITION_DURATION) :
230 callback()
231
232 } else if (!this.isShown && this.$backdrop) {
233 this.$backdrop.removeClass('in')
234
235 var callbackRemove = function () {
236 that.removeBackdrop()
237 callback && callback()
238 }
239 $.support.transition && this.$element.hasClass('fade') ?
240 this.$backdrop
241 .one('bsTransitionEnd', callbackRemove)
242 .emulateTransitionEnd(Modal.BACKDROP_TRANSITION_DURATION) :
243 callbackRemove()
244
245 } else if (callback) {
246 callback()
247 }
248 }
249
250 // these following methods are used to handle overflowing modals
251
252 Modal.prototype.handleUpdate = function () {
253 this.adjustDialog()
254 }
255
256 Modal.prototype.adjustDialog = function () {
257 var modalIsOverflowing = this.$element[0].scrollHeight > document.documentElement.clientHeight
258
259 this.$element.css({
260 paddingLeft: !this.bodyIsOverflowing && modalIsOverflowing ? this.scrollbarWidth : '',
261 paddingRight: this.bodyIsOverflowing && !modalIsOverflowing ? this.scrollbarWidth : ''
262 })
263 }
264
265 Modal.prototype.resetAdjustments = function () {
266 this.$element.css({
267 paddingLeft: '',
268 paddingRight: ''
269 })
270 }
271
272 Modal.prototype.checkScrollbar = function () {
273 var fullWindowWidth = window.innerWidth
274 if (!fullWindowWidth) { // workaround for missing window.innerWidth in IE8
275 var documentElementRect = document.documentElement.getBoundingClientRect()
276 fullWindowWidth = documentElementRect.right - Math.abs(documentElementRect.left)
277 }
278 this.bodyIsOverflowing = document.body.clientWidth < fullWindowWidth
279 this.scrollbarWidth = this.measureScrollbar()
280 }
281
282 Modal.prototype.setScrollbar = function () {
283 var bodyPad = parseInt((this.$body.css('padding-right') || 0), 10)
284 this.originalBodyPad = document.body.style.paddingRight || ''
285 if (this.bodyIsOverflowing) this.$body.css('padding-right', bodyPad + this.scrollbarWidth)
286 }
287
288 Modal.prototype.resetScrollbar = function () {
289 this.$body.css('padding-right', this.originalBodyPad)
290 }
291
292 Modal.prototype.measureScrollbar = function () { // thx walsh
293 var scrollDiv = document.createElement('div')
294 scrollDiv.className = 'modal-scrollbar-measure'
295 this.$body.append(scrollDiv)
296 var scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth
297 this.$body[0].removeChild(scrollDiv)
298 return scrollbarWidth
299 }
300
301
302 // MODAL PLUGIN DEFINITION
303 // =======================
304
305 function Plugin(option, _relatedTarget) {
306 return this.each(function () {
307 var $this = $(this)
308 var data = $this.data('wpbc.modal')
309 var options = $.extend({}, Modal.DEFAULTS, $this.data(), typeof option == 'object' && option)
310
311 if (!data) $this.data('wpbc.modal', (data = new Modal(this, options)))
312 if (typeof option == 'string') data[option](_relatedTarget)
313 else if (options.show) data.show(_relatedTarget)
314 })
315 }
316
317 var old = $.fn.wpbc_my_modal
318
319 $.fn.wpbc_my_modal = Plugin
320 $.fn.wpbc_my_modal.Constructor = Modal
321
322
323 // MODAL NO CONFLICT
324 // =================
325
326 $.fn.wpbc_my_modal.noConflict = function () {
327 $.fn.wpbc_my_modal = old
328 return this
329 }
330
331
332 // MODAL DATA-API
333 // ==============
334
335 $(document).on('click.wpbc.modal.data-api', '[data-toggle="wpbc_my_modal"]', function (e) {
336 var $this = $(this)
337 var href = $this.attr('href')
338 var $target = $($this.attr('data-target') || (href && href.replace(/.*(?=#[^\s]+$)/, ''))) // strip for ie7
339 var option = $target.data('wpbc.modal') ? 'toggle' : $.extend({ remote: !/#/.test(href) && href }, $target.data(), $this.data())
340
341 if ($this.is('a')) e.preventDefault()
342
343 $target.one('show.wpbc.modal', function (showEvent) {
344 if (showEvent.isDefaultPrevented()) return // only register focus restorer if modal will actually get shown
345 $target.one('hidden.wpbc.modal', function () {
346 $this.is(':visible') && $this.trigger('focus')
347 })
348 })
349 Plugin.call($target, option, this)
350 })
351
352 }(jQuery);
353
354
355 +function ($) {
356 'use strict';
357
358 // DROPDOWN CLASS DEFINITION
359 // =========================
360
361 var backdrop = '.dropdown-backdrop'
362 var toggle = '[data-toggle="wpbc_dropdown"]'
363 var Dropdown = function (element) {
364 $(element).on('click.wpbc.dropdown', this.toggle)
365 }
366
367 Dropdown.VERSION = '3.3.5'
368
369 function getParent($this) {
370 var selector = $this.attr('data-target')
371
372 if (!selector) {
373 selector = $this.attr('href')
374 selector = selector && /#[A-Za-z]/.test(selector) && selector.replace(/.*(?=#[^\s]*$)/, '') // strip for ie7
375 }
376
377 var $parent = selector && $(selector)
378
379 return $parent && $parent.length ? $parent : $this.parent()
380 }
381
382 function clearMenus(e) {
383 if (e && e.which === 3) return
384 $(backdrop).remove()
385 $(toggle).each(function () {
386 var $this = $(this)
387 var $parent = getParent($this)
388 var relatedTarget = { relatedTarget: this }
389
390 if (!$parent.hasClass('open')) return
391
392 if (e && e.type == 'click' && /input|textarea/i.test(e.target.tagName) && $.contains($parent[0], e.target)) return
393
394 $parent.trigger(e = $.Event('hide.wpbc.dropdown', relatedTarget))
395
396 if (e.isDefaultPrevented()) return
397
398 $this.attr('aria-expanded', 'false')
399 $parent.removeClass('open').trigger('hidden.wpbc.dropdown', relatedTarget)
400 })
401 }
402
403 Dropdown.prototype.toggle = function (e) {
404 var $this = $(this)
405
406 if ($this.is('.disabled, :disabled')) return
407
408 var $parent = getParent($this)
409 var isActive = $parent.hasClass('open')
410
411 clearMenus()
412
413 if (!isActive) {
414 if ('ontouchstart' in document.documentElement && !$parent.closest('.navbar-nav').length) {
415 // if mobile we use a backdrop because click events don't delegate
416 $(document.createElement('div'))
417 .addClass('dropdown-backdrop')
418 .insertAfter($(this))
419 .on('click', clearMenus)
420 }
421
422 var relatedTarget = { relatedTarget: this }
423 $parent.trigger(e = $.Event('show.wpbc.dropdown', relatedTarget))
424
425 if (e.isDefaultPrevented()) return
426
427 $this
428 .trigger('focus')
429 .attr('aria-expanded', 'true')
430
431 $parent
432 .toggleClass('open')
433 .trigger('shown.wpbc.dropdown', relatedTarget)
434 }
435
436 return false
437 }
438
439 Dropdown.prototype.keydown = function (e) {
440 if (!/(38|40|27|32)/.test(e.which) || /input|textarea/i.test(e.target.tagName)) return
441
442 var $this = $(this)
443
444 e.preventDefault()
445 e.stopPropagation()
446
447 if ($this.is('.disabled, :disabled')) return
448
449 var $parent = getParent($this)
450 var isActive = $parent.hasClass('open')
451
452 if (!isActive && e.which != 27 || isActive && e.which == 27) {
453 if (e.which == 27) $parent.find(toggle).trigger('focus')
454 return $this.trigger('click')
455 }
456
457 var desc = ' li:not(.disabled):visible a'
458 var $items = $parent.find('.dropdown-menu' + desc + ',.ui_dropdown_menu' + desc)
459
460 if (!$items.length) return
461
462 var index = $items.index(e.target)
463
464 if (e.which == 38 && index > 0) index-- // up
465 if (e.which == 40 && index < $items.length - 1) index++ // down
466 if (!~index) index = 0
467
468 $items.eq(index).trigger('focus')
469 }
470
471
472 // DROPDOWN PLUGIN DEFINITION
473 // ==========================
474
475 function Plugin(option) {
476 return this.each(function () {
477 var $this = $(this)
478 var data = $this.data('wpbc.dropdown')
479
480 if (!data) $this.data('wpbc.dropdown', (data = new Dropdown(this)))
481 if (typeof option == 'string') data[option].call($this)
482 })
483 }
484
485 var old = $.fn.wpbc_dropdown
486
487 $.fn.wpbc_dropdown = Plugin
488 $.fn.wpbc_dropdown.Constructor = Dropdown
489
490
491 // DROPDOWN NO CONFLICT
492 // ====================
493
494 $.fn.wpbc_dropdown.noConflict = function () {
495 $.fn.wpbc_dropdown = old
496 return this
497 }
498
499
500 // APPLY TO STANDARD DROPDOWN ELEMENTS
501 // ===================================
502
503 $(document)
504 .on('click.wpbc.dropdown.data-api', clearMenus)
505 .on('click.wpbc.dropdown.data-api', '.dropdown form', function (e) { e.stopPropagation() })
506 .on('click.wpbc.dropdown.data-api', toggle, Dropdown.prototype.toggle)
507 .on('keydown.wpbc.dropdown.data-api', toggle, Dropdown.prototype.keydown)
508 .on('keydown.wpbc.dropdown.data-api', '.dropdown-menu', Dropdown.prototype.keydown)
509 .on('keydown.wpbc.dropdown.data-api', '.ui_dropdown_menu', Dropdown.prototype.keydown)
510
511 }(jQuery);
512