oldController.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. for(let button of this.querySelectorAll("button")){
  18. button.onclick = ()=>{
  19. this.setAttribute("strand", button.strandName.slice(0, button.strandName.indexOf("Strand")));
  20. window[`${button.strandName.slice(0, button.strandName.indexOf("Strand"))}Obj`].display();
  21. }
  22. }
  23. strands[0].style.display = "flex";
  24. })
  25. }
  26. static get observedAttributes(){
  27. return ["strand"];
  28. }
  29. attributeChangedCallback(){
  30. setTimeout(()=>{
  31. let buttons = this.querySelectorAll("button");
  32. for(let button of buttons){
  33. if(button.innerText.toLowerCase() === this.getAttribute("strand").toLowerCase()){
  34. button.style.borderBottom = "3px solid black";
  35. button.style.cursor = "pointer";
  36. }else{
  37. button.style.borderBottom = "none";
  38. button.style.cursor = "pointer";
  39. }
  40. }
  41. })
  42. }
  43. }
  44. customElements.define("strand-selector", StrandSelector);
  45. let actions = document.querySelectorAll(".action");
  46. for(let action of actions){
  47. action.display = ()=>{window[`${action.id.slice(0, action.id.indexOf("Action"))}Obj`].display();};
  48. }
  49. let strands = document.querySelectorAll(".strand");
  50. for(let strand of strands){
  51. strand.display = ()=>{window[`${strand.id.slice(0, strand.id.indexOf("Strand"))}Obj`].display();};
  52. }
  53. window.clearScreen = ()=>{
  54. let subpages = document.querySelectorAll(".strand, .action");
  55. for(let subpage of subpages){
  56. subpage.style.display = "none";
  57. }
  58. }