|
2 | 2 | 'use strict'; |
3 | 3 |
|
4 | 4 | var patternfly = { |
5 | | - version: "3.20.0", |
| 5 | + version: "3.21.0", |
6 | 6 | }; |
7 | 7 |
|
8 | 8 | // Util: PatternFly Palette colors |
|
1663 | 1663 | return $.fn.setupVerticalNavigation.self; |
1664 | 1664 | }; |
1665 | 1665 | }(jQuery)); |
| 1666 | + |
| 1667 | +// PatternFly pf-list |
| 1668 | +(function ($) { |
| 1669 | + 'use strict'; |
| 1670 | + |
| 1671 | + $.fn.pfList = function () { |
| 1672 | + function init (list) { |
| 1673 | + // Ensure the state of the expansion elements is consistent |
| 1674 | + list.find('[data-list=expansion], .list-pf-item, .list-pf-expansion').each(function (index, element) { |
| 1675 | + var $expansion = $(element), |
| 1676 | + $collapse = $expansion.find('.collapse').first(), |
| 1677 | + expanded = $collapse.hasClass('in'); |
| 1678 | + updateChevron($expansion, expanded); |
| 1679 | + if ($expansion.hasClass('list-pf-item')) { |
| 1680 | + updateActive($expansion, expanded); |
| 1681 | + } |
| 1682 | + }); |
| 1683 | + list.find('.list-pf-container').each(function (index, element) { |
| 1684 | + var $element = $(element); |
| 1685 | + // The toggle element is the element with the data-list=toggle attribute |
| 1686 | + // or the entire .list-pf-container as a fallback |
| 1687 | + var $toggles = $element.find('[data-list=toggle]'); |
| 1688 | + $toggles.length || ($toggles = $element); |
| 1689 | + $toggles.on('keydown', function (event) { |
| 1690 | + if (event.keyCode === 13 || event.keyCode === 32) { |
| 1691 | + toggleCollapse(this); |
| 1692 | + event.stopPropagation(); |
| 1693 | + event.preventDefault(); |
| 1694 | + } |
| 1695 | + }); |
| 1696 | + $toggles.on('click', function (event) { |
| 1697 | + toggleCollapse(this); |
| 1698 | + event.stopPropagation(); |
| 1699 | + event.preventDefault(); |
| 1700 | + }); |
| 1701 | + }); |
| 1702 | + } |
| 1703 | + |
| 1704 | + function toggleCollapse (toggle) { |
| 1705 | + var $toggle, $expansion, $collapse, expanded, $listItem; |
| 1706 | + $toggle = $(toggle); |
| 1707 | + // Find the parent expansion of the toggle |
| 1708 | + $expansion = $toggle.parentsUntil('.list-pf', '[data-list=expansion]').first(); |
| 1709 | + $expansion.length || ($expansion = $toggle.closest('.list-pf-item, .list-pf-expansion')); |
| 1710 | + |
| 1711 | + // toggle the "in" class of its first .collapse child |
| 1712 | + $collapse = $expansion.find('.collapse').first(); |
| 1713 | + $collapse.toggleClass('in'); |
| 1714 | + |
| 1715 | + // update the state of the expansion element |
| 1716 | + updateChevron($expansion, $collapse.hasClass('in')); |
| 1717 | + $listItem = $expansion.closest('.list-pf-item'); |
| 1718 | + updateActive($listItem, $listItem.find('.collapse').first().hasClass('in')); |
| 1719 | + } |
| 1720 | + |
| 1721 | + function updateActive ($listItem, expanded) { |
| 1722 | + // Find the closest .list-pf-item of the expansion, and set its "active" class |
| 1723 | + if (expanded) { |
| 1724 | + $listItem.addClass('active'); |
| 1725 | + } else { |
| 1726 | + $listItem.removeClass('active'); |
| 1727 | + } |
| 1728 | + } |
| 1729 | + |
| 1730 | + function updateChevron ($expansion, expanded) { |
| 1731 | + var $chevron = $expansion.find('.list-pf-chevron .fa').first(); |
| 1732 | + if (expanded) { |
| 1733 | + $chevron.removeClass('fa-angle-right'); |
| 1734 | + $chevron.addClass('fa-angle-down'); |
| 1735 | + } else { |
| 1736 | + $chevron.addClass('fa-angle-right'); |
| 1737 | + $chevron.removeClass('fa-angle-down'); |
| 1738 | + } |
| 1739 | + } |
| 1740 | + |
| 1741 | + init(this); |
| 1742 | + |
| 1743 | + return this; |
| 1744 | + }; |
| 1745 | +}(jQuery)); |
0 commit comments