1(function () { 2 class BreakdanceSearchForm { 3 constructor(selector) { 4 this.selector = selector; 5 this.element = this.queryElement(`${this.selector} .js-search-form`); 6 this.type = this.element.dataset.type; 7 this.expandButton = this.queryElement( 8 `${this.selector} .js-search-form-expand-button` 9 ); 10 this.closeButton = this.queryElement( 11 `${this.selector} .js-search-form-close` 12 ); 13 this.searchField = this.queryElement( 14 `${this.selector} .js-search-form-field` 15 ); 16 this.lightboxBg = this.queryElement( 17 `${this.selector} .js-search-form-lightbox-bg` 18 ); 19 this.lightbox = this.queryElement(`${this.selector} .js-search-form-lightbox`); 20 21 this.previousFocus = null; 22 23 this.init(); 24 } 25 26 queryElement(element) { 27 if (typeof element == "string") { 28 return document.querySelector(element); 29 } 30 return element; 31 } 32 33 toggleForm() { 34 this.element.classList.toggle("is-active"); 35 this.element.setAttribute("aria-hidden", "false"); 36 this.expandButton.setAttribute("aria-expanded", "true"); 37 38 this.lightbox.addEventListener("transitionend", this.handleAutofocus, { 39 once: true 40 }); 41 } 42 43 closeFormEscape(event) { 44 if (event.key !== "Escape") return; 45 this.closeForm(); 46 } 47 48 closeForm() { 49 this.lightbox.addEventListener("transitionend", this.handleAutofocus, { 50 once: true 51 }); 52 53 this.element.classList.remove("is-active"); 54 this.element.setAttribute("aria-hidden", "true"); 55 this.expandButton.setAttribute("aria-expanded", "false"); 56 } 57 58 // Methods 59 destroy() { 60 if (this.type === "expand") { 61 this.expandButton.removeEventListener("click", this.handleToggleForm); 62 } 63 64 if (this.type === "full-screen") { 65 this.expandButton.removeEventListener("click", this.handleToggleForm); 66 this.closeButton.removeEventListener("click", this.handleCloseForm); 67 this.lightbox.removeEventListener("transitionend", this.handleAutofocus); 68 this.lightboxBg.removeEventListener("click", this.handleCloseForm); 69 removeEventListener("keydown", this.handleCloseFromEscape); 70 } 71 } 72 73 handleAutofocus() { 74 if (this.element.classList.contains("is-active")) { 75 this.previousFocus = document.activeElement; 76 this.searchField.focus(); 77 } else if (this.previousFocus) { 78 this.previousFocus?.focus(); 79 this.previousFocus = null; 80 } else { 81 this.searchField.blur(); 82 } 83 } 84 85 update() { 86 this.destroy(); 87 this.init(); 88 } 89 90 bindListeners() { 91 this.handleToggleForm = this.toggleForm.bind(this); 92 this.handleCloseForm = this.closeForm.bind(this); 93 this.handleCloseFromEscape = this.closeFormEscape.bind(this); 94 this.handleAutofocus = this.handleAutofocus.bind(this); 95 96 if (this.type === "expand") { 97 this.expandButton.addEventListener("click", this.handleToggleForm); 98 } 99 100 if (this.type === "full-screen") { 101 this.expandButton.addEventListener("click", this.handleToggleForm); 102 this.closeButton.addEventListener("click", this.handleCloseForm); 103 this.lightboxBg.addEventListener("click", this.handleCloseForm); 104 addEventListener("keydown", this.handleCloseFromEscape); 105 } 106 } 107 108 init() { 109 this.bindListeners(); 110 } 111 } 112 113 window.BreakdanceSearchForm = BreakdanceSearchForm; 114})();
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.