diff options
| author | Gijs Boddeus <[email protected]> | 2017-10-04 08:46:03 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2017-10-04 08:46:03 +0200 |
| commit | 263190305e1208b183611fe511ea8f983932a00d (patch) | |
| tree | 8cc874b98d5d9e7d9db66b078d94e5dc1db2c4e8 /js/src | |
| parent | cc092272eefa0e89bebfc716c8df8214d2804c77 (diff) | |
| parent | 682ad1fff58fb6586dceaf31d490aaa522110e59 (diff) | |
| download | bootstrap-263190305e1208b183611fe511ea8f983932a00d.tar.xz bootstrap-263190305e1208b183611fe511ea8f983932a00d.zip | |
Merge branch 'v4-dev' into yiq-function-update
Diffstat (limited to 'js/src')
| -rw-r--r-- | js/src/collapse.js | 15 | ||||
| -rw-r--r-- | js/src/dropdown.js | 15 | ||||
| -rw-r--r-- | js/src/scrollspy.js | 3 | ||||
| -rw-r--r-- | js/src/tab.js | 8 | ||||
| -rw-r--r-- | js/src/util.js | 10 |
5 files changed, 38 insertions, 13 deletions
diff --git a/js/src/collapse.js b/js/src/collapse.js index bf9c990ec..fa082f133 100644 --- a/js/src/collapse.js +++ b/js/src/collapse.js @@ -33,7 +33,7 @@ const Collapse = (() => { const DefaultType = { toggle : 'boolean', - parent : 'string' + parent : '(string|element)' } const Event = { @@ -289,7 +289,18 @@ const Collapse = (() => { } _getParent() { - const parent = $(this._config.parent)[0] + let parent = null + if (Util.isElement(this._config.parent)) { + parent = this._config.parent + + // it's a jQuery object + if (typeof this._config.parent.jquery !== 'undefined') { + parent = this._config.parent[0] + } + } else { + parent = $(this._config.parent)[0] + } + const selector = `[data-toggle="collapse"][data-parent="${this._config.parent}"]` diff --git a/js/src/dropdown.js b/js/src/dropdown.js index f76f84ef0..6681df668 100644 --- a/js/src/dropdown.js +++ b/js/src/dropdown.js @@ -80,7 +80,7 @@ const Dropdown = (() => { } const DefaultType = { - offset : '(number|string)', + offset : '(number|string|function)', flip : 'boolean' } @@ -246,12 +246,19 @@ const Dropdown = (() => { } _getPopperConfig() { + const offsetConf = {} + if (typeof this._config.offset === 'function') { + offsetConf.fn = (data) => { + data.offsets = $.extend({}, data.offsets, this._config.offset(data.offsets) || {}) + return data + } + } else { + offsetConf.offset = this._config.offset + } const popperConfig = { placement : this._getPlacement(), modifiers : { - offset : { - offset : this._config.offset - }, + offset : offsetConf, flip : { enabled : this._config.flip } diff --git a/js/src/scrollspy.js b/js/src/scrollspy.js index 70067c0b3..e8f0d3101 100644 --- a/js/src/scrollspy.js +++ b/js/src/scrollspy.js @@ -54,6 +54,7 @@ const ScrollSpy = (() => { ACTIVE : '.active', NAV_LIST_GROUP : '.nav, .list-group', NAV_LINKS : '.nav-link', + NAV_ITEMS : '.nav-item', LIST_ITEMS : '.list-group-item', DROPDOWN : '.dropdown', DROPDOWN_ITEMS : '.dropdown-item', @@ -264,6 +265,8 @@ const ScrollSpy = (() => { // Set triggered links parents as active // With both <ul> and <nav> markup a parent is the previous sibling of any nav ancestor $link.parents(Selector.NAV_LIST_GROUP).prev(`${Selector.NAV_LINKS}, ${Selector.LIST_ITEMS}`).addClass(ClassName.ACTIVE) + // Handle special case when .nav-link is inside .nav-item + $link.parents(Selector.NAV_LIST_GROUP).prev(Selector.NAV_ITEMS).children(Selector.NAV_LINKS).addClass(ClassName.ACTIVE) } $(this._scrollElement).trigger(Event.ACTIVATE, { diff --git a/js/src/tab.js b/js/src/tab.js index 18af4e7e2..2a554c287 100644 --- a/js/src/tab.js +++ b/js/src/tab.js @@ -196,11 +196,15 @@ const Tab = (() => { $(dropdownChild).removeClass(ClassName.ACTIVE) } - active.setAttribute('aria-expanded', false) + if (active.getAttribute('role') === 'tab') { + active.setAttribute('aria-selected', false) + } } $(element).addClass(ClassName.ACTIVE) - element.setAttribute('aria-expanded', true) + if (element.getAttribute('role') === 'tab') { + element.setAttribute('aria-selected', true) + } if (isTransitioning) { Util.reflow(element) diff --git a/js/src/util.js b/js/src/util.js index b18d0f776..7eb25de55 100644 --- a/js/src/util.js +++ b/js/src/util.js @@ -32,10 +32,6 @@ const Util = (() => { return {}.toString.call(obj).match(/\s([a-zA-Z]+)/)[1].toLowerCase() } - function isElement(obj) { - return (obj[0] || obj).nodeType - } - function getSpecialTransitionEndEvent() { return { bindType: transition.end, @@ -138,12 +134,16 @@ const Util = (() => { return Boolean(transition) }, + isElement(obj) { + return (obj[0] || obj).nodeType + }, + typeCheckConfig(componentName, config, configTypes) { for (const property in configTypes) { if (Object.prototype.hasOwnProperty.call(configTypes, property)) { const expectedTypes = configTypes[property] const value = config[property] - const valueType = value && isElement(value) ? + const valueType = value && Util.isElement(value) ? 'element' : toType(value) if (!new RegExp(expectedTypes).test(valueType)) { |
