X-Git-Url: https://git.auder.net/doc/index.css?a=blobdiff_plain;f=public%2Fjavascripts%2Fcomponents%2Fgame.js;h=147aeafeeb76f066daf27878785b96d7102a96e4;hb=7d6b0773c093ad4347ff8b444236e7d89b06977e;hp=40035a5fb256052612eac0e5c8adb827121f5c2b;hpb=3ed62725fe47e395793cf952403d61fc9f347eee;p=vchess.git diff --git a/public/javascripts/components/game.js b/public/javascripts/components/game.js index 40035a5f..147aeafe 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"); @@ -649,7 +668,7 @@ Vue.component('my-game', { this.selectedPiece.style.display = "inline-block"; this.selectedPiece.style.zIndex = 3000; let startSquare = this.getSquareFromId(e.target.parentNode.id); - this.possibleMoves = this.vr.canIplay(this.mycolor,startSquare) + this.possibleMoves = this.mode!="idle" && this.vr.canIplay(this.mycolor,startSquare) ? this.vr.getPossibleMovesFrom(startSquare) : []; e.target.parentNode.appendChild(this.selectedPiece);