]> git.sesse.net Git - remoteglot/commitdiff
Various fixes for running with advanced JS optimizations, if we want to do that in...
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 23 Dec 2022 17:42:20 +0000 (18:42 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 23 Dec 2022 17:42:20 +0000 (18:42 +0100)
www/js/chessboard-0.3.0.js
www/js/json_delta.js
www/js/remoteglot.js

index 2ad6f44c5b9215bc88b4a92b59d9e5b9604262ef..e15ab00ff5d57b2d3ed61c6c683967e7f3b564b2 100644 (file)
@@ -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;
index 91b17e1c11344790a8a9b144a8612780ecb24ae1..f6417df92773b6439f6f8d9640637c9b8146bd75 100644 (file)
@@ -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);
        }
index beaf63f74f1bfcba4437c3e4a6ca94aa30a91736..f252f5b3a1b903a3af605e4df58e4196c8430b45 100644 (file)
@@ -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 = "<strong>Off</strong>";
        }
        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);
        }