Download app/javascript/controllers/locale_dropdown_controller.js from denise-oneill-inbox-ru/Rails-8-API-Image-Processing: direct link, hf CLI and curl.
- Browser
- Download file 798 Bytes
-
https://huggingface.co/spaces/denise-oneill-inbox-ru/Rails-8-API-Image-Processing/resolve/main/app/javascript/controllers/locale_dropdown_controller.js
- Command line
-
hf download hf://spaces/denise-oneill-inbox-ru/Rails-8-API-Image-Processing/app/javascript/controllers/locale_dropdown_controller.js
-
curl -L -o locale_dropdown_controller.js https://huggingface.co/spaces/denise-oneill-inbox-ru/Rails-8-API-Image-Processing/resolve/main/app/javascript/controllers/locale_dropdown_controller.js
798 Bytes
| import { Controller } from "@hotwired/stimulus" | |
| export default class extends Controller { | |
| static targets = ["button", "menu"] | |
| connect() { | |
| this.boundClickOutside = this.clickOutside.bind(this) | |
| document.addEventListener("click", this.boundClickOutside) | |
| } | |
| disconnect() { | |
| document.removeEventListener("click", this.boundClickOutside) | |
| } | |
| toggle() { | |
| const open = this.menuTarget.classList.toggle("hidden") === false | |
| this.buttonTarget.setAttribute("aria-expanded", open) | |
| if (open) this.menuTarget.focus() | |
| } | |
| clickOutside(event) { | |
| if (!this.element.contains(event.target)) { | |
| this.close() | |
| } | |
| } | |
| close() { | |
| this.menuTarget.classList.add("hidden") | |
| this.buttonTarget.setAttribute("aria-expanded", "false") | |
| this.buttonTarget.focus() | |
| } | |
| } | |