src/lib/wordfindgame.js
function (e) {
            // see if we formed a valid word
            for (var i = 0, len = wordList.length; i < len; i++) {
                if (wordList[i] === curWord) {
                    var selected = $('.selected');
                    selected.addClass('found');
                    wordList.splice(i, 1);
                    var color = e.data.colorHash.hex(curWord);
                    $('.' + curWord).addClass('wordFound');
                    for (var selectedIndex = 0, selectedLength = selected.length; selectedIndex < selectedLength; selectedIndex++) {
                        var current = $(selected[selectedIndex]), style = current.attr("style"), hasBC = style != undefined && style.search("background-color") != -1;
                        if (hasBC) {
                            current.css("border", "4px solid " + color);
                        }
                        else {
                            current.css("background-color", color);
                        }
                    }
                    $(e.data.puzzleEl).trigger("found", curWord);
                    $(e.data.wordsEl).append("<li class=\"" + curWord + " wordFound\"><i style=\"background-color:" + color + ";\"></i>" + curWord + "</li>");
                }
                if (wordList.length === 0) {
                    $('.puzzleSquare').off(".spl").addClass('complete');
                    $(e.data.puzzleEl).trigger("end");
                }
            }
            // reset the turn
            $('.selected').removeClass('selected');
            startSquare = null;
            selectedSquares = [];
            curWord = '';
            curOrientation = null;
        }
function (e) {
            // see if we formed a valid word
            for (var i = 0, len = wordList.length; i < len; i++) {
                if (wordList[i] === curWord) {
                    var selected = $('.selected');
                    selected.addClass('found');
                    wordList.splice(i, 1);
                    var color = e.data.colorHash.hex(curWord);
                    $('.' + curWord).addClass('wordFound');
                    for (var selectedIndex = 0, selectedLength = selected.length; selectedIndex < selectedLength; selectedIndex++) {
                        var current = $(selected[selectedIndex]), style = current.attr("style"), hasBC = style != undefined && style.search("background-color") != -1;
                        if (hasBC) {
                            current.css("border", "4px solid " + color);
                        }
                        else {
                            current.css("background-color", color);
                        }
                    }
                    $(e.data.puzzleEl).trigger("found", curWord);
                    $(e.data.wordsEl).append("<li class=\"" + curWord + " wordFound\"><i style=\"background-color:" + color + ";\"></i>" + curWord + "</li>");
                }
                if (wordList.length === 0) {
                    $('.puzzleSquare').off(".spl").addClass('complete');
                    $(e.data.puzzleEl).trigger("end");
                }
            }
            // reset the turn
            $('.selected').removeClass('selected');
            startSquare = null;
            selectedSquares = [];
            curWord = '';
            curOrientation = null;
        }
function ( e ) { // see if we formed a valid word for ( var i = 0 , len = wordList . length ; i < len ; i ++ ) { if ( wordList [ i ] === curWord ) { var selected = $ ( '.selected' ) ; selected . addClass ( 'found' ) ; wordList . splice ( i , 1 ) ; var color = e . data . colorHash . hex ( curWord ) ; $ ( '.' + curWord ) . addClass ( 'wordFound' ) ; for ( var selectedIndex = 0 , selectedLength = selected . length ; selectedIndex < selectedLength ; selectedIndex ++ ) { var current = $ ( selected [ selectedIndex ] ) , style = current . attr ( "style" ) , hasBC = style != undefined && style . search ( "background-color" ) != - 1 ; if ( hasBC ) { current . css ( "border" , "4px solid " + color ) ; } else { current . css ( "background-color" , color ) ; } } $ ( e . data . puzzleEl ) . trigger ( "found" , curWord ) ; $ ( e . data . wordsEl ) . append ( "<li class=\"" + curWord + " wordFound\"><i style=\"background-color:" + color + ";\"></i>" + curWord + "</li>" ) ; } if ( wordList . length === 0 ) { $ ( '.puzzleSquare' ) . off ( ".spl" ) . addClass ( 'complete' ) ; $ ( e . data . puzzleEl ) . trigger ( "end" ) ; } } // reset the turn $ ( '.selected' ) . removeClass ( 'selected' ) ; startSquare = null ; selectedSquares = [ ] ; curWord = '' ; curOrientation = null ; }
Event that handles mouse up on a square. Checks to see if a valid word
was created and updates the class of the letters and word if it was. Then
resets the game state to start a new word.
Event that handles mouse up on a square . Checks to see if a valid word was created and updates the class of the letters and word if it was . Then resets the game state to start a new word .