Skip to content

Commit

Permalink
fix issue on answers grid caused by storage
Browse files Browse the repository at this point in the history
  • Loading branch information
Lily2point0 committed Jun 6, 2017
1 parent 13420e4 commit 0464ed4
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/js/oCrossword.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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]')) {
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -898,7 +900,7 @@ OCrossword.prototype.assemble = function assemble() {

saveLocal();

if(answersEmpty()) {
if(answersEmpty() || isAnswerVersion) {
resetButton.classList.add('hidden');
} else {
resetButton.classList.remove('hidden');
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 0464ed4

Please sign in to comment.