1import{Controller}from"@hotwired/stimulus";export default class extends Controller{static values={path:String,method:{type:String,default:"post"}};connect(){console.log("MainToggle Stimulus controller connected!",this.element)}async toggle(e){e.preventDefault();if(!this.pathValue||"#"===this.pathValue||this.pathValue.includes("/admin/mds/")||window.location.pathname.includes("/rails/view_components"))this.toggleVisualState();else{this.element.setAttribute("data-loading","true");try{const e=await fetch(this.pathValue,{method:this.methodValue.toUpperCase(),headers:{"X-CSRF-Token":document.querySelector('[name="csrf-token"]').content,Accept:"application/json"}});e.ok?location.replace(location.pathname):(console.error("MainToggle: Request failed",e.status),this.element.setAttribute("data-loading","false"))}catch(e){console.error("MainToggle: Error during toggle",e),this.element.setAttribute("data-loading","false")}}}toggleVisualState(){const e=this.element.querySelector(".mds-toggle-slider"),t=this.element.querySelector(".mds-toggle-small-toggle-slider");if(!e&&!t)return void console.warn("Slider element not found");if(t)return void(t.classList.contains("mds-toggle-small-toggle-slider-left")?(t.classList.remove("mds-toggle-small-toggle-slider-left"),t.classList.add("mds-toggle-small-toggle-slider-right"),this.element.classList.remove("mds-toggle-small-toggle-left"),this.element.classList.add("mds-toggle-small-toggle-right"),this.element.setAttribute("aria-checked","true")):(t.classList.remove("mds-toggle-small-toggle-slider-right"),t.classList.add("mds-toggle-small-toggle-slider-left"),this.element.classList.remove("mds-toggle-small-toggle-right"),this.element.classList.add("mds-toggle-small-toggle-left"),this.element.setAttribute("aria-checked","false")));const l=this.element.querySelector(".mds-toggle-left-option"),s=this.element.querySelector(".mds-toggle-right-option");l&&s?e.classList.contains("mds-toggle-slider-left")?(e.classList.remove("mds-toggle-slider-left"),e.classList.add("mds-toggle-slider-right"),this.element.setAttribute("aria-checked","true"),this.updateSliderContent(e,s)):(e.classList.remove("mds-toggle-slider-right"),e.classList.add("mds-toggle-slider-left"),this.element.setAttribute("aria-checked","false"),this.updateSliderContent(e,l)):console.warn("Left or right option elements not found")}updateSliderContent(e,t){e.innerHTML="";const l=t.querySelector("svg"),s=t.querySelector(".mds-toggle-label");l&&e.appendChild(l.cloneNode(!0)),s&&e.appendChild(s.cloneNode(!0))}}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.