PluginProbe
Booking Calendar / 11.8.4
Booking Calendar v11.8.4
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 / vendors / _custom / dropdown_modal / _src / dropdown_modal.js

dropdown_modal.js in Booking Calendar 11.8.4, at vendors/_custom/dropdown_modal/_src/dropdown_modal.js

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