bunkat/wordfind

Solve display does not work if your html page contains some classes labelled as '.' + word to find

clodion opened this issue · 0 comments

The solve display need to find all the buttons created with an automated created class with the text to find. So, if your page uses this class to display some elements that are not in the puzzle, thoses elements will get the "wordFound" class.

The first time you solves the puzzle everything is good. but if you want to dynamically rgenerate another puzzle, without reloading your html page, then the solve script does not word anymore on the texte to find, which correspond to the className.

I've changed in wordfindgame.js the solve script in order to set the class "wordFound" only into the div containing te puzzle, whatever this div id can be. here is the code :

` solve: function(puzzle, words) {

            var solution = wordfind.solve(puzzle, words).found;

            // recherche l'element qui contient le puzzle
            var elem_puzzle = $('[x="0"][y="0"]').parent().parent().attr('id')
          
            for (var i = 0, len = solution.length; i < len; i++) {

                var word = solution[i].word,
                    orientation = solution[i].orientation,
                    x = solution[i].x,
                    y = solution[i].y,
                    next = wordfind.orientations[orientation];

                if (!$('#'+elem_puzzle + '.' + word).hasClass('wordFound')) {
                  
                    for (var j = 0, size = word.length; j < size; j++) {
                        var nextPos = next(x, y, j);
                        $('[x="' + nextPos.x + '"][y="' + nextPos.y + '"]').addClass('solved');
                    }

                    $('#'+ elem_puzzle +' .' + word).addClass('wordFound');
                    
                }
            }

        },

Hope it helps`everybody