Skip to content

Commit

Permalink
Merge pull request #45 from ftlabs/bugfix/answered_grid
Browse files Browse the repository at this point in the history
[Bugfix] Answers grid
  • Loading branch information
Lily2point0 authored Jun 6, 2017
2 parents 13420e4 + 0464ed4 commit 16c8a0c
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 16c8a0c

Please sign in to comment.