@uqds/accordion
Advanced tools
Comparing version 0.0.13-alpha.0 to 0.0.14-alpha.0
@@ -5,2 +5,3 @@ "use strict"; | ||
'use strict'; | ||
/** | ||
@@ -12,3 +13,2 @@ * @file | ||
*/ | ||
class accordion { | ||
@@ -26,6 +26,6 @@ /** | ||
} | ||
this.className = className; | ||
this.init(); | ||
} | ||
/** | ||
@@ -38,14 +38,13 @@ * Method to replace jQuery's .next() method. | ||
*/ | ||
static getNextSibling(el, selector) { | ||
// Get the next sibling element | ||
var sibling = el.nextElementSibling; // If there's no selector, return the first sibling | ||
var sibling = el.nextElementSibling; | ||
// If there's no selector, return the first sibling | ||
if (!selector) { | ||
return sibling; | ||
} // If the sibling matches our selector, use it | ||
} | ||
// If the sibling matches our selector, use it | ||
// If not, jump to the next sibling and continue the loop | ||
while (sibling) { | ||
@@ -55,6 +54,6 @@ if (sibling.matches(selector)) { | ||
} | ||
sibling = sibling.nextElementSibling; | ||
} | ||
} | ||
/** | ||
@@ -66,14 +65,13 @@ * Method to get previous sibling element. | ||
*/ | ||
static getPrevSibling(el, selector) { | ||
// Get the next sibling element | ||
var sibling = el.previousElementSibling; // If there's no selector, return the first sibling | ||
var sibling = el.previousElementSibling; | ||
// If there's no selector, return the first sibling | ||
if (!selector) { | ||
return sibling; | ||
} // If the sibling matches our selector, use it | ||
} | ||
// If the sibling matches our selector, use it | ||
// If not, jump to the next sibling and continue the loop | ||
while (sibling) { | ||
@@ -83,6 +81,6 @@ if (sibling.matches(selector)) { | ||
} | ||
sibling = sibling.previousElementSibling; | ||
} | ||
} | ||
/** | ||
@@ -93,4 +91,2 @@ * Method to hide accordion content | ||
*/ | ||
slideContentUp(el) { | ||
@@ -109,2 +105,3 @@ const content = accordion.getNextSibling(el, ".".concat(this.className, "__content")); | ||
} | ||
/** | ||
@@ -115,4 +112,2 @@ * Method to show accordion content | ||
*/ | ||
slideContentDown(el) { | ||
@@ -132,2 +127,3 @@ const content = accordion.getNextSibling(el, ".".concat(this.className, "__content")); | ||
} | ||
/** | ||
@@ -139,4 +135,2 @@ * Method to hide all other accordion content except for passed element. | ||
*/ | ||
slideUpOthers(el, togglers) { | ||
@@ -151,2 +145,3 @@ for (let i = 0; i < togglers.length; i++) { | ||
} | ||
/** | ||
@@ -157,4 +152,2 @@ * Click handler for 'togglers' | ||
*/ | ||
handleToggle(togglers) { | ||
@@ -164,3 +157,2 @@ return e => { | ||
const toggle = e.target.closest(".".concat(this.className, "__toggle")); | ||
if (toggle.classList.contains("".concat(this.className, "__toggle--active"))) { | ||
@@ -178,2 +170,3 @@ this.slideContentUp(toggle); | ||
} | ||
/** | ||
@@ -183,22 +176,20 @@ * Initialise accordion behavior | ||
*/ | ||
init() { | ||
if (window.location.hash) { | ||
this.hash = window.location.hash; | ||
} // Scroll to hash (param string) selected accordion | ||
} | ||
// Scroll to hash (param string) selected accordion | ||
if (this.hash && this.hash !== "") { | ||
const hashSelectedContent = document.querySelector("".concat(this.hash, ".").concat(this.className, "__content")); | ||
if (hashSelectedContent) { | ||
// Only apply classes on load when linking directly to an accordion item. | ||
const hashSelected = accordion.getPrevSibling(hashSelectedContent, ".".concat(this.className, "__toggle")); | ||
this.slideContentDown(hashSelected); // Scroll to top of selected item. | ||
this.slideContentDown(hashSelected); | ||
// Scroll to top of selected item. | ||
window.scrollTo(0, hashSelected.getBoundingClientRect().top); | ||
} | ||
} | ||
const accordions = document.querySelectorAll(".".concat(this.className)); | ||
@@ -210,4 +201,5 @@ accordions.forEach(el => { | ||
}); | ||
}); // wrap contents of uq-accordion__content in a wrapper to apply padding and prevent animation jump | ||
}); | ||
// wrap contents of uq-accordion__content in a wrapper to apply padding and prevent animation jump | ||
const accordionContents = document.querySelectorAll(".".concat(this.className, "__content")); | ||
@@ -222,10 +214,5 @@ const accordionName = this.className; | ||
} | ||
} | ||
exports.accordion = accordion; | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
return exports; | ||
}({}); |
@@ -1,1 +0,1 @@ | ||
"use strict";var uq=function(t){class a{constructor(t){this.className=t=t||"uq-accordion",this.init()}static getNextSibling(t,e){var s=t.nextElementSibling;if(!e)return s;for(;s;){if(s.matches(e))return s;s=s.nextElementSibling}}static getPrevSibling(t,e){var s=t.previousElementSibling;if(!e)return s;for(;s;){if(s.matches(e))return s;s=s.previousElementSibling}}slideContentUp(t){const e=a.getNextSibling(t,".".concat(this.className,"__content"));t.classList.remove("".concat(this.className,"__toggle--active")),t.parentNode.classList.remove("".concat(this.className,"__item--is-open")),t.setAttribute("aria-expanded","false"),e.style.height="0px",e.addEventListener("transitionend",()=>{e.classList.remove("".concat(this.className,"__content--active"))},{once:!0}),e.setAttribute("aria-hidden","true")}slideContentDown(t){const e=a.getNextSibling(t,".".concat(this.className,"__content")),s=(t.classList.add("".concat(this.className,"__toggle--active")),t.parentNode.classList.add("".concat(this.className,"__item--is-open")),t.setAttribute("aria-expanded","true"),e.classList.add("".concat(this.className,"__content--active")),e.style.height="auto",e.clientHeight+"px");e.style.height="0px",setTimeout(()=>{e.style.height=s},0),e.setAttribute("aria-hidden","false")}slideUpOthers(e,s){for(let t=0;t<s.length;t++)s[t]!==e&&s[t].classList.contains("".concat(this.className,"__toggle--active"))&&this.slideContentUp(s[t])}handleToggle(s){return t=>{t.preventDefault();const e=t.target.closest(".".concat(this.className,"__toggle"));e.classList.contains("".concat(this.className,"__toggle--active"))?this.slideContentUp(e):e.closest(".".concat(this.className)).classList.contains("".concat(this.className,"--is-manual"))?this.slideContentDown(e):(this.slideContentDown(e),this.slideUpOthers(e,s))}}init(){if(window.location.hash&&(this.hash=window.location.hash),this.hash&&""!==this.hash){var t=document.querySelector("".concat(this.hash,".").concat(this.className,"__content"));if(t){const n=a.getPrevSibling(t,".".concat(this.className,"__toggle"));this.slideContentDown(n),window.scrollTo(0,n.getBoundingClientRect().top)}}const e=document.querySelectorAll(".".concat(this.className)),s=(e.forEach(t=>{const e=t.querySelectorAll(".".concat(this.className,"__toggle"));e.forEach(t=>{t.addEventListener("click",this.handleToggle(e))})}),document.querySelectorAll(".".concat(this.className,"__content"))),i=this.className;s.forEach(function(t){var e=t.innerHTML,e=(t.innerHTML="",'<div class ="'+i+'__content-wrapper">'.concat(e,"</div>"));t.innerHTML=e})}}return t.accordion=a,Object.defineProperty(t,"__esModule",{value:!0}),t}({}); | ||
"use strict";var uq=function(t){class i{constructor(t){this.className=t=t||"uq-accordion",this.init()}static getNextSibling(t,e){var s=t.nextElementSibling;if(!e)return s;for(;s;){if(s.matches(e))return s;s=s.nextElementSibling}}static getPrevSibling(t,e){var s=t.previousElementSibling;if(!e)return s;for(;s;){if(s.matches(e))return s;s=s.previousElementSibling}}slideContentUp(t){const e=i.getNextSibling(t,".".concat(this.className,"__content"));t.classList.remove("".concat(this.className,"__toggle--active")),t.parentNode.classList.remove("".concat(this.className,"__item--is-open")),t.setAttribute("aria-expanded","false"),e.style.height="0px",e.addEventListener("transitionend",()=>{e.classList.remove("".concat(this.className,"__content--active"))},{once:!0}),e.setAttribute("aria-hidden","true")}slideContentDown(t){const e=i.getNextSibling(t,".".concat(this.className,"__content")),s=(t.classList.add("".concat(this.className,"__toggle--active")),t.parentNode.classList.add("".concat(this.className,"__item--is-open")),t.setAttribute("aria-expanded","true"),e.classList.add("".concat(this.className,"__content--active")),e.style.height="auto",e.clientHeight+"px");e.style.height="0px",setTimeout(()=>{e.style.height=s},0),e.setAttribute("aria-hidden","false")}slideUpOthers(e,s){for(let t=0;t<s.length;t++)s[t]!==e&&s[t].classList.contains("".concat(this.className,"__toggle--active"))&&this.slideContentUp(s[t])}handleToggle(e){return t=>{t.preventDefault();t=t.target.closest(".".concat(this.className,"__toggle"));t.classList.contains("".concat(this.className,"__toggle--active"))?this.slideContentUp(t):t.closest(".".concat(this.className)).classList.contains("".concat(this.className,"--is-manual"))?this.slideContentDown(t):(this.slideContentDown(t),this.slideUpOthers(t,e))}}init(){window.location.hash&&(this.hash=window.location.hash),this.hash&&""!==this.hash&&(t=document.querySelector("".concat(this.hash,".").concat(this.className,"__content")))&&(t=i.getPrevSibling(t,".".concat(this.className,"__toggle")),this.slideContentDown(t),window.scrollTo(0,t.getBoundingClientRect().top));document.querySelectorAll(".".concat(this.className)).forEach(t=>{const e=t.querySelectorAll(".".concat(this.className,"__toggle"));e.forEach(t=>{t.addEventListener("click",this.handleToggle(e))})});var t=document.querySelectorAll(".".concat(this.className,"__content"));const s=this.className;t.forEach(function(t){var e=t.innerHTML,e=(t.innerHTML="",'<div class ="'+s+'__content-wrapper">'.concat(e,"</div>"));t.innerHTML=e})}}return t.accordion=i,t}({}); |
{ | ||
"name": "@uqds/accordion", | ||
"version": "0.0.13-alpha.0", | ||
"version": "0.0.14-alpha.0", | ||
"description": "Accordion component", | ||
@@ -45,4 +45,4 @@ "keywords": [ | ||
"dependencies": { | ||
"@uqds/core": "^1.0.0", | ||
"@uqds/icon": "^0.0.13-alpha.0" | ||
"@uqds/core": "^1.1.0", | ||
"@uqds/icon": "^0.0.14-alpha.0" | ||
}, | ||
@@ -52,3 +52,3 @@ "devDependencies": { | ||
}, | ||
"gitHead": "07bdc5a8169d386baae8ea4ffa5b4a75fc7e9ebb" | ||
"gitHead": "3f399bb23a696bdfae45d2b23b6749dfad3aaf2d" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
24790
379
+ Added@uqds/icon@0.0.14-alpha.0(transitive)
- Removed@uqds/icon@0.0.13-alpha.0(transitive)
Updated@uqds/core@^1.1.0
Updated@uqds/icon@^0.0.14-alpha.0