$( document ).ready( function() { var pole= new Array(); pole[0]="n"; pole[1]="a"; pole[2]="l"; pole[3]="b"; pole[4]="u"; pole[5]="f"; pole[6]="i"; pole[7]="n"; pole[8]="m"; pole[9]="a"; pole[10]="c"; pole[11]="s"; pole[12]="e"; pole[13]="v"; pole[14]="o"; pole[15]="f"; pole[16]="l"; pole[17]="u"; pole[18]="r"; pole[19]="a"; pole[20]="n"; pole[21]="p"; pole[22]="o"; pole[23]="r"; pole[24]="f"; pole[25]="y"; pole[26]="r"; pole[27]="i"; pole[28]="e"; pole[29]="s"; pole[30]="u"; pole[31]="x"; pole[32]="a"; pole[33]="m"; pole[34]="e"; pole[35]="t"; pole[36]="h"; pole[37]="o"; pole[38]="n"; pole[39]="i"; pole[40]="u"; pole[41]="m"; pole[42]="s"; pole[43]="u"; pole[44]="g"; pole[45]="a"; pole[46]="m"; pole[47]="m"; pole[48]="a"; pole[49]="d"; pole[50]="e"; pole[51]="x"; pole[52]="e"; pole[53]="t"; pole[54]="o"; pole[55]="m"; pole[56]="i"; pole[57]="d"; pole[58]="a"; pole[59]="t"; pole[60]="c"; pole[61]="i"; pole[62]="s"; pole[63]="a"; pole[64]="t"; pole[65]="r"; pole[66]="a"; pole[67]="k"; pole[68]="u"; pole[69]="r"; pole[70]="i"; pole[71]="u"; pole[72]="m"; pole[73]="j"; pole[74]="a"; pole[75]="p"; pole[76]="o"; pole[77]="n"; pole[78]="s"; pole[79]="k"; pole[80]="o"; pole[81]="m"; pole[82]="i"; pole[83]="d"; pole[84]="a"; pole[85]="z"; pole[86]="o"; pole[87]="l"; pole[88]="a"; pole[89]="m"; pole[90]="p"; pole[91]="r"; pole[92]="o"; pole[93]="p"; pole[94]="o"; pole[95]="f"; pole[96]="o"; pole[97]="l"; // Add interactivity on mouseup and keyup for the inputs $( '#crossword' ).find( 'input' ).mouseup( function( event ) { // Select the letter in the input so it can be replaced by simply typing another letter $( this ).select(); event.preventDefault(); }).focus( function() { // Select the letter in the input so it can be replaced by simply typing another letter $( this ).select(); }).keyup( function( event ) { var code = event.keyCode || event.which; // Don't do anything if the Tab, Shift, Backspace, Space, or Delete keys are pressed. if ( code === 9 || code === 16 || code === 8 || code === 46 ) { return true; } // Automagically remove spaces when they are typed. else if ( code === 32 ) { $( this ).val( $( this ).val().replace(/\s/g, '')); } // Automatically focus on the next appropriate input once a letter or symbol is entered or an arrow key is pressed. // This is sort of a best-guess interaction based on where the user is typing. else { // Cache several variables that will be used to move focus to other inputs in the crossword. // If we try to get an input that doesn't exist, the script fails gracefully by simply not moving focus to another input. // Cache the class of the current input. var inputClass = $( this ).attr( 'class' ); // Cache the table cell containing the current input. var cell = $( this ).closest( 'td' ); // Cache the index of the current table cell. var colIndex = $( cell ).parent().children().index( cell ); // Cache the next input to the right of the current input. var nextAcross = $( cell ).next().find( 'input' ); // Cache the previous input to the left of the current input. var prevAcross = $( cell ).prev().find( 'input' ); // Cache the value of the next input to the right of the current input. var nextAcrossVal = $( nextAcross ).val(); // Cache the next input below the current input (this is why we need the column index of the current table cell). var nextDown = $( cell ).parent().next().find( 'td:eq(' + colIndex + ')' ).find( 'input' ); // Cache the previous input above the current input (this is why we need the column index of the current table cell). var prevDown = $( cell ).parent().prev().find( 'td:eq(' + colIndex + ')' ).find( 'input' ); // If the arrow keys are pressed, go to the appropriate input (if available). switch ( code ) { case 37: // left arrow prevAcross.focus(); return false; break; case 38: // up arrow prevDown.focus(); return false; break; case 39: // right arrow nextAcross.focus(); return false; break; case 40: // down arrow nextDown.focus().addClass( "force-down" ); // If user pressed the down arrow, they probably want to continue typing a down response. return false; break; default: } // If the input is for both across AND down responses... if ( inputClass.indexOf( "across" ) !== -1 && inputClass.indexOf( "down" ) !== -1 ) { // ...and if the input doesn't have the 'force-down' class and the next across input is available but empty, focus on the next across input... if ( inputClass.indexOf( "force-down" ) === -1 && nextAcrossVal === "" ) { $( nextAcross ).focus(); } // ...otherwise focus on the next down input and add the force-down class to the next down input. else { $( nextDown ).addClass( "force-down" ).focus(); } } // If the input is ONLY for down responses focus on the next down input and add the force-down class to the next down input. else if ( inputClass.indexOf( "across" ) === -1 && inputClass.indexOf( "down" ) !== -1 ) { $( nextDown ).addClass( "force-down" ).focus(); } // If the input is ONLY for across responses focus on the next across input. else { $( nextAcross ).focus(); } // Remove the force-down class once the focus has moved on from the current input. $( this ).removeClass( "force-down" ); } }); /**************************** KONTROLA ***********************************************/ $( '#crossword-submit' ).click( function( event ) { var hodnota,i,pocet; pocet=$('td div input').length; $('div.legenda').show(); for(i=0;i