From 0464ed47b79a1afd8744c13ee9d6c88958e4a531 Mon Sep 17 00:00:00 2001 From: Lily2point0 Date: Tue, 6 Jun 2017 16:35:18 +0100 Subject: [PATCH] fix issue on answers grid caused by storage --- src/js/oCrossword.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/js/oCrossword.js b/src/js/oCrossword.js index 2c541e7..dfa4a9b 100644 --- a/src/js/oCrossword.js +++ b/src/js/oCrossword.js @@ -98,6 +98,7 @@ function buildGrid( } rootEl.parentElement.setAttribute('data-o-crossword-title', name); + rootEl.setAttribute('data-answer-version', !!answers); if (clues) { rootEl.parentElement.setAttribute('data-o-crossword-clue-length', clues.across.length + clues.down.length); @@ -388,7 +389,8 @@ function getLetterIndex(gridEl, cell, number, direction) { OCrossword.prototype.assemble = function assemble() { const gridEl = this.rootEl.querySelector('table'); const cluesEl = this.rootEl.querySelector('ul.o-crossword-clues'); - let answerStore = JSON.parse(this.rootEl.getAttribute('data-storage')); + let answerStore = JSON.parse(this.rootEl.getAttribute('data-storage')); + const isAnswerVersion = JSON.parse(this.rootEl.getAttribute('data-answer-version')); const gridMap = new Map(); let currentlySelectedGridItem = null; for (const el of cluesEl.querySelectorAll('[data-o-crossword-number]')) { @@ -463,7 +465,7 @@ OCrossword.prototype.assemble = function assemble() { const resetButton = document.createElement('button'); resetButton.classList.add('o-crossword-reset'); - if(answersEmpty()) { + if(answersEmpty() || isAnswerVersion) { resetButton.classList.add('hidden'); } resetButton.textContent = 'Reset grid'; @@ -898,7 +900,7 @@ OCrossword.prototype.assemble = function assemble() { saveLocal(); - if(answersEmpty()) { + if(answersEmpty() || isAnswerVersion) { resetButton.classList.add('hidden'); } else { resetButton.classList.remove('hidden'); @@ -982,7 +984,8 @@ OCrossword.prototype.assemble = function assemble() { } function answersEmpty() { - return (/^[*,\-]+$/).test(answerStore.across) && (/^[*,\-]+$/).test(answerStore.down); + + return answerStore && (/^[*,\-]+$/).test(answerStore.across) && (/^[*,\-]+$/).test(answerStore.down); } const onResize = function onResize(init) {