-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsol-accordion.js
36 lines (35 loc) · 1.36 KB
/
sol-accordion.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import {demo} from './utils/view.js';
export class SolAccordion extends HTMLElement {
constructor() {
super();
}
connectedCallback(){
let wantedHeader = this.getAttribute('header');
let nodes = this.querySelectorAll(wantedHeader);
for(let node of nodes){
let inner = node.nextSibling;
inner.className = "hidden";
// inner.classList.add('sol-modal');
let closeButton = document.createElement('DIV');
closeButton.style = "color:red;font-size: 2rem;font-weight:bold;cursor:pointer;position:relative;right:0; top:0;text-align:right";
closeButton.setAttribute('onclick',"this.parentNode.classList.toggle('hidden')");
closeButton.innerHTML = "×";
// if(inner.hasAttribute('demo')) inner.innerHTML = demo(inner.innerHTML) + innerHTML;
inner.innerHTML = closeButton.outerHTML+inner.innerHTML;
node.style.cursor="pointer";
node.style.display="inline-block !important";
node.style.float="left";
node.onclick = (event)=> {
// node.scrollIntoView(true);
for(let n of nodes){
let inner2 = n.nextSibling;
if(inner2 !=inner) inner2.className = "hidden";
n.className = "hidden";
}
inner.classList.toggle("hidden");
node.classList.toggle("hidden");
}
}
}
}
customElements.define("sol-accordion",SolAccordion);