2015-01-03 22:58:44 +01:00
|
|
|
/** =======================================================================
|
|
|
|
* Bootstrap: dropdown.js v4.0.0
|
|
|
|
* http://getbootstrap.com/javascript/#dropdown
|
2013-05-22 04:30:33 +02:00
|
|
|
* ========================================================================
|
2015-01-01 01:23:48 +01:00
|
|
|
* Copyright 2011-2015 Twitter, Inc.
|
2013-12-19 00:28:08 +01:00
|
|
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
|
2015-01-03 22:58:44 +01:00
|
|
|
* ========================================================================
|
|
|
|
* @fileoverview - Add dropdown menus to nearly anything with this simple
|
|
|
|
* plugin, including the navbar, tabs, and pills.
|
|
|
|
*
|
|
|
|
* Public Methods & Properties:
|
|
|
|
*
|
|
|
|
* + $.dropdown
|
|
|
|
* + $.dropdown.noConflict
|
|
|
|
* + $.dropdown.Constructor
|
|
|
|
* + $.dropdown.Constructor.VERSION
|
|
|
|
* + $.dropdown.Constructor.prototype.toggle
|
|
|
|
*
|
|
|
|
* ========================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Our dropdown class.
|
|
|
|
* @param {Element!} element
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
var Dropdown = function (element) {
|
|
|
|
$(element).on('click.bs.dropdown', this['toggle'])
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @const
|
|
|
|
* @type {string}
|
|
|
|
*/
|
|
|
|
Dropdown['VERSION'] = '4.0.0'
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @const
|
|
|
|
* @type {string}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Dropdown._NAME = 'dropdown'
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @const
|
|
|
|
* @type {string}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Dropdown._DATA_KEY = 'bs.dropdown'
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @const
|
|
|
|
* @type {Function}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Dropdown._JQUERY_NO_CONFLICT = $.fn[Dropdown._NAME]
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @const
|
|
|
|
* @enum {string}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Dropdown._Event = {
|
|
|
|
HIDE : 'hide.bs.dropdown',
|
|
|
|
HIDDEN : 'hidden.bs.dropdown',
|
|
|
|
SHOW : 'show.bs.dropdown',
|
|
|
|
SHOWN : 'shown.bs.dropdown'
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @const
|
|
|
|
* @enum {string}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Dropdown._ClassName = {
|
|
|
|
BACKDROP : 'dropdown-backdrop',
|
|
|
|
DISABLED : 'disabled',
|
|
|
|
OPEN : 'open'
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @const
|
|
|
|
* @enum {string}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Dropdown._Selector = {
|
|
|
|
BACKDROP : '.dropdown-backdrop',
|
|
|
|
DATA_TOGGLE : '[data-toggle="dropdown"]',
|
|
|
|
FORM_CHILD : '.dropdown form',
|
|
|
|
ROLE_MENU : '[role="menu"]',
|
|
|
|
ROLE_LISTBOX : '[role="listbox"]',
|
|
|
|
NAVBAR_NAV : '.navbar-nav',
|
|
|
|
VISIBLE_ITEMS : '[role="menu"] li:not(.divider) a, [role="listbox"] li:not(.divider) a'
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Provides the jQuery Interface for the alert component.
|
|
|
|
* @param {string=} opt_config
|
|
|
|
* @this {jQuery}
|
|
|
|
* @return {jQuery}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Dropdown._jQueryInterface = function (opt_config) {
|
|
|
|
return this.each(function () {
|
|
|
|
var data = $(this).data(Dropdown._DATA_KEY)
|
|
|
|
|
|
|
|
if (!data) {
|
|
|
|
$(this).data(Dropdown._DATA_KEY, (data = new Dropdown(this)))
|
|
|
|
}
|
2011-08-28 06:46:50 +02:00
|
|
|
|
2015-01-03 22:58:44 +01:00
|
|
|
if (typeof opt_config === 'string') {
|
|
|
|
data[opt_config].call(this)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2014-06-10 07:18:05 +02:00
|
|
|
|
2012-04-15 01:29:53 +02:00
|
|
|
|
2015-01-03 22:58:44 +01:00
|
|
|
/**
|
|
|
|
* @param {Event=} opt_event
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Dropdown._clearMenus = function (opt_event) {
|
|
|
|
if (opt_event && opt_event.which == 3) {
|
|
|
|
return
|
2014-06-23 20:07:18 +02:00
|
|
|
}
|
2011-11-21 03:19:50 +01:00
|
|
|
|
2015-01-03 22:58:44 +01:00
|
|
|
var backdrop = $(Dropdown._Selector.BACKDROP)[0]
|
|
|
|
if (backdrop) {
|
|
|
|
backdrop.parentNode.removeChild(backdrop)
|
|
|
|
}
|
2014-05-13 06:15:16 +02:00
|
|
|
|
2015-01-03 22:58:44 +01:00
|
|
|
var toggles = /** @type {Array.<Element>} */ ($.makeArray($(Dropdown._Selector.DATA_TOGGLE)))
|
2011-11-21 05:58:04 +01:00
|
|
|
|
2015-01-03 22:58:44 +01:00
|
|
|
for (var i = 0; i < toggles.length; i++) {
|
|
|
|
var parent = Dropdown._getParentFromElement(toggles[i])
|
|
|
|
var relatedTarget = { 'relatedTarget': toggles[i] }
|
2012-04-15 01:29:53 +02:00
|
|
|
|
2015-01-03 22:58:44 +01:00
|
|
|
if (!$(parent).hasClass(Dropdown._ClassName.OPEN)) {
|
|
|
|
continue
|
|
|
|
}
|
2012-01-28 10:35:13 +01:00
|
|
|
|
2015-01-03 22:58:44 +01:00
|
|
|
var hideEvent = $.Event(Dropdown._Event.HIDE, relatedTarget)
|
|
|
|
$(parent).trigger(hideEvent)
|
|
|
|
if (hideEvent.isDefaultPrevented()) {
|
|
|
|
continue
|
|
|
|
}
|
2012-12-08 00:37:32 +01:00
|
|
|
|
2015-01-03 22:58:44 +01:00
|
|
|
toggles[i].setAttribute('aria-expanded', 'false')
|
2013-05-25 08:15:04 +02:00
|
|
|
|
2015-01-03 22:58:44 +01:00
|
|
|
$(parent)
|
|
|
|
.removeClass(Dropdown._ClassName.OPEN)
|
|
|
|
.trigger(Dropdown._Event.HIDDEN, relatedTarget)
|
|
|
|
}
|
|
|
|
}
|
2013-05-25 08:15:04 +02:00
|
|
|
|
|
|
|
|
2015-01-03 22:58:44 +01:00
|
|
|
/**
|
|
|
|
* @param {Element} element
|
|
|
|
* @return {Element}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Dropdown._getParentFromElement = function (element) {
|
|
|
|
var selector = Bootstrap.getSelectorFromElement(element)
|
2012-05-17 09:23:11 +02:00
|
|
|
|
2015-01-03 22:58:44 +01:00
|
|
|
if (selector) {
|
|
|
|
var parent = $(selector)[0]
|
2014-06-23 20:07:18 +02:00
|
|
|
}
|
2012-05-17 09:23:11 +02:00
|
|
|
|
2015-01-03 22:58:44 +01:00
|
|
|
return /** @type {Element} */ (parent || element.parentNode)
|
|
|
|
}
|
|
|
|
|
2012-05-17 09:23:11 +02:00
|
|
|
|
2015-01-03 22:58:44 +01:00
|
|
|
/**
|
|
|
|
* @param {Event} event
|
|
|
|
* @this {Element}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Dropdown._dataApiKeydownHandler = function (event) {
|
|
|
|
if (!/(38|40|27|32)/.test(event.which) || /input|textarea/i.test(event.target.tagName)) {
|
|
|
|
return
|
|
|
|
}
|
2012-01-28 10:35:13 +01:00
|
|
|
|
2015-01-03 22:58:44 +01:00
|
|
|
event.preventDefault()
|
|
|
|
event.stopPropagation()
|
2011-11-21 05:58:04 +01:00
|
|
|
|
2015-01-03 22:58:44 +01:00
|
|
|
if (this.disabled || $(this).hasClass(Dropdown._ClassName.DISABLED)) {
|
|
|
|
return
|
|
|
|
}
|
2012-04-15 01:29:53 +02:00
|
|
|
|
2015-01-03 22:58:44 +01:00
|
|
|
var parent = Dropdown._getParentFromElement(this)
|
|
|
|
var isActive = $(parent).hasClass(Dropdown._ClassName.OPEN)
|
2011-11-21 05:58:04 +01:00
|
|
|
|
2015-01-03 22:58:44 +01:00
|
|
|
if ((!isActive && event.which != 27) || (isActive && event.which == 27)) {
|
|
|
|
if (event.which == 27) {
|
|
|
|
var toggle = $(parent).find(Dropdown._Selector.DATA_TOGGLE)[0]
|
|
|
|
$(toggle).trigger('focus')
|
2014-06-23 20:07:18 +02:00
|
|
|
}
|
2015-01-03 22:58:44 +01:00
|
|
|
$(this).trigger('click')
|
|
|
|
return
|
|
|
|
}
|
2012-05-17 09:23:11 +02:00
|
|
|
|
2015-01-03 22:58:44 +01:00
|
|
|
var items = $.makeArray($(Dropdown._Selector.VISIBLE_ITEMS))
|
2012-05-17 09:23:11 +02:00
|
|
|
|
2015-01-03 22:58:44 +01:00
|
|
|
items = items.filter(function (item) {
|
|
|
|
return item.offsetWidth || item.offsetHeight
|
|
|
|
})
|
2012-05-17 09:23:11 +02:00
|
|
|
|
2015-01-03 22:58:44 +01:00
|
|
|
if (!items.length) {
|
|
|
|
return
|
|
|
|
}
|
2011-11-21 05:58:04 +01:00
|
|
|
|
2015-01-03 22:58:44 +01:00
|
|
|
var index = items.indexOf(event.target)
|
2011-11-25 04:40:25 +01:00
|
|
|
|
2015-01-03 22:58:44 +01:00
|
|
|
if (event.which == 38 && index > 0) index-- // up
|
|
|
|
if (event.which == 40 && index < items.length - 1) index++ // down
|
|
|
|
if (!~index) index = 0
|
|
|
|
|
|
|
|
items[index].focus()
|
|
|
|
}
|
2012-05-17 09:23:11 +02:00
|
|
|
|
2014-07-22 07:44:35 +02:00
|
|
|
|
2015-01-03 22:58:44 +01:00
|
|
|
/**
|
|
|
|
* Toggles the dropdown
|
|
|
|
* @this {Element}
|
|
|
|
* @return {boolean|undefined}
|
|
|
|
*/
|
|
|
|
Dropdown.prototype['toggle'] = function () {
|
|
|
|
if (this.disabled || $(this).hasClass(Dropdown._ClassName.DISABLED)) {
|
|
|
|
return
|
|
|
|
}
|
2014-07-22 07:44:35 +02:00
|
|
|
|
2015-01-03 22:58:44 +01:00
|
|
|
var parent = Dropdown._getParentFromElement(this)
|
|
|
|
var isActive = $(parent).hasClass(Dropdown._ClassName.OPEN)
|
2014-07-22 07:44:35 +02:00
|
|
|
|
2015-01-03 22:58:44 +01:00
|
|
|
Dropdown._clearMenus()
|
2014-07-22 07:44:35 +02:00
|
|
|
|
2015-01-03 22:58:44 +01:00
|
|
|
if (isActive) {
|
|
|
|
return false
|
2014-06-23 20:07:18 +02:00
|
|
|
}
|
2012-05-17 09:23:11 +02:00
|
|
|
|
2015-01-03 22:58:44 +01:00
|
|
|
if ('ontouchstart' in document.documentElement && !$(parent).closest(Dropdown._Selector.NAVBAR_NAV).length) {
|
|
|
|
// if mobile we use a backdrop because click events don't delegate
|
|
|
|
var dropdown = document.createElement('div')
|
|
|
|
dropdown.className = Dropdown._ClassName.BACKDROP
|
|
|
|
this.parentNode.insertBefore(this, dropdown)
|
|
|
|
$(dropdown).on('click', Dropdown._clearMenus)
|
|
|
|
}
|
2012-05-17 09:23:11 +02:00
|
|
|
|
2015-01-03 22:58:44 +01:00
|
|
|
var relatedTarget = { 'relatedTarget': this }
|
|
|
|
var showEvent = $.Event(Dropdown._Event.SHOW, relatedTarget)
|
2012-05-17 09:23:11 +02:00
|
|
|
|
2015-01-03 22:58:44 +01:00
|
|
|
$(parent).trigger(showEvent)
|
2011-11-21 05:58:04 +01:00
|
|
|
|
2015-01-03 22:58:44 +01:00
|
|
|
if (showEvent.isDefaultPrevented()) {
|
|
|
|
return
|
2014-06-23 20:07:18 +02:00
|
|
|
}
|
2011-11-21 05:58:04 +01:00
|
|
|
|
2015-01-03 22:58:44 +01:00
|
|
|
this.focus()
|
|
|
|
this.setAttribute('aria-expanded', 'true')
|
2011-11-21 03:19:50 +01:00
|
|
|
|
2015-01-03 22:58:44 +01:00
|
|
|
$(parent).toggleClass(Dropdown._ClassName.OPEN)
|
2014-06-23 20:07:18 +02:00
|
|
|
|
2015-01-03 22:58:44 +01:00
|
|
|
$(parent).trigger(Dropdown._Event.SHOWN, relatedTarget)
|
2013-05-16 21:50:06 +02:00
|
|
|
|
2015-01-03 22:58:44 +01:00
|
|
|
return false
|
|
|
|
}
|
2011-08-28 06:46:50 +02:00
|
|
|
|
2014-04-22 07:03:33 +02:00
|
|
|
|
2015-01-03 22:58:44 +01:00
|
|
|
/**
|
|
|
|
* ------------------------------------------------------------------------
|
|
|
|
* jQuery Interface + noConflict implementaiton
|
|
|
|
* ------------------------------------------------------------------------
|
|
|
|
*/
|
2011-12-21 08:28:48 +01:00
|
|
|
|
2015-01-03 22:58:44 +01:00
|
|
|
/**
|
|
|
|
* @const
|
|
|
|
* @type {Function}
|
|
|
|
*/
|
|
|
|
$.fn[Dropdown._NAME] = Dropdown._jQueryInterface
|
2011-11-21 05:58:04 +01:00
|
|
|
|
2012-12-07 23:06:01 +01:00
|
|
|
|
2015-01-03 22:58:44 +01:00
|
|
|
/**
|
|
|
|
* @const
|
|
|
|
* @type {Function}
|
|
|
|
*/
|
|
|
|
$.fn[Dropdown._NAME]['Constructor'] = Dropdown
|
|
|
|
|
2012-12-07 23:06:01 +01:00
|
|
|
|
2015-01-03 22:58:44 +01:00
|
|
|
/**
|
|
|
|
* @const
|
|
|
|
* @type {Function}
|
|
|
|
*/
|
|
|
|
$.fn[Dropdown._NAME]['noConflict'] = function () {
|
|
|
|
$.fn[Dropdown._NAME] = Dropdown._JQUERY_NO_CONFLICT
|
|
|
|
return this
|
|
|
|
}
|
2012-12-07 23:06:01 +01:00
|
|
|
|
2013-05-16 21:50:06 +02:00
|
|
|
|
2015-01-03 22:58:44 +01:00
|
|
|
/**
|
|
|
|
* ------------------------------------------------------------------------
|
|
|
|
* Data Api implementation
|
|
|
|
* ------------------------------------------------------------------------
|
|
|
|
*/
|
2011-10-05 06:48:53 +02:00
|
|
|
|
2015-01-03 22:58:44 +01:00
|
|
|
$(document)
|
|
|
|
.on('click.bs.dropdown.data-api', Dropdown._clearMenus)
|
|
|
|
.on('click.bs.dropdown.data-api', Dropdown._Selector.FORM_CHILD, function (e) { e.stopPropagation() })
|
|
|
|
.on('click.bs.dropdown.data-api', Dropdown._Selector.DATA_TOGGLE, Dropdown.prototype['toggle'])
|
|
|
|
.on('keydown.bs.dropdown.data-api', Dropdown._Selector.DATA_TOGGLE, Dropdown._dataApiKeydownHandler)
|
|
|
|
.on('keydown.bs.dropdown.data-api', Dropdown._Selector.ROLE_MENU, Dropdown._dataApiKeydownHandler)
|
|
|
|
.on('keydown.bs.dropdown.data-api', Dropdown._Selector.ROLE_LISTBOX, Dropdown._dataApiKeydownHandler)
|