Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.91 KB | None | 0 0
  1. /*globals Granite,Coral*/
  2. (function ($, document) {
  3.  
  4. 'use strict';
  5.  
  6. //used in the dialogs
  7. $(document).on('dialog-ready', function () {
  8. init()
  9. });
  10.  
  11. var visibaleTabIds = [];
  12.  
  13. function toggleTabs(allDepPanelIds, negate) {
  14. return function (tab) {
  15. var panelStack = tab.parentElement.parentElement;
  16. var tabId = panelStack.id;
  17.  
  18. visibaleTabIds.push(tabId);
  19. var tabsList = document.querySelector('coral-dialog-content coral-tablist');
  20.  
  21. tabsList.items.getAll().forEach(function (tabItem) {
  22. var ariaControls = tabItem.getAttribute('aria-controls');
  23.  
  24. if (allDepPanelIds.indexOf(ariaControls) !== -1) {
  25. if (negate) {
  26. tabItem.hidden = !ariaControls !== tabId;
  27. } else {
  28. if (ariaControls !== tabId) {
  29. tabItem.hidden = !visibaleTabIds.includes(ariaControls)
  30. } else {
  31. tabItem.hidden = false;
  32. }
  33. }
  34. }
  35. });
  36. };
  37. }
  38.  
  39. function showHideTabListItems(initial) {
  40. var allDependentTabsNodeList = document.querySelectorAll('[data-dep-value]');
  41. var allDependentTabs = [].slice.call(allDependentTabsNodeList);
  42.  
  43. var allDepPanelIds = allDependentTabs.map(function (tab) {
  44. var panelStack = tab.parentElement.parentElement;
  45. return panelStack.id;
  46. });
  47.  
  48. var tabsToShow = allDependentTabs.filter(function (el) {
  49.  
  50. var array = el.dataset.depValue.split(',');
  51. if (array.length) {
  52. return array.includes(initial);
  53. } else {
  54. return el.dataset.depValue === initial;
  55. }
  56.  
  57. });
  58.  
  59. if (tabsToShow.length) {
  60. tabsToShow.forEach(toggleTabs(allDepPanelIds, false));
  61. } else {
  62. allDependentTabs.forEach(toggleTabs(allDepPanelIds, true))
  63. }
  64.  
  65. visibaleTabIds = [];
  66. }
  67.  
  68. function setUpShowHide(selector) {
  69. Coral.commons.ready(selector, function () {
  70. selector.on('change', function (e) {
  71. showHideTabListItems(e.target.value);
  72. });
  73.  
  74. var initial = selector.value;
  75. showHideTabListItems(initial);
  76. })
  77. }
  78.  
  79. function init() {
  80. Coral.commons.ready(document, function () {
  81. var selectors = document.querySelectorAll('.tabs__show-hide');
  82. if (selectors.length !== 0) {
  83. selectors.forEach(setUpShowHide)
  84. }
  85.  
  86. })
  87. }
  88. }
  89.  
  90. )(Granite.$, document);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement