From d3f6f5ff196669ac7757369f5ef704a7c1c0616e Mon Sep 17 00:00:00 2001
From: Arkerthan <arkerthan@gmail.com>
Date: Sun, 17 May 2020 22:53:42 +0200
Subject: [PATCH] execute passageSwitchHandler regardless of route

---
 src/gui/storyCaptionWidgets.tw       | 4 ----
 src/interaction/policies/policies.tw | 2 +-
 src/uncategorized/options.tw         | 2 +-
 src/uncategorized/summaryOptions.tw  | 2 +-
 src/zz1-last/setupEventHandlers.js   | 9 ++++++++-
 5 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/src/gui/storyCaptionWidgets.tw b/src/gui/storyCaptionWidgets.tw
index 7e20114b35f..9efbfd1e31e 100644
--- a/src/gui/storyCaptionWidgets.tw
+++ b/src/gui/storyCaptionWidgets.tw
@@ -16,10 +16,6 @@
 			<strong><div id="nextButton">
 			<<if $nextButton != " ">>
 				<<link "$nextButton">>
-					<<if _passageSwitchHandler>>
-						<<run _passageSwitchHandler();>>
-						<<set _passageSwitchHandler = null>>
-					<</if>>
 					<<goto $nextLink>>
 				<</link>> @@.cyan;[Space]@@
 			<</if>>
diff --git a/src/interaction/policies/policies.tw b/src/interaction/policies/policies.tw
index 630654d3e3e..29c2524ffa8 100644
--- a/src/interaction/policies/policies.tw
+++ b/src/interaction/policies/policies.tw
@@ -7,7 +7,7 @@
 </style>
 
 <<set $nextButton = "Back">>
-<<set _passageSwitchHandler = App.EventHandlers.societyChanged>>
+<<set $passageSwitchHandler = App.EventHandlers.societyChanged>>
 <<if $arcologies[0].FSSupremacistLawME && $PC.race != $arcologies[0].FSSupremacistRace>>
 	<<set $nextLink = "Gameover", $gameover = "Idiot Ball 2 The Dumbassening">>
 <<elseif $arcologies[0].FSSubjugationistLawME && $PC.race == $arcologies[0].FSSubjugationistRace>>
diff --git a/src/uncategorized/options.tw b/src/uncategorized/options.tw
index cb985f3f58f..739b3ee57c0 100644
--- a/src/uncategorized/options.tw
+++ b/src/uncategorized/options.tw
@@ -23,7 +23,7 @@
 <</if>>
 
 <<set $nextButton = "Back", $nextLink = $storedLink, $encyclopedia = "How to Play">>
-<<set _passageSwitchHandler = App.EventHandlers.optionsChanged>>
+<<set $passageSwitchHandler = App.EventHandlers.optionsChanged>>
 
 <<set _options = new App.UI.OptionsGroup()>>
 <<run _options.addOption("End of week autosaving is currently", "autosave")
diff --git a/src/uncategorized/summaryOptions.tw b/src/uncategorized/summaryOptions.tw
index 62115362074..bb269e7d04b 100644
--- a/src/uncategorized/summaryOptions.tw
+++ b/src/uncategorized/summaryOptions.tw
@@ -9,7 +9,7 @@
 	<</if>>
 <</if>>
 <<set $nextLink = $storedLink>>
-<<set _passageSwitchHandler = App.EventHandlers.optionsChanged>>
+<<set $passageSwitchHandler = App.EventHandlers.optionsChanged>>
 
 <h1>Summary Options</h1>
 
diff --git a/src/zz1-last/setupEventHandlers.js b/src/zz1-last/setupEventHandlers.js
index 44cba09f389..0a6ef416022 100644
--- a/src/zz1-last/setupEventHandlers.js
+++ b/src/zz1-last/setupEventHandlers.js
@@ -2,7 +2,7 @@
 Config.saves.onLoad = App.EventHandlers.onLoad;
 Config.saves.onSave = App.EventHandlers.onSave;
 
-$(document).on(':storyready', function(ev) {
+$(document).on(':storyready', function() {
 	App.EventHandlers.storyReady();
 });
 
@@ -15,3 +15,10 @@ $(document).on(':passagestart', function() {
 		get: () => S
 	});
 });
+
+$(document).on("passageinit", () => {
+	if (V.passageSwitchHandler) {
+		V.passageSwitchHandler();
+		delete V.passageSwitchHandler;
+	}
+});
-- 
GitLab