Prevent scope leakage of some variables in application.js

This commit is contained in:
Gnome Ann 2021-09-01 14:01:04 -04:00
parent 6bd6415749
commit f1633d3e5c
1 changed files with 17 additions and 17 deletions

View File

@ -287,7 +287,7 @@ function addWiLine(ob) {
disableWiSelective(ob.num); disableWiSelective(ob.num);
}); });
$("#constant-key-"+ob.num).on("click", function () { $("#constant-key-"+ob.num).on("click", function () {
element = $("#constant-key-"+ob.num); var element = $("#constant-key-"+ob.num);
if(element.hasClass("constant-key-icon-enabled")) { if(element.hasClass("constant-key-icon-enabled")) {
socket.send({'cmd': 'wiconstantoff', 'data': ob.num}); socket.send({'cmd': 'wiconstantoff', 'data': ob.num});
element.removeClass("constant-key-icon-enabled") element.removeClass("constant-key-icon-enabled")
@ -607,7 +607,7 @@ function buildLoadList(ar) {
} }
$("#newsavename").val("") $("#newsavename").val("")
$("#loadcontainerrename-storyname").text(name); $("#loadcontainerrename-storyname").text(name);
submit = (function (name) { var submit = (function (name) {
return function () { return function () {
hide([$(".saveasoverwrite"), $(".popuperror")]); hide([$(".saveasoverwrite"), $(".popuperror")]);
socket.send({'cmd': 'renamestory', 'data': name, 'newname': $("#newsavename").val()}); socket.send({'cmd': 'renamestory', 'data': name, 'newname': $("#newsavename").val()});
@ -730,26 +730,26 @@ function chunkOnKeyDown(event) {
switch(event.keyCode) { switch(event.keyCode) {
case 37: // left case 37: // left
case 39: // right case 39: // right
old_range = getSelection().getRangeAt(0); var old_range = getSelection().getRangeAt(0);
old_range_start = old_range.startOffset; var old_range_start = old_range.startOffset;
old_range_end = old_range.endOffset; var old_range_end = old_range.endOffset;
old_range_ancestor = old_range.commonAncestorContainer; var old_range_ancestor = old_range.commonAncestorContainer;
old_range_start_container = old_range.startContainer; var old_range_start_container = old_range.startContainer;
old_range_end_container = old_range.endContainer; var old_range_end_container = old_range.endContainer;
setTimeout(function () { setTimeout(function () {
// Wait a few milliseconds and check if the caret has moved // Wait a few milliseconds and check if the caret has moved
new_selection = getSelection(); var new_selection = getSelection();
new_range = new_selection.getRangeAt(0); var new_range = new_selection.getRangeAt(0);
if(old_range_start != new_range.startOffset || old_range_end != new_range.endOffset || old_range_ancestor != new_range.commonAncestorContainer || old_range_start_container != new_range.startContainer || old_range_end_container != new_range.endContainer) { if(old_range_start != new_range.startOffset || old_range_end != new_range.endOffset || old_range_ancestor != new_range.commonAncestorContainer || old_range_start_container != new_range.startContainer || old_range_end_container != new_range.endContainer) {
return; return;
} }
// If it hasn't moved, we're at the beginning or end of a chunk // If it hasn't moved, we're at the beginning or end of a chunk
// and the caret must be moved to a different chunk // and the caret must be moved to a different chunk
chunk = document.activeElement; var chunk = document.activeElement;
switch(event.keyCode) { switch(event.keyCode) {
case 37: // left case 37: // left
if((chunk = chunk.previousSibling) && chunk.tagName == "CHUNK") { if((chunk = chunk.previousSibling) && chunk.tagName == "CHUNK") {
range = document.createRange(); var range = document.createRange();
range.selectNodeContents(chunk); range.selectNodeContents(chunk);
range.collapse(false); range.collapse(false);
new_selection.removeAllRanges(); new_selection.removeAllRanges();
@ -766,7 +766,7 @@ function chunkOnKeyDown(event) {
return; return;
case 8: // backspace case 8: // backspace
old_length = document.activeElement.innerText.length; var old_length = document.activeElement.innerText.length;
setTimeout(function () { setTimeout(function () {
// Wait a few milliseconds and compare the chunk's length // Wait a few milliseconds and compare the chunk's length
if(old_length != document.activeElement.innerText.length) { if(old_length != document.activeElement.innerText.length) {
@ -774,8 +774,8 @@ function chunkOnKeyDown(event) {
} }
// If it's the same, we're at the beginning of a chunk // If it's the same, we're at the beginning of a chunk
if((chunk = document.activeElement.previousSibling) && chunk.tagName == "CHUNK") { if((chunk = document.activeElement.previousSibling) && chunk.tagName == "CHUNK") {
range = document.createRange(); var range = document.createRange();
selection = getSelection(); var selection = getSelection();
range.selectNodeContents(chunk); range.selectNodeContents(chunk);
range.collapse(false); range.collapse(false);
selection.removeAllRanges(); selection.removeAllRanges();
@ -814,7 +814,7 @@ function submitEditedChunk(event) {
return; return;
} }
chunk = current_editing_chunk; var chunk = current_editing_chunk;
current_editing_chunk = null; current_editing_chunk = null;
// Submit the edited chunk if it's not empty, otherwise delete it // Submit the edited chunk if it's not empty, otherwise delete it
@ -916,7 +916,7 @@ $(document).ready(function(){
} }
}); });
} else if(msg.cmd == "updatescreen") { } else if(msg.cmd == "updatescreen") {
_gamestarted = gamestarted; var _gamestarted = gamestarted;
gamestarted = msg.gamestarted; gamestarted = msg.gamestarted;
if(_gamestarted != gamestarted) { if(_gamestarted != gamestarted) {
action_mode = 0; action_mode = 0;