1
0
Fork 0
mirror of https://github.com/twbs/bootstrap.git synced 2022-11-09 12:25:43 -05:00

redo js dists

This commit is contained in:
Jacob Thornton 2015-08-18 22:07:45 -07:00
parent 03e732708c
commit 08d2041c45
4 changed files with 72 additions and 91 deletions

View file

@ -2203,16 +2203,23 @@ var ScrollSpy = (function ($) {
}; };
var ClassName = { var ClassName = {
DROPDOWN_ITEM: 'dropdown-item',
DROPDOWN_MENU: 'dropdown-menu', DROPDOWN_MENU: 'dropdown-menu',
NAV_LINK: 'nav-link',
NAV: 'nav',
ACTIVE: 'active' ACTIVE: 'active'
}; };
var Selector = { var Selector = {
DATA_SPY: '[data-spy="scroll"]', DATA_SPY: '[data-spy="scroll"]',
ACTIVE: '.active', ACTIVE: '.active',
LIST_ITEM: '.list-item',
LI: 'li', LI: 'li',
LI_DROPDOWN: 'li.dropdown', LI_DROPDOWN: 'li.dropdown',
NAV_ANCHORS: '.nav li > a' NAV_LINKS: '.nav-link',
DROPDOWN: '.dropdown',
DROPDOWN_ITEMS: '.dropdown-item',
DROPDOWN_TOGGLE: '.dropdown-toggle'
}; };
var OffsetMethod = { var OffsetMethod = {
@ -2233,7 +2240,7 @@ var ScrollSpy = (function ($) {
this._element = element; this._element = element;
this._scrollElement = element.tagName === 'BODY' ? window : element; this._scrollElement = element.tagName === 'BODY' ? window : element;
this._config = this._getConfig(config); this._config = this._getConfig(config);
this._selector = this._config.target + ' ' + Selector.NAV_ANCHORS; this._selector = this._config.target + ' ' + Selector.NAV_LINKS + ',' + (this._config.target + ' ' + Selector.DROPDOWN_ITEMS);
this._offsets = []; this._offsets = [];
this._targets = []; this._targets = [];
this._activeTarget = null; this._activeTarget = null;
@ -2381,20 +2388,20 @@ var ScrollSpy = (function ($) {
this._clear(); this._clear();
var selector = this._selector + '[data-target="' + target + '"],' + (this._selector + '[href="' + target + '"]'); var queries = this._selector.split(',');
queries = queries.map(function (selector) {
return selector + '[data-target="' + target + '"],' + (selector + '[href="' + target + '"]');
});
// todo (fat): getting all the raw li's up the tree is not great. var $link = $(queries.join(','));
var parentListItems = $(selector).parents(Selector.LI);
for (var i = parentListItems.length; i--;) { if ($link.hasClass(ClassName.DROPDOWN_ITEM)) {
$(parentListItems[i]).addClass(ClassName.ACTIVE); $link.closest(Selector.DROPDOWN).find(Selector.DROPDOWN_TOGGLE).addClass(ClassName.ACTIVE);
$link.addClass(ClassName.ACTIVE);
var itemParent = parentListItems[i].parentNode; } else {
// todo (fat) this is kinda sus…
if (itemParent && $(itemParent).hasClass(ClassName.DROPDOWN_MENU)) { // recursively add actives to tested nav-links
var closestDropdown = $(itemParent).closest(Selector.LI_DROPDOWN)[0]; $link.parents(Selector.LI).find(Selector.NAV_LINKS).addClass(ClassName.ACTIVE);
$(closestDropdown).addClass(ClassName.ACTIVE);
}
} }
$(this._scrollElement).trigger(Event.ACTIVATE, { $(this._scrollElement).trigger(Event.ACTIVATE, {
@ -2404,11 +2411,7 @@ var ScrollSpy = (function ($) {
}, { }, {
key: '_clear', key: '_clear',
value: function _clear() { value: function _clear() {
var activeParents = $(this._selector).parentsUntil(this._config.target, Selector.ACTIVE); $(this._selector).filter(Selector.ACTIVE).removeClass(ClassName.ACTIVE);
for (var i = activeParents.length; i--;) {
$(activeParents[i]).removeClass(ClassName.ACTIVE);
}
} }
// static // static
@ -2511,13 +2514,14 @@ var Tab = (function ($) {
var Selector = { var Selector = {
A: 'a', A: 'a',
LI: 'li', LI: 'li',
LI_DROPDOWN: 'li.dropdown', DROPDOWN: '.dropdown',
UL: 'ul:not(.dropdown-menu)', UL: 'ul:not(.dropdown-menu)',
FADE_CHILD: '> .fade', FADE_CHILD: '> .nav-item .fade, > .fade',
ACTIVE: '.active', ACTIVE: '.active',
ACTIVE_CHILD: '> .active', ACTIVE_CHILD: '> .nav-item > .active, > .active',
DATA_TOGGLE: '[data-toggle="tab"], [data-toggle="pill"]', DATA_TOGGLE: '[data-toggle="tab"], [data-toggle="pill"]',
DROPDOWN_ACTIVE_CHILD: '> .dropdown-menu > .active' DROPDOWN_TOGGLE: '.dropdown-toggle',
DROPDOWN_ACTIVE_CHILD: '> .dropdown-menu .active'
}; };
/** /**
@ -2549,7 +2553,7 @@ var Tab = (function ($) {
value: function show() { value: function show() {
var _this15 = this; var _this15 = this;
if (this._element.parentNode && this._element.parentNode.nodeType === Node.ELEMENT_NODE && $(this._element).parent().hasClass(ClassName.ACTIVE)) { if (this._element.parentNode && this._element.parentNode.nodeType === Node.ELEMENT_NODE && $(this._element).hasClass(ClassName.ACTIVE)) {
return; return;
} }
@ -2561,10 +2565,6 @@ var Tab = (function ($) {
if (ulElement) { if (ulElement) {
previous = $.makeArray($(ulElement).find(Selector.ACTIVE)); previous = $.makeArray($(ulElement).find(Selector.ACTIVE));
previous = previous[previous.length - 1]; previous = previous[previous.length - 1];
if (previous) {
previous = $(previous).find(Selector.A)[0];
}
} }
var hideEvent = $.Event(Event.HIDE, { var hideEvent = $.Event(Event.HIDE, {
@ -2589,7 +2589,7 @@ var Tab = (function ($) {
target = $(selector)[0]; target = $(selector)[0];
} }
this._activate($(this._element).closest(Selector.LI)[0], ulElement); this._activate(this._element, ulElement);
var complete = function complete() { var complete = function complete() {
var hiddenEvent = $.Event(Event.HIDDEN, { var hiddenEvent = $.Event(Event.HIDDEN, {
@ -2644,22 +2644,16 @@ var Tab = (function ($) {
$(active).removeClass(ClassName.ACTIVE); $(active).removeClass(ClassName.ACTIVE);
var dropdownChild = $(active).find(Selector.DROPDOWN_ACTIVE_CHILD)[0]; var dropdownChild = $(active).find(Selector.DROPDOWN_ACTIVE_CHILD)[0];
if (dropdownChild) { if (dropdownChild) {
$(dropdownChild).removeClass(ClassName.ACTIVE); $(dropdownChild).removeClass(ClassName.ACTIVE);
} }
var activeToggle = $(active).find(Selector.DATA_TOGGLE)[0]; active.setAttribute('aria-expanded', false);
if (activeToggle) {
activeToggle.setAttribute('aria-expanded', false);
}
} }
$(element).addClass(ClassName.ACTIVE); $(element).addClass(ClassName.ACTIVE);
element.setAttribute('aria-expanded', true);
var elementToggle = $(element).find(Selector.DATA_TOGGLE)[0];
if (elementToggle) {
elementToggle.setAttribute('aria-expanded', true);
}
if (isTransitioning) { if (isTransitioning) {
Util.reflow(element); Util.reflow(element);
@ -2670,15 +2664,12 @@ var Tab = (function ($) {
if (element.parentNode && $(element.parentNode).hasClass(ClassName.DROPDOWN_MENU)) { if (element.parentNode && $(element.parentNode).hasClass(ClassName.DROPDOWN_MENU)) {
var dropdownElement = $(element).closest(Selector.LI_DROPDOWN)[0]; var dropdownElement = $(element).closest(Selector.DROPDOWN)[0];
if (dropdownElement) { if (dropdownElement) {
$(dropdownElement).addClass(ClassName.ACTIVE); $(dropdownElement).find(Selector.DROPDOWN_TOGGLE).addClass(ClassName.ACTIVE);
} }
elementToggle = $(element).find(Selector.DATA_TOGGLE)[0]; element.setAttribute('aria-expanded', true);
if (elementToggle) {
elementToggle.setAttribute('aria-expanded', true);
}
} }
if (callback) { if (callback) {

File diff suppressed because one or more lines are too long

View file

@ -62,16 +62,23 @@
}; };
var ClassName = { var ClassName = {
DROPDOWN_ITEM: 'dropdown-item',
DROPDOWN_MENU: 'dropdown-menu', DROPDOWN_MENU: 'dropdown-menu',
NAV_LINK: 'nav-link',
NAV: 'nav',
ACTIVE: 'active' ACTIVE: 'active'
}; };
var Selector = { var Selector = {
DATA_SPY: '[data-spy="scroll"]', DATA_SPY: '[data-spy="scroll"]',
ACTIVE: '.active', ACTIVE: '.active',
LIST_ITEM: '.list-item',
LI: 'li', LI: 'li',
LI_DROPDOWN: 'li.dropdown', LI_DROPDOWN: 'li.dropdown',
NAV_ANCHORS: '.nav li > a' NAV_LINKS: '.nav-link',
DROPDOWN: '.dropdown',
DROPDOWN_ITEMS: '.dropdown-item',
DROPDOWN_TOGGLE: '.dropdown-toggle'
}; };
var OffsetMethod = { var OffsetMethod = {
@ -92,7 +99,7 @@
this._element = element; this._element = element;
this._scrollElement = element.tagName === 'BODY' ? window : element; this._scrollElement = element.tagName === 'BODY' ? window : element;
this._config = this._getConfig(config); this._config = this._getConfig(config);
this._selector = this._config.target + ' ' + Selector.NAV_ANCHORS; this._selector = this._config.target + ' ' + Selector.NAV_LINKS + ',' + (this._config.target + ' ' + Selector.DROPDOWN_ITEMS);
this._offsets = []; this._offsets = [];
this._targets = []; this._targets = [];
this._activeTarget = null; this._activeTarget = null;
@ -240,20 +247,20 @@
this._clear(); this._clear();
var selector = this._selector + '[data-target="' + target + '"],' + (this._selector + '[href="' + target + '"]'); var queries = this._selector.split(',');
queries = queries.map(function (selector) {
return selector + '[data-target="' + target + '"],' + (selector + '[href="' + target + '"]');
});
// todo (fat): getting all the raw li's up the tree is not great. var $link = $(queries.join(','));
var parentListItems = $(selector).parents(Selector.LI);
for (var i = parentListItems.length; i--;) { if ($link.hasClass(ClassName.DROPDOWN_ITEM)) {
$(parentListItems[i]).addClass(ClassName.ACTIVE); $link.closest(Selector.DROPDOWN).find(Selector.DROPDOWN_TOGGLE).addClass(ClassName.ACTIVE);
$link.addClass(ClassName.ACTIVE);
var itemParent = parentListItems[i].parentNode; } else {
// todo (fat) this is kinda sus…
if (itemParent && $(itemParent).hasClass(ClassName.DROPDOWN_MENU)) { // recursively add actives to tested nav-links
var closestDropdown = $(itemParent).closest(Selector.LI_DROPDOWN)[0]; $link.parents(Selector.LI).find(Selector.NAV_LINKS).addClass(ClassName.ACTIVE);
$(closestDropdown).addClass(ClassName.ACTIVE);
}
} }
$(this._scrollElement).trigger(Event.ACTIVATE, { $(this._scrollElement).trigger(Event.ACTIVATE, {
@ -263,11 +270,7 @@
}, { }, {
key: '_clear', key: '_clear',
value: function _clear() { value: function _clear() {
var activeParents = $(this._selector).parentsUntil(this._config.target, Selector.ACTIVE); $(this._selector).filter(Selector.ACTIVE).removeClass(ClassName.ACTIVE);
for (var i = activeParents.length; i--;) {
$(activeParents[i]).removeClass(ClassName.ACTIVE);
}
} }
// static // static

38
dist/js/umd/tab.js vendored
View file

@ -62,13 +62,14 @@
var Selector = { var Selector = {
A: 'a', A: 'a',
LI: 'li', LI: 'li',
LI_DROPDOWN: 'li.dropdown', DROPDOWN: '.dropdown',
UL: 'ul:not(.dropdown-menu)', UL: 'ul:not(.dropdown-menu)',
FADE_CHILD: '> .fade', FADE_CHILD: '> .nav-item .fade, > .fade',
ACTIVE: '.active', ACTIVE: '.active',
ACTIVE_CHILD: '> .active', ACTIVE_CHILD: '> .nav-item > .active, > .active',
DATA_TOGGLE: '[data-toggle="tab"], [data-toggle="pill"]', DATA_TOGGLE: '[data-toggle="tab"], [data-toggle="pill"]',
DROPDOWN_ACTIVE_CHILD: '> .dropdown-menu > .active' DROPDOWN_TOGGLE: '.dropdown-toggle',
DROPDOWN_ACTIVE_CHILD: '> .dropdown-menu .active'
}; };
/** /**
@ -100,7 +101,7 @@
value: function show() { value: function show() {
var _this = this; var _this = this;
if (this._element.parentNode && this._element.parentNode.nodeType === Node.ELEMENT_NODE && $(this._element).parent().hasClass(ClassName.ACTIVE)) { if (this._element.parentNode && this._element.parentNode.nodeType === Node.ELEMENT_NODE && $(this._element).hasClass(ClassName.ACTIVE)) {
return; return;
} }
@ -112,10 +113,6 @@
if (ulElement) { if (ulElement) {
previous = $.makeArray($(ulElement).find(Selector.ACTIVE)); previous = $.makeArray($(ulElement).find(Selector.ACTIVE));
previous = previous[previous.length - 1]; previous = previous[previous.length - 1];
if (previous) {
previous = $(previous).find(Selector.A)[0];
}
} }
var hideEvent = $.Event(Event.HIDE, { var hideEvent = $.Event(Event.HIDE, {
@ -140,7 +137,7 @@
target = $(selector)[0]; target = $(selector)[0];
} }
this._activate($(this._element).closest(Selector.LI)[0], ulElement); this._activate(this._element, ulElement);
var complete = function complete() { var complete = function complete() {
var hiddenEvent = $.Event(Event.HIDDEN, { var hiddenEvent = $.Event(Event.HIDDEN, {
@ -195,22 +192,16 @@
$(active).removeClass(ClassName.ACTIVE); $(active).removeClass(ClassName.ACTIVE);
var dropdownChild = $(active).find(Selector.DROPDOWN_ACTIVE_CHILD)[0]; var dropdownChild = $(active).find(Selector.DROPDOWN_ACTIVE_CHILD)[0];
if (dropdownChild) { if (dropdownChild) {
$(dropdownChild).removeClass(ClassName.ACTIVE); $(dropdownChild).removeClass(ClassName.ACTIVE);
} }
var activeToggle = $(active).find(Selector.DATA_TOGGLE)[0]; active.setAttribute('aria-expanded', false);
if (activeToggle) {
activeToggle.setAttribute('aria-expanded', false);
}
} }
$(element).addClass(ClassName.ACTIVE); $(element).addClass(ClassName.ACTIVE);
element.setAttribute('aria-expanded', true);
var elementToggle = $(element).find(Selector.DATA_TOGGLE)[0];
if (elementToggle) {
elementToggle.setAttribute('aria-expanded', true);
}
if (isTransitioning) { if (isTransitioning) {
_Util['default'].reflow(element); _Util['default'].reflow(element);
@ -221,15 +212,12 @@
if (element.parentNode && $(element.parentNode).hasClass(ClassName.DROPDOWN_MENU)) { if (element.parentNode && $(element.parentNode).hasClass(ClassName.DROPDOWN_MENU)) {
var dropdownElement = $(element).closest(Selector.LI_DROPDOWN)[0]; var dropdownElement = $(element).closest(Selector.DROPDOWN)[0];
if (dropdownElement) { if (dropdownElement) {
$(dropdownElement).addClass(ClassName.ACTIVE); $(dropdownElement).find(Selector.DROPDOWN_TOGGLE).addClass(ClassName.ACTIVE);
} }
elementToggle = $(element).find(Selector.DATA_TOGGLE)[0]; element.setAttribute('aria-expanded', true);
if (elementToggle) {
elementToggle.setAttribute('aria-expanded', true);
}
} }
if (callback) { if (callback) {