controller.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. class StrandSelector extends HTMLElement{
  2. constructor(){
  3. super();
  4. }
  5. connectedCallback(){
  6. setTimeout(()=>{
  7. let firstStrand = document.querySelector(".strand");
  8. this.setAttribute("strand", firstStrand.id.slice(0, firstStrand.id.indexOf("Strand")));
  9. window[`${firstStrand.id.slice(0, firstStrand.id.indexOf("Strand"))}Obj`].display();
  10. let strands = document.querySelectorAll(".strand");
  11. for(let strand of strands){
  12. let selector = document.createElement("button");
  13. selector.strandName = strand.id;
  14. selector.innerText = strand.id.slice(0, strand.id.indexOf("Strand")).toUpperCase();
  15. this.appendChild(selector);
  16. }
  17. strands[0].style.display = "flex";
  18. })
  19. }
  20. static get observedAttributes(){
  21. return ["strand"];
  22. }
  23. attributeChangedCallback(){
  24. setTimeout(()=>{
  25. let buttons = this.querySelectorAll("button");
  26. for(let button of buttons){
  27. if(button.innerText.toLowerCase() === this.getAttribute("strand").toLowerCase()){
  28. button.style.borderBottom = "3px solid black";
  29. button.style.cursor = "pointer";
  30. }else{
  31. button.style.borderBottom = "none";
  32. button.style.cursor = "pointer";
  33. button.onclick = ()=>{
  34. this.setAttribute("strand", button.strandName.slice(0, button.strandName.indexOf("Strand")));
  35. window[`${button.strandName.slice(0, button.strandName.indexOf("Strand"))}Obj`].display();
  36. }
  37. }
  38. }
  39. })
  40. }
  41. }
  42. customElements.define("strand-selector", StrandSelector);
  43. let actions = document.querySelectorAll(".action");
  44. for(let action of actions){
  45. action.display = ()=>{window[`${action.id.slice(0, action.id.indexOf("Action"))}Obj`].display();};
  46. }
  47. let strands = document.querySelectorAll(".strand");
  48. for(let strand of strands){
  49. strand.display = ()=>{window[`${strand.id.slice(0, strand.id.indexOf("Strand"))}Obj`].display();};
  50. }
  51. window.clearScreen = ()=>{
  52. let subpages = document.querySelectorAll(".strand, .action");
  53. for(let subpage of subpages){
  54. subpage.style.display = "none";
  55. }
  56. }