viresh-ratnakar / exolve

Online interactive crossword software in JavaScript
MIT License
71 stars 15 forks source link

Feature Request: A congratulatory message once the solver completes the puzzle? #85

Closed SinghGauravKumar closed 1 year ago

SinghGauravKumar commented 1 year ago

I don't know what's best, but anything which says "Woohoo, you have done it"

viresh-ratnakar commented 1 year ago

This is already supported. An "Exolve" event is fired upon completion, and you just have to add a few lines of JavaScript to listen for this event and show a message upon receiving it.

See the documentation in https://github.com/viresh-ratnakar/exolve#completion-event and see https://github.com/viresh-ratnakar/exolve/blob/master/test-completion-notice.html for an example.

SinghGauravKumar commented 1 year ago

@viresh-ratnakar I saw that. But I am hosting several crosswords on the same page of my website using embeds. The Alert message shows up for the whole page, while I was looking for a message at that particular crossword itself.

viresh-ratnakar commented 1 year ago

You don't have to show a page-wide alert() upon completion—that's just an example. You can insert a congratulatory message anywhere, instead. For example, this code will insert a message in the puzzle preamble:


document.addEventListener('exolve', function (e) {
  let msg = 'You have completed the puzzle.';
  msg += '.';
  if (e.detail.knownCorrect) msg += ' Your solution is correct!';
  if (e.detail.knownIncorrect) msg += ' Your solution has mistakes.';
  const puz = exolvePuzzles[e.detail.id];
  document.getElementById(puz.prefix + '-preamble').innerHTML = msg;
});