From 2bd99f9e2e92e22e24c3f43baf048cd85889235d Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Fri, 23 Dec 2022 18:42:20 +0100 Subject: [PATCH] Various fixes for running with advanced JS optimizations, if we want to do that in the future. --- www/js/chessboard-0.3.0.js | 4 ++-- www/js/json_delta.js | 49 +++++++++++++++++++------------------- www/js/remoteglot.js | 12 +++++----- 3 files changed, 33 insertions(+), 32 deletions(-) diff --git a/www/js/chessboard-0.3.0.js b/www/js/chessboard-0.3.0.js index 2ad6f44..e15ab00 100644 --- a/www/js/chessboard-0.3.0.js +++ b/www/js/chessboard-0.3.0.js @@ -768,7 +768,7 @@ function animateSparePieceToSquare(piece, dest, completeFn) { duration: cfg.moveSpeed, complete: complete }; - $(animatedPieceEl).animate(destOffset, opts); + //$(animatedPieceEl).animate(destOffset, opts); } function fadeIn(piece, onFinish) { @@ -1141,7 +1141,7 @@ function trashDraggedPiece() { // hide the dragged piece // FIXME: support this for non-jquery - $(draggedPieceEl).fadeOut(cfg.trashSpeed); + //$(draggedPieceEl).fadeOut(cfg.trashSpeed); // set state DRAGGING_A_PIECE = false; diff --git a/www/js/json_delta.js b/www/js/json_delta.js index 91b17e1..f6417df 100644 --- a/www/js/json_delta.js +++ b/www/js/json_delta.js @@ -29,7 +29,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. This implementation is based heavily on the original python2 version: see http://www.phil-roberts.name/json-delta/ for further documentation. */ -JSON_delta = { +const JSON_delta = { isStrictlyEqual: function (left, right) { if (this.isTerminal(left) && this.isTerminal(right)) { return (left === right); @@ -41,7 +41,7 @@ JSON_delta = { if (left.length != right.length) { return false; } - for (idx in left) { + for (let idx in left) { if ( ! this.isStrictlyEqual(left[idx], right[idx])) { return false; } @@ -55,7 +55,7 @@ JSON_delta = { if (ks[1].length != 0 || ks[2].length != 0) { return false; } - for (key in ks[0]) { + for (let key in ks[0]) { key = ks[0][key]; if ( ! this.isStrictlyEqual(left[key], right[key])) { return false @@ -75,7 +75,7 @@ JSON_delta = { splitDeletions: function (diff) { if (diff.length == 0) {return [[], diff]} diff.sort(function (a,b) {return b.length-a.length}); - for (idx in diff) { + for (var idx in diff) { if (diff[idx].length === 1) {break} } return [diff.slice(0,idx), diff.slice(idx)] @@ -109,7 +109,7 @@ JSON_delta = { var target = overlap; var targ_num = (left instanceof Array); - for (key in left) { + for (let key in left) { if (targ_num) { key = Number(key) } @@ -121,7 +121,7 @@ JSON_delta = { } target.push(key); } - for (key in right) { + for (let key in right) { if (targ_num) { key = Number(key) } @@ -135,12 +135,13 @@ JSON_delta = { commonality: function (left, right) { var com = 0; var tot = 0; + var elem; if (this.isTerminal(left) || this.isTerminal(right)) { return 0; } if ((left instanceof Array) && (right instanceof Array)) { - for (idx in left) { + for (let idx in left) { elem = left[idx]; if (right.indexOf(elem) != -1) { com += 1; @@ -153,10 +154,10 @@ JSON_delta = { } else { var ks = this.computeKeysets(left, right); - o = ks[0]; l = ks[1]; r = ks[2]; + let o = ks[0]; let l = ks[1]; let r = ks[2]; com = o.length; tot = o.length + l.length + r.length; - for (idx in r) { + for (let idx in r) { elem = r[idx]; if (l.indexOf(elem) == -1) { tot += 1 @@ -180,18 +181,18 @@ JSON_delta = { if (common) { var ks = this.computeKeysets(left, right); - for (idx in ks[0]) { - okey = ks[0][idx]; + for (let idx in ks[0]) { + let okey = ks[0][idx]; if (left[okey] != right[okey]) { out.push([key.concat([okey]), right[okey]]); } } - for (idx in ks[1]) { - okey = ks[1][idx]; + for (let idx in ks[1]) { + let okey = ks[1][idx]; out.push([key.concat([okey])]); } - for (idx in ks[2]) { - okey = ks[2][idx]; + for (let idx in ks[2]) { + let okey = ks[2][idx]; out.push([key.concat([okey]), right[okey]]); } return out @@ -207,13 +208,13 @@ JSON_delta = { keysetDiff: function (left, right, key) { var out = []; var ks = this.computeKeysets(left, right); - for (k in ks[1]) { + for (let k in ks[1]) { out.push([key.concat(ks[1][k])]); } - for (k in ks[2]) { + for (let k in ks[2]) { out.push([key.concat(ks[2][k]), right[ks[2][k]]]); } - for (k in ks[0]) { + for (let k in ks[0]) { out = out.concat(this.diff(left[ks[0][k]], right[ks[0][k]], key.concat([ks[0][k]]))) } @@ -223,7 +224,7 @@ JSON_delta = { patchStanza: function (struc, diff) { // Applies the diff stanza diff to the structure struc. Returns // the modified structure. - key = diff[0]; + let key = diff[0]; switch (key.length) { case 0: struc = diff[1]; @@ -242,9 +243,9 @@ JSON_delta = { } break; default: - pass_key = key.slice(1); - pass_struc = struc[key[0]]; - pass_diff = [pass_key].concat(diff.slice(1)); + let pass_key = key.slice(1); + let pass_struc = struc[key[0]]; + let pass_diff = [pass_key].concat(diff.slice(1)); struc[key[0]] = this.patchStanza(pass_struc, pass_diff); } return struc; @@ -253,7 +254,7 @@ JSON_delta = { patch: function (struc, diff) { // Applies the sequence of diff stanzas diff to the structure // struc, and returns the patched structure. - for (stan_key in diff) { + for (let stan_key in diff) { struc = this.patchStanza(struc, diff[stan_key]); } return struc @@ -265,7 +266,7 @@ JSON_delta = { var dumbdiff = [[key, right]] var my_diff = []; - common = this.commonality(left, right); + let common = this.commonality(left, right); if (common < 0.5) { my_diff = this.thisLevelDiff(left, right, key, common); } diff --git a/www/js/remoteglot.js b/www/js/remoteglot.js index beaf63f..f252f5b 100644 --- a/www/js/remoteglot.js +++ b/www/js/remoteglot.js @@ -244,12 +244,12 @@ var supports_html5_storage = function() { // Of course, you can never fully protect against people deliberately wanting to spam. var get_unique = function() { var use_local_storage = supports_html5_storage(); - if (use_local_storage && localStorage['unique']) { - return localStorage['unique']; + if (use_local_storage && window['localStorage']['unique']) { + return window['localStorage']['unique']; } var unique = Math.random(); if (use_local_storage) { - localStorage['unique'] = unique; + window['localStorage']['unique'] = unique; } return unique; } @@ -1971,7 +1971,7 @@ var set_sound = function(param_enable_sound) { document.getElementById("soundoff").innerHTML = "Off"; } if (supports_html5_storage()) { - localStorage['enable_sound'] = enable_sound ? 1 : 0; + window['localStorage']['enable_sound'] = enable_sound ? 1 : 0; } } window['set_sound'] = set_sound; @@ -2414,8 +2414,8 @@ var init = function() { unique = get_unique(); // Load settings from HTML5 local storage if available. - if (supports_html5_storage() && localStorage['enable_sound']) { - set_sound(parseInt(localStorage['enable_sound'])); + if (supports_html5_storage() && window['localStorage']['enable_sound']) { + set_sound(parseInt(window['localStorage']['enable_sound'])); } else { set_sound(false); } -- 2.39.2