From: Benjamin Auder Date: Mon, 19 Nov 2018 16:48:14 +0000 (+0100) Subject: Workaround unselectable text: allow PGN download X-Git-Url: https://git.auder.net/variants/img/pieces/css/css/assets/rpsls.css?a=commitdiff_plain;h=01ca2adce0ddcf246f184c6d19389262b0f5e6e5;p=vchess.git Workaround unselectable text: allow PGN download --- diff --git a/TODO b/TODO deleted file mode 100644 index 314c0c72..00000000 --- a/TODO +++ /dev/null @@ -1 +0,0 @@ -PGN text is not selectable on desktop computer (understand why?!) diff --git a/public/javascripts/components/game.js b/public/javascripts/components/game.js index 40035a5f..3eb27f27 100644 --- a/public/javascripts/components/game.js +++ b/public/javascripts/components/game.js @@ -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(/
/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"); diff --git a/public/javascripts/variants/Zen.js b/public/javascripts/variants/Zen.js index 96dd8f9f..bfc0e0ab 100644 --- a/public/javascripts/variants/Zen.js +++ b/public/javascripts/variants/Zen.js @@ -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)); diff --git a/public/stylesheets/variant.sass b/public/stylesheets/variant.sass index 39fb80bf..7e530f69 100644 --- a/public/stylesheets/variant.sass +++ b/public/stylesheets/variant.sass @@ -14,6 +14,12 @@ margin-right: 0 padding: 0 3px +#pgn-div > a + display: none + +#pgn-div > p + cursor: pointer + .warn padding: 3px color: red diff --git a/variants.js b/variants.js index 0bb5c9ee..ed2b6bad 100644 --- a/variants.js +++ b/variants.js @@ -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" }, ];