From 613554f960c73d808b04c32cf16e9afc3fc8309c Mon Sep 17 00:00:00 2001
From: Vasileios Pasialiokis <whiterocket@outlook.com>
Date: Tue, 10 Apr 2018 22:15:30 +0300
Subject: [PATCH] html5passage

---
 src/js/rulesAssistantOptions.tw     | 10 ++--------
 src/js/utilJS.tw                    | 13 ++++++++++++-
 src/uncategorized/rulesAssistant.tw |  2 +-
 3 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/src/js/rulesAssistantOptions.tw b/src/js/rulesAssistantOptions.tw
index 820d0ba0145..bbb02903f18 100644
--- a/src/js/rulesAssistantOptions.tw
+++ b/src/js/rulesAssistantOptions.tw
@@ -11,20 +11,14 @@ window.rulesAssistantOptions = (function() {
 	let V
 	let r = ""
 
-	function rulesAssistantOptions() {
+	function rulesAssistantOptions(element) {
 		V = State.variables
 		V.nextButton = "Back to Main"
 		V.nextLink = "Main"
 		V.returnTo = "Main"
 		V.showEncyclopedia = 1
 		V.encyclopedia = "Personal Assistant"
-		
-		let tmp = document.createElement("div")
-		tmp.classList.add("passage")
-		tmp.classList.add("rules-assistant-options")
-		document.getElementById("passages").appendChild(tmp)
-
-		const root = new Root(tmp)
+		const root = new Root(element)
 	}
 
 	function onreturn(e, cb) {
diff --git a/src/js/utilJS.tw b/src/js/utilJS.tw
index b1258a2583e..8ad5cdb542e 100644
--- a/src/js/utilJS.tw
+++ b/src/js/utilJS.tw
@@ -518,8 +518,19 @@ window.generateNewID = function generateNewID() {
 	return randint + timestamp.toString(36);
 };
 
-window.arraySwap(array, a, b) {
+window.arraySwap = function arraySwap(array, a, b) {
 	const tmp = array[a];
 	array[b] = array[a];
 	array[a] = tmp;
 };
+
+// circumvents sugarcube, allowing a plain HTML5 UI within it
+window.html5passage = function html5passage(passage_function) {
+	$(document).one(':passagedisplay', ev => {
+		const element = document.createElement("div");
+		element.classList.add("passage");
+		document.getElementById("passages").appendChild(element);
+		passage_function(element);
+		$(document).off(':passagedisplay');
+	});
+};
diff --git a/src/uncategorized/rulesAssistant.tw b/src/uncategorized/rulesAssistant.tw
index 6b645e21166..f4ca87d0eec 100644
--- a/src/uncategorized/rulesAssistant.tw
+++ b/src/uncategorized/rulesAssistant.tw
@@ -1,6 +1,6 @@
 :: Rules Assistant [nobr]
 
-<<script>>$(document).one(':passagedisplay', ev => { rulesAssistantOptions(); $(document).off(':passagedisplay') })<</script>>
+<<script>>html5passage(rulesAssistantOptions)<</script>>
 /*
 <<set $nextButton = "Back to Main", $nextLink = "Main", $returnTo = "Main">>
 <<set $showEncyclopedia = 1, $encyclopedia = "Personal Assistant">>
-- 
GitLab