Skip to content

Instantly share code, notes, and snippets.

@wesruv
Last active July 7, 2021 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wesruv/0ad963a6213e8fb05461cd040bf17a84 to your computer and use it in GitHub Desktop.
Save wesruv/0ad963a6213e8fb05461cd040bf17a84 to your computer and use it in GitHub Desktop.
// Pfe Tabs in or out of a content set
document.addEventListener('pfe-tabs:shown-tab', function(event) {
if (window.analyticsHelper && typeof window.analyticsHelper.parseCustomEvent === 'function') {
var componentParent = event.target.closest('pfe-content-set') || event.target.closest('pfe-tabs');
var tabTextWrapper = null;
if (componentParent) {
if (componentParent.tagName === 'PFE-CONTENT-SET') {
var tabSlot = event.detail.tab.querySelector('slot');
if (tabSlot) {
var tabTextWrapper = componentParent.getSlot(tabSlot.getAttribute('name'));
if (tabTextWrapper) {
tabTextWrapper = componentParent.getSlot(event.detail.tab.querySelector('slot').getAttribute('name'))[0];
}
}
}
else {
tabTextWrapper = event.detail.tab;
}
if (tabTextWrapper) {
window.analyticsHelper.parseCustomEvent(tabTextWrapper, componentParent, 'clicked');
}
else {
console.warn('Wasn\'t able to find the tabTextWrapper');
}
}
else {
console.warn('Wasn\'t able to find the componentParent');
}
}
});
// PFE Accordion in or out of a content-set
document.addEventListener('pfe-accordion:change', function(event) {
if (window.analyticsHelper && typeof window.analyticsHelper.parseCustomEvent === 'function') {
var componentParent = event.target.closest('pfe-content-set') || event.target.closest('pfe-accordion');
// Check to make sure it just got opened, not closed
if (event.detail.expanded) {
var toggle = event.target.tagName === 'PFE-ACCORDION-HEADER' ? event.target : event.path[0];
if (componentParent) {
if (componentParent.tagName === 'PFE-CONTENT-SET') {
var toggleSlot = toggle.querySelector('slot');
if (toggleSlot) {
var toggleTextWrapper = componentParent.getSlot(toggleSlot.getAttribute('name'));
if (toggleTextWrapper) {
toggle = toggleTextWrapper;
}
}
}
}
window.analyticsHelper.parseCustomEvent(toggle, componentParent, 'expand');
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment