Workaround unselectable text: allow PGN download
authorBenjamin Auder <benjamin.auder@somewhere>
Mon, 19 Nov 2018 16:48:14 +0000 (17:48 +0100)
committerBenjamin Auder <benjamin.auder@somewhere>
Mon, 19 Nov 2018 16:48:14 +0000 (17:48 +0100)
TODO [deleted file]
public/javascripts/components/game.js
public/javascripts/variants/Zen.js
public/stylesheets/variant.sass
variants.js

diff --git a/TODO b/TODO
deleted file mode 100644 (file)
index 314c0c7..0000000
--- a/TODO
+++ /dev/null
@@ -1 +0,0 @@
-PGN text is not selectable on desktop computer (understand why?!)
index 40035a5..3eb27f2 100644 (file)
@@ -334,10 +334,20 @@ Vue.component('my-game', {
                {
                        elementArray.push(
                                h('div',
-                                       { },
+                                       { attrs: { id: "pgn-div" } },
                                        [
+                                               h('a',
+                                                       {
+                                                               attrs: {
+                                                                       id: "download",
+                                                                       href: "#",
+                                                               }
+                                                       }
+                                               ),
                                                h('p',
                                                        {
+                                                               attrs: { id: "pgn-game" },
+                                                               on: { click: this.download },
                                                                domProps: {
                                                                        innerHTML: this.vr.getPGN(this.mycolor, this.score, this.fenStart, this.mode)
                                                                }
@@ -470,6 +480,15 @@ Vue.component('my-game', {
                this.conn.onclose = socketCloseListener;
        },
        methods: {
+               download: function() {
+                       let content = document.getElementById("pgn-game").innerHTML;
+                       content = content.replace(/<br>/g, "\n");
+                       // Prepare and trigger download link
+                       let downloadAnchor = document.getElementById("download");
+                       downloadAnchor.setAttribute("download", "game.pgn");
+                       downloadAnchor.href = "data:text/plain;charset=utf-8," + encodeURIComponent(content);
+                       downloadAnchor.click();
+               },
                endGame: function(score) {
                        this.score = score;
                        let modalBox = document.getElementById("modal-eog");
index 96dd8f9..bfc0e0a 100644 (file)
@@ -114,6 +114,7 @@ class ZenRules extends ChessRules
                let [sizeX,sizeY] = VariantRules.size;
                let shift = (color == 'w' ? -1 : 1);
                let startRank = (color == 'w' ? sizeY-2 : 1);
+               let firstRank = (color == 'w' ? sizeY-1 : 0);
                let lastRank = (color == "w" ? 0 : sizeY-1);
 
                if (x+shift >= 0 && x+shift < sizeX && x+shift != lastRank)
@@ -122,7 +123,7 @@ class ZenRules extends ChessRules
                        if (this.board[x+shift][y] == V.EMPTY)
                        {
                                moves.push(this.getBasicMove(x, y, x+shift, y));
-                               if (x==startRank && this.board[x+2*shift][y] == V.EMPTY)
+                               if ([startRank,firstRank].includes(x) && this.board[x+2*shift][y] == V.EMPTY)
                                {
                                        //two squares jump
                                        moves.push(this.getBasicMove(x, y, x+2*shift, y));
index 39fb80b..7e530f6 100644 (file)
     margin-right: 0
     padding: 0 3px
 
+#pgn-div > a
+  display: none
+
+#pgn-div > p
+  cursor: pointer
+
 .warn
   padding: 3px
   color: red
index 0bb5c9e..ed2b6ba 100644 (file)
@@ -6,14 +6,11 @@ module.exports = [
 //  { "name" : "AntiKing", "description" : "Keep anti-king in check" },
 //  { "name" : "Magnetic", "description" : "Laws of attraction" },
 //  { "name" : "Alice", "description" : "Both sides of the mirror" },
-//  { "name" : "Cylindric", "description" : "Sides comunicate" },
-//  { "name" : "Moscow", "description" : "Custom pieces setup" },
 //  { "name" : "Grand", "description" : "Big board" },
 //  { "name" : "Wildebeest", "description" : "Balanced sliders & leapers" },
 //  { "name" : "Loser", "description" : "Lose all pieces" },
-//  { "name" : "Shatranj", "description" : "Ancestral rules" },
+//  { "name" : "Crazyhouse", "description" : "Captures reborn" },
 //  { "name" : "Switching", "description" : "Exchange pieces positions" },
 //  { "name" : "Absorption", "description" : "Capture enhance movements" },
 //  { "name" : "Dark", "description" : "In the fog" },
-//  { "name" : "Kriegspiel", "description" : "Blind war" },
 ];