diff --git a/static/application.js b/static/application.js
index e6c05c08..04cf862e 100644
--- a/static/application.js
+++ b/static/application.js
@@ -79,7 +79,7 @@ var sman_allow_delete = false;
var sman_allow_rename = false;
// This is true iff [we're in macOS and the browser is Safari] or [we're in iOS]
-var using_webkit_patch = false;
+var using_webkit_patch = null;
// Key states
var shift_down = false;
@@ -1105,35 +1105,6 @@ $(document).ready(function(){
seqselmenu = $("#seqselmenu");
seqselcontents = $("#seqselcontents");
- // A simple feature detection test to determine whether the user interface
- // is using WebKit (Safari browser's rendering engine) because WebKit
- // requires special treatment to work correctly with the KoboldAI editor
- using_webkit_patch = (function() {
- try {
- var active_element = document.activeElement;
- var c = document.createElement("chunk");
- var t = document.createTextNode("KoboldAI");
- c.appendChild(t);
- game_text[0].appendChild(c);
- var r = rangy.createRange();
- r.setStart(t, 6);
- r.collapse(true);
- var s = rangy.getSelection();
- s.removeAllRanges();
- s.addRange(r);
- game_text.blur();
- game_text.focus();
- var offset = rangy.getSelection().focusOffset;
- c.removeChild(t);
- game_text[0].removeChild(c);
- document.activeElement.blur();
- active_element.focus();
- return offset !== 6;
- } catch (e) {
- return false;
- }
- })();
-
// Connect to SocketIO server
socket = io.connect(window.document.origin);
@@ -1158,6 +1129,36 @@ $(document).ready(function(){
game_text.attr('contenteditable', allowedit);
}
});
+ // A simple feature detection test to determine whether the user interface
+ // is using WebKit (Safari browser's rendering engine) because WebKit
+ // requires special treatment to work correctly with the KoboldAI editor
+ if(using_webkit_patch === null) {
+ using_webkit_patch = (function() {
+ try {
+ var active_element = document.activeElement;
+ var c = document.createElement("chunk");
+ var t = document.createTextNode("KoboldAI");
+ c.appendChild(t);
+ game_text[0].appendChild(c);
+ var r = rangy.createRange();
+ r.setStart(t, 6);
+ r.collapse(true);
+ var s = rangy.getSelection();
+ s.removeAllRanges();
+ s.addRange(r);
+ game_text.blur();
+ game_text.focus();
+ var offset = rangy.getSelection().focusOffset;
+ c.removeChild(t);
+ game_text[0].removeChild(c);
+ document.activeElement.blur();
+ active_element.focus();
+ return offset !== 6;
+ } catch (e) {
+ return false;
+ }
+ })();
+ }
} else if(msg.cmd == "updatescreen") {
var _gamestarted = gamestarted;
gamestarted = msg.gamestarted;
diff --git a/templates/index.html b/templates/index.html
index 3a078f88..55978aec 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -6,7 +6,7 @@
-
+