diff options
author | Mario Vavti <mario@mariovavti.com> | 2017-03-20 11:18:23 +0100 |
---|---|---|
committer | Mario Vavti <mario@mariovavti.com> | 2017-03-20 11:18:23 +0100 |
commit | 37d350c3f589779a32ca356047d8c7244ac4878f (patch) | |
tree | fa042cc1f488fd91ae395d6335753cd9742d6baf /library/bootstrap/js/bootstrap.js | |
parent | b10c519cc16ac7cc115becd19bc8eeb3ee2e4c38 (diff) | |
download | volse-hubzilla-37d350c3f589779a32ca356047d8c7244ac4878f.tar.gz volse-hubzilla-37d350c3f589779a32ca356047d8c7244ac4878f.tar.bz2 volse-hubzilla-37d350c3f589779a32ca356047d8c7244ac4878f.zip |
update to latest bs4 from git and change hidden-* classes to d-*
Diffstat (limited to 'library/bootstrap/js/bootstrap.js')
-rw-r--r-- | library/bootstrap/js/bootstrap.js | 83 |
1 files changed, 52 insertions, 31 deletions
diff --git a/library/bootstrap/js/bootstrap.js b/library/bootstrap/js/bootstrap.js index ee87b9f88..d16517bba 100644 --- a/library/bootstrap/js/bootstrap.js +++ b/library/bootstrap/js/bootstrap.js @@ -141,13 +141,16 @@ var Util = function ($) { }, getSelectorFromElement: function getSelectorFromElement(element) { var selector = element.getAttribute('data-target'); - - if (!selector) { + if (!selector || selector === '#') { selector = element.getAttribute('href') || ''; - selector = /^#[a-z]/i.test(selector) ? selector : null; } - return selector; + try { + var $selector = $(selector); + return $selector.length > 0 ? selector : null; + } catch (error) { + return null; + } }, reflow: function reflow(element) { return element.offsetHeight; @@ -1055,7 +1058,8 @@ var Collapse = function ($) { var Selector = { ACTIVES: '.card > .show, .card > .collapsing', - DATA_TOGGLE: '[data-toggle="collapse"]' + DATA_TOGGLE: '[data-toggle="collapse"]', + DATA_CHILDREN: 'data-children' }; /** @@ -1072,13 +1076,20 @@ var Collapse = function ($) { this._element = element; this._config = this._getConfig(config); this._triggerArray = $.makeArray($('[data-toggle="collapse"][href="#' + element.id + '"],' + ('[data-toggle="collapse"][data-target="#' + element.id + '"]'))); - this._parent = this._config.parent ? this._getParent() : null; if (!this._config.parent) { this._addAriaAndCollapsedClass(this._element, this._triggerArray); } + this._selectorActives = Selector.ACTIVES; + if (this._parent) { + var childrenSelector = this._parent.hasAttribute(Selector.DATA_CHILDREN) ? this._parent.getAttribute(Selector.DATA_CHILDREN) : null; + if (childrenSelector !== null) { + this._selectorActives = childrenSelector + ' > .show, ' + childrenSelector + ' > .collapsing'; + } + } + if (this._config.toggle) { this.toggle(); } @@ -1111,7 +1122,7 @@ var Collapse = function ($) { var activesData = void 0; if (this._parent) { - actives = $.makeArray($(this._parent).find(Selector.ACTIVES)); + actives = $.makeArray($(this._parent).find(this._selectorActives)); if (!actives.length) { actives = null; } @@ -1191,9 +1202,8 @@ var Collapse = function ($) { } var dimension = this._getDimension(); - var offsetDimension = dimension === Dimension.WIDTH ? 'offsetWidth' : 'offsetHeight'; - this._element.style[dimension] = this._element[offsetDimension] + 'px'; + this._element.style[dimension] = this._element.getBoundingClientRect()[dimension] + 'px'; Util.reflow(this._element); @@ -1440,15 +1450,6 @@ var Dropdown = function ($) { return false; } - if ('ontouchstart' in document.documentElement && !$(parent).closest(Selector.NAVBAR_NAV).length) { - - // if mobile we use a backdrop because click events don't delegate - var dropdown = document.createElement('div'); - dropdown.className = ClassName.BACKDROP; - $(dropdown).insertBefore(this); - $(dropdown).on('click', Dropdown._clearMenus); - } - var relatedTarget = { relatedTarget: this }; @@ -1460,6 +1461,16 @@ var Dropdown = function ($) { return false; } + // set the backdrop only if the dropdown menu will be opened + if ('ontouchstart' in document.documentElement && !$(parent).closest(Selector.NAVBAR_NAV).length) { + + // if mobile we use a backdrop because click events don't delegate + var dropdown = document.createElement('div'); + dropdown.className = ClassName.BACKDROP; + $(dropdown).insertBefore(this); + $(dropdown).on('click', Dropdown._clearMenus); + } + this.focus(); this.setAttribute('aria-expanded', true); @@ -1506,11 +1517,6 @@ var Dropdown = function ($) { return; } - var backdrop = $(Selector.BACKDROP)[0]; - if (backdrop) { - backdrop.parentNode.removeChild(backdrop); - } - var toggles = $.makeArray($(Selector.DATA_TOGGLE)); for (var i = 0; i < toggles.length; i++) { @@ -1533,6 +1539,12 @@ var Dropdown = function ($) { continue; } + // remove backdrop only if the dropdown menu will be hidden + var backdrop = $(parent).find(Selector.BACKDROP)[0]; + if (backdrop) { + backdrop.parentNode.removeChild(backdrop); + } + toggles[i].setAttribute('aria-expanded', 'false'); $(parent).removeClass(ClassName.SHOW).trigger($.Event(Event.HIDDEN, relatedTarget)); @@ -2069,7 +2081,7 @@ var Modal = function ($) { var scrollDiv = document.createElement('div'); scrollDiv.className = ClassName.SCROLLBAR_MEASURER; document.body.appendChild(scrollDiv); - var scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth; + var scrollbarWidth = scrollDiv.getBoundingClientRect().width - scrollDiv.clientWidth; document.body.removeChild(scrollDiv); return scrollbarWidth; }; @@ -2288,9 +2300,12 @@ var ScrollSpy = function ($) { target = $(targetSelector)[0]; } - if (target && (target.offsetWidth || target.offsetHeight)) { - // todo (fat): remove sketch reliance on jQuery position/offset - return [$(target)[offsetMethod]().top + offsetBase, targetSelector]; + if (target) { + var targetBCR = target.getBoundingClientRect(); + if (targetBCR.width || targetBCR.height) { + // todo (fat): remove sketch reliance on jQuery position/offset + return [$(target)[offsetMethod]().top + offsetBase, targetSelector]; + } } return null; }).filter(function (item) { @@ -2345,7 +2360,7 @@ var ScrollSpy = function ($) { }; ScrollSpy.prototype._getOffsetHeight = function _getOffsetHeight() { - return this._scrollElement === window ? window.innerHeight : this._scrollElement.offsetHeight; + return this._scrollElement === window ? window.innerHeight : this._scrollElement.getBoundingClientRect().height; }; ScrollSpy.prototype._process = function _process() { @@ -2521,10 +2536,10 @@ var Tab = function ($) { A: 'a', LI: 'li', DROPDOWN: '.dropdown', - LIST: 'ul:not(.dropdown-menu), ol:not(.dropdown-menu), nav:not(.dropdown-menu)', - FADE_CHILD: '> .nav-item .fade, > .fade', + LIST: 'ul:not(.dropdown-menu), ol:not(.dropdown-menu), nav:not(.dropdown-menu), .list-group:not(.dropdown-menu)', + FADE_CHILD: '> .nav-item .fade, > .list-group-item .fade, > .fade', ACTIVE: '.active', - ACTIVE_CHILD: '> .nav-item > .active, > .active', + ACTIVE_CHILD: '> .nav-item > .active, > .list-group-item > .active, > .active', DATA_TOGGLE: '[data-toggle="tab"], [data-toggle="pill"]', DROPDOWN_TOGGLE: '.dropdown-toggle', DROPDOWN_ACTIVE_CHILD: '> .dropdown-menu .active' @@ -2639,6 +2654,9 @@ var Tab = function ($) { Tab.prototype._transitionComplete = function _transitionComplete(element, active, isTransitioning, callback) { if (active) { $(active).removeClass(ClassName.ACTIVE); + if ($(active).hasClass('list-group-item')) { + $(active).find('a.nav-link').removeClass(ClassName.ACTIVE); + } var dropdownChild = $(active.parentNode).find(Selector.DROPDOWN_ACTIVE_CHILD)[0]; @@ -2650,6 +2668,9 @@ var Tab = function ($) { } $(element).addClass(ClassName.ACTIVE); + if ($(element.parentNode).hasClass('list-group-item')) { + $(element.parentNode).addClass(ClassName.ACTIVE); + } element.setAttribute('aria-expanded', true); if (isTransitioning) { |