Fix beforeunload event listeners
This commit is contained in:
@@ -6,13 +6,17 @@ export default class extends BridgeComponent {
|
||||
static targets = [ "button" ]
|
||||
|
||||
connect() {
|
||||
window.addEventListener("beforeunload", this.handleBeforeUnload.bind(this))
|
||||
window.addEventListener("turbo:before-visit", this.handleBeforeVisit.bind(this))
|
||||
if (!this.beforeUnloadHandler) {
|
||||
this.beforeUnloadHandler = this.handleBeforeUnload.bind(this)
|
||||
}
|
||||
|
||||
window.addEventListener("beforeunload", this.beforeUnloadHandler)
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
window.removeEventListener("beforeunload", this.handleBeforeUnload.bind(this))
|
||||
window.removeEventListener("turbo:before-visit", this.handleBeforeVisit.bind(this))
|
||||
if (this.beforeUnloadHandler) {
|
||||
window.removeEventListener("beforeunload", this.beforeUnloadHandler)
|
||||
}
|
||||
}
|
||||
|
||||
buttonTargetConnected() {
|
||||
@@ -45,10 +49,6 @@ export default class extends BridgeComponent {
|
||||
this.notifyBridgeOfDisconnect()
|
||||
}
|
||||
|
||||
handleBeforeVisit() {
|
||||
this.notifyBridgeOfDisconnect()
|
||||
}
|
||||
|
||||
#clickButton(message) {
|
||||
const selectedIndex = message.data.selectedIndex
|
||||
this.#enabledButtonTargets[selectedIndex].click()
|
||||
|
||||
@@ -7,13 +7,17 @@ export default class extends BridgeComponent {
|
||||
static values = { submitTitle: String }
|
||||
|
||||
connect() {
|
||||
window.addEventListener("beforeunload", this.handleBeforeUnload.bind(this))
|
||||
window.addEventListener("turbo:before-visit", this.handleBeforeVisit.bind(this))
|
||||
if (!this.beforeUnloadHandler) {
|
||||
this.beforeUnloadHandler = this.handleBeforeUnload.bind(this)
|
||||
}
|
||||
|
||||
window.addEventListener("beforeunload", this.beforeUnloadHandler)
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
window.removeEventListener("beforeunload", this.handleBeforeUnload.bind(this))
|
||||
window.removeEventListener("turbo:before-visit", this.handleBeforeVisit.bind(this))
|
||||
if (this.beforeUnloadHandler) {
|
||||
window.removeEventListener("beforeunload", this.beforeUnloadHandler)
|
||||
}
|
||||
}
|
||||
|
||||
submitTargetConnected() {
|
||||
@@ -63,10 +67,6 @@ export default class extends BridgeComponent {
|
||||
this.notifyBridgeOfDisconnect()
|
||||
}
|
||||
|
||||
handleBeforeVisit() {
|
||||
this.notifyBridgeOfDisconnect()
|
||||
}
|
||||
|
||||
#observeSubmitTarget() {
|
||||
this.submitObserver = new MutationObserver(() => {
|
||||
this.send(this.submitTarget.disabled ? "submitDisabled" : "submitEnabled")
|
||||
|
||||
Reference in New Issue
Block a user