1; 2(function ( $ ) { 3 "use strict" 4 5 document.addEventListener('DOMContentLoaded', (event) => 6 { 7 8 if( document.querySelector("#ymc-crossword-container") ) 9 { 10 11 let board; 12 let wordArr; 13 let wordBank; 14 let wordsActive; 15 let boardMap; 16 let focusChar; 17 let focusIndex = null; 18 let mode; 19 let wordElementsAcross; 20 let wordElementsDown; 21 22 let Bounds = { 23 top:0, 24 right:0, 25 bottom:0, 26 left:0, 27 28 Update: function( x, y ) { 29 this.top = Math.min( y, this.top ); 30 this.right = Math.max( x, this.right ); 31 this.bottom = Math.max( y, this.bottom ); 32 this.left = Math.min( x, this.left ); 33 }, 34 35 Clean: function(){ 36 this.top = 999; 37 this.right = 0; 38 this.bottom = 0; 39 this.left = 999; 40 } 41 }; 42 43 const Timer = { 44 totalSeconds: 0, 45 start: function ( crossword ) { 46 let self = this; 47 let mode_timer = true; 48 let keys_timer = Object.keys(sessionStorage); 49 for(let key of keys_timer) { 50 if(sessionStorage.getItem(key) === '_t_s') { 51 mode_timer = false; 52 } 53 } 54 if( mode_timer ) { 55 sessionStorage.setItem('_ymc_timer', '_t_s'); 56 57 function pad(val) { 58 return val > 9 ? val : "0" + val; 59 } 60 this.interval = setInterval(function () { 61 self.totalSeconds += 1; 62 crossword.find('.ymc-control-panel .ymc-timer .ymc-min, .ymc-popup-crossword .ymc-game-over .ymc-min'). 63 text(pad(Math.floor(self.totalSeconds / 60 % 60))); 64 crossword.find('.ymc-control-panel .ymc-timer .ymc-sec, .ymc-popup-crossword .ymc-game-over .ymc-sec'). 65 text(pad(parseInt(self.totalSeconds % 60))); 66 67 }, 1000); 68 } 69 }, 70 reset: function ( crossword ) { 71 Timer.totalSeconds = null; 72 clearInterval(this.interval); 73 crossword.find('.ymc-control-panel .ymc-timer .ymc-min, .ymc-popup-crossword .ymc-game-over .ymc-min').text("00"); 74 crossword.find('.ymc-control-panel .ymc-timer .ymc-sec, .ymc-popup-crossword .ymc-game-over .ymc-sec').text("00"); 75 }, 76 pause: function () { 77 clearInterval(this.interval); 78 delete this.interval; 79 } 80 }; 81 82 const crossword = $(document.querySelector('#ymc-crossword-container')); 83 84 85 // MAIN FUNC 86 function Play() { 87 let charEleArr = document.querySelectorAll('#ymc-crossword-container .ymc-square .ymc-char'); 88 mode = 0; 89 90 for(var i = 0; i < charEleArr.length; i++){ 91 RegisterChar(charEleArr[i],boardMap[i]); 92 charEleArr[i].placeholder = ""; 93 } 94 95 FormatClues(); 96 } 97 98 function FormatClues() { 99 let cluesAcross = document.querySelector("#ymc-crossword-container #ymc-cluesAcross"), 100 cluesDown = document.querySelector("#ymc-crossword-container #ymc-cluesDown"), 101 directionAcross = document.querySelector("#ymc-crossword-container #ymcDirectionAcross"), 102 directionDown = document.querySelector("#ymc-crossword-container #ymcDirectionDown"); 103 104 if( cluesAcross !== null && cluesDown !== null ) { 105 106 cluesAcross.innerHTML = ""; 107 cluesDown.innerHTML = ""; 108 109 cluesAcross.appendChild(directionAcross); 110 cluesDown.appendChild(directionDown); 111 112 for(let i = 0; i < wordElementsAcross.length; i++){ 113 let lineEle = cluesAcross.appendChild(wordElementsAcross[i].ele), 114 numEle = lineEle.getElementsByClassName("ymc-lineNum")[0], 115 linkEle = lineEle.getElementsByClassName("ymc-clue")[0]; 116 117 numEle.innerHTML = wordElementsAcross[i].num; 118 linkEle.setAttribute('data-num', wordElementsAcross[i].num ); 119 linkEle.setAttribute('data-dir', 0 ); 120 RemoveClass(numEle,'disabled'); 121 } 122 123 for(let i = 0; i < wordElementsDown.length; i++){ 124 let lineEle = cluesDown.appendChild(wordElementsDown[i].ele), 125 numEle = lineEle.getElementsByClassName("ymc-lineNum")[0], 126 linkEle = lineEle.getElementsByClassName("ymc-clue")[0]; 127 numEle.innerHTML = wordElementsDown[i].num; 128 linkEle.setAttribute('data-num', wordElementsDown[i].num ); 129 linkEle.setAttribute('data-dir', 1 ); 130 RemoveClass(numEle,'disabled'); 131 } 132 } 133 134 } 135 136 function Generate() {
137 wordElementsAcross = []; 138 wordElementsDown = []; 139 140 mode = 1; 141 GetWordsFromInput(); 142 143 for(var i = 0, isSuccess=false; i < 19 && !isSuccess; i++){ 144 CleanVars(); 145 isSuccess = PopulateBoard(); 146 } 147 148 let crossword = document.querySelector('#ymc-crossword-container'); 149 $(crossword).find('.ymc-crossword').html( (isSuccess) ? BoardToHtml(" ") : "<div class='ymc-crossword-notice'>Failed to create crossword puzzle</div>" ); 150 151 FormatClues(); 152 } 153 154 function GetWordsFromInput(){ 155 wordArr = []; 156 for(var i=0, val, w=document.querySelectorAll("#ymc-crossword-container .ymc-line"); i<w.length; i++){ 157 val = w[i].getElementsByClassName("ymc-word")[0].value.toUpperCase(); 158 if (val !== null && val.length > 1){wordArr.push({ele:w[i],value:val});} 159 } 160 } 161 162 function CleanVars(){ 163 Bounds.Clean(); 164 wordBank = []; 165 wordsActive = []; 166 board = []; 167 168 for(var i = 0; i < 50; i++){ 169 board.push([]); 170 for(var j = 0; j < 50; j++){ 171 board[i].push({value:null,char:[]}); 172 } 173 } 174 } 175 176 function PopulateBoard(){ 177 PrepareBoard(); 178 for(var i=0,isOk=true,len=wordBank.length; i<len && isOk; i++){ 179 isOk = AddWordToBoard(); 180 } 181 return isOk; 182 } 183 184 function PrepareBoard(){ 185 wordBank=[]; 186 187 for(var i = 0, len = wordArr.length; i < len; i++){ 188 wordBank.push(new WordObj(wordArr[i])); 189 } 190 191 for(i = 0; i < wordBank.length; i++){ 192 for(var j = 0, wA=wordBank[i]; j<wA.char.length; j++){ 193 for(var k = 0, cA=wA.char[j]; k<wordBank.length; k++){ 194 for(var l = 0,wB=wordBank[k]; k!==i && l<wB.char.length; l++){ 195 wA.totalMatches += (cA === wB.char[l])?1:0; 196 } 197 } 198 } 199 } 200 } 201 202 function AddWordToBoard(){ 203 let i, len, curIndex, curWord, curChar, curMatch, testWord, testChar, minMatchDiff = 9999, curMatchDiff; 204 205 if(wordsActive.length < 1){ 206 curIndex = 0; 207 for(i = 0, len = wordBank.length; i < len; i++){ 208 if (wordBank[i].totalMatches < wordBank[curIndex].totalMatches){ 209 curIndex = i; 210 } 211 } 212 wordBank[curIndex].successfulMatches = [{x:12,y:12,dir:0}]; 213 } 214 215 else{ 216 curIndex = -1; 217 218 for(i = 0, len = wordBank.length; i < len; i++){ 219 curWord = wordBank[i]; 220 curWord.effectiveMatches = 0; 221 curWord.successfulMatches = []; 222 for(var j = 0, lenJ = curWord.char.length; j < lenJ; j++){ 223 curChar = curWord.char[j]; 224 for (var k = 0, lenK = wordsActive.length; k < lenK; k++){ 225 testWord = wordsActive[k]; 226 for (var l = 0, lenL = testWord.char.length; l < lenL; l++){ 227 testChar = testWord.char[l]; 228 if (curChar === testChar){ 229 curWord.effectiveMatches++; 230 var curCross = {x:testWord.x,y:testWord.y,dir:0}; 231 if(testWord.dir === 0){ 232 curCross.dir = 1; 233 curCross.x += l; 234 curCross.y -= j; 235 } 236 else{ 237 curCross.dir = 0; 238 curCross.y += l; 239 curCross.x -= j; 240 } 241 242 var isMatch = true; 243 244 for(var m = -1, lenM = curWord.char.length + 1; m < lenM; m++){ 245 var crossVal = []; 246 if (m !== j){ 247 if (curCross.dir === 0){ 248 var xIndex = curCross.x + m; 249 250 if (xIndex < 0 || xIndex > board.length){ 251 isMatch = false;
252 break; 253 } 254 255 try { 256 if( board[xIndex][curCross.y] !== undefined ) { 257 crossVal.push(board[xIndex][curCross.y].value); 258 crossVal.push(board[xIndex][curCross.y + 1].value); 259 crossVal.push(board[xIndex][curCross.y - 1].value); 260 } 261 } 262 catch (e) { 263 //console.error(e); 264 } 265 266 } 267 else{ 268 var yIndex = curCross.y + m; 269 270 if (yIndex < 0 || yIndex > board[curCross.x].length){ 271 isMatch = false; 272 break; 273 } 274 275 try { 276 if( board[curCross.x][yIndex] !== undefined ) { 277 crossVal.push(board[curCross.x][yIndex].value); 278 crossVal.push(board[curCross.x + 1][yIndex].value); 279 crossVal.push(board[curCross.x - 1][yIndex].value); 280 } 281 } 282 catch (e) { 283 //console.error(e); 284 } 285 286 287 } 288 289 if(m > -1 && m < lenM-1){ 290 if (crossVal[0] !== curWord.char[m]){ 291 if (crossVal[0] !== null){ 292 isMatch = false; 293 break; 294 } 295 else if (crossVal[1] !== null){ 296 isMatch = false; 297 break; 298 } 299 else if (crossVal[2] !== null){ 300 isMatch = false; 301 break; 302 } 303 } 304 } 305 else if (crossVal[0] !== null){ 306 isMatch = false; 307 break; 308 } 309 } 310 } 311 312 if (isMatch === true){ 313 curWord.successfulMatches.push(curCross); 314 } 315 } 316 } 317 } 318 } 319 320 curMatchDiff = curWord.totalMatches - curWord.effectiveMatches; 321 322 if (curMatchDiff<minMatchDiff && curWord.successfulMatches.length>0){ 323 curMatchDiff = minMatchDiff; 324 curIndex = i; 325 } 326 else if (curMatchDiff <= 0){ 327 return false;
328 } 329 } 330 } 331 332 if (curIndex === -1){ 333 return false; 334 } 335 336 let spliced = wordBank.splice(curIndex, 1); 337 wordsActive.push(spliced[0]); 338 339 let pushIndex = wordsActive.length - 1, 340 rand = Math.random(), 341 matchArr = wordsActive[pushIndex].successfulMatches, 342 matchIndex = Math.floor(rand * matchArr.length), 343 matchData = matchArr[matchIndex]; 344 345 wordsActive[pushIndex].x = matchData.x; 346 wordsActive[pushIndex].y = matchData.y; 347 wordsActive[pushIndex].dir = matchData.dir; 348 349 350 let prevObj = null; 351 352 for(i = 0, len = wordsActive[pushIndex].char.length; i < len; i++){ 353 var cObj, 354 cIndex, 355 xInd = matchData.x, 356 yInd = matchData.y; 357 358 if (matchData.dir === 0){ xInd = matchData.x + i; } 359 else{ yInd = matchData.y + i; } 360 361 cObj = {wordIndex:pushIndex,prev:prevObj, 362 value:wordsActive[pushIndex].char[i],next:null}; 363 364 cIndex = board[xInd][yInd].char.length; 365 366 board[xInd][yInd].char.push(cObj); 367 board[xInd][yInd].value = wordsActive[pushIndex].char[i]; 368 369 Bounds.Update(xInd,yInd); 370 371 if (prevObj !== null){ 372 prevObj.next = board[xInd][yInd].char[cIndex]; 373 } 374 375 prevObj = board[xInd][yInd].char[cIndex]; 376 } 377 378 prevObj = null; 379 return true; 380 381 } 382 383 function BoardToHtml( blank ){ 384 385 boardMap = []; 386 387 for(var i=Bounds.top-1, str=""; i<Bounds.bottom+2; i++){ //y 388 str += "<div class='ymc-row'>"; 389 for(var j=Bounds.left-1; j<Bounds.right+2; j++){ //x 390 str += BoardCharToElement(board[j][i],j,i); 391 } 392 str += "</div>"; 393 } 394 395 return str; 396 } 397 398 function BoardCharToElement( c,x,y ){ 399 let inner = ""; 400 let num = ""; 401 let dataAtr = []; 402 403 if (c.value !== null) { 404 405 for(var i=0 ; i < c.char.length; i++) { 406 c.char[i].index = boardMap.length; 407 if (c.char[i].prev === null){ 408 var matchingObj = wordsActive[c.char[i].wordIndex]; 409 410 if (num === ""){ 411 num = wordElementsDown.length + wordElementsAcross.length + 1; 412 } 413 if (matchingObj.dir === 0){ 414 wordElementsAcross.push({num:num,ele:matchingObj.element}); 415 } 416 else{ 417 wordElementsDown.push({num:num,ele:matchingObj.element}); 418 } 419 } 420 } 421 boardMap.push(c); 422 423 inner = EleStr('input', [{a:'type',v:['text']}, 424 {a:'class',v:['ymc-char']}, 425 {a:'maxlength',v:['1']}, 426 {a:'data-letter',v:[c.value]}, 427 {a:'placeholder',v:[c.value]}], 428 EleStr('span', [{a:'class',v:['ymc-num']}],num)); 429 430 dataAtr.push({a:'data-x',v:[x]}); 431 dataAtr.push({a:'data-y',v:[y]}); 432 dataAtr.push({a:'data-c',v:[num]}); 433 } 434 435 let firstLetter = ( num !== "" ) ? " ymc-first-letter" : ""; 436 let el = ( num !== "" ) ? num - 1 : ""; 437 dataAtr.push({a:'class',v:['ymc-square'+firstLetter+'']}); 438 dataAtr.push({a:'data-el',v:[el]}); 439 440 return EleStr('div',dataAtr,inner); 441 } 442 443 // OBJECT DEFINITIONS 444 function WordObj( wordData ){ 445 this.element = wordData.ele; 446 this.string = wordData.value; 447 this.char = wordData.value.split(""); 448 this.totalMatches = 0; 449 this.effectiveMatches = 0; 450 this.successfulMatches = []; 451 } 452 453 // EVENTS 454 function RegisterChar( ele, boardChar ) { 455 456 let BoardCharClick = function ( boardChar ) { 457 458 return function() { 459 460 if ( mode === 1 ) { 461 return; 462 } 463 464 this.select(); 465 466 // wordsActive | wordIndex 467 // boardMap | index 468 469 if( $(window).width() > 1024 ) { 470 471 let word = ''; 472 let word2 = ''; 473 474 crossword.find('.ymc-clueBlock').find('.ymc-clue').removeClass('ymc-active'); 475 476 if ( boardChar.char.length === 1 ) { 477 word = wordsActive[boardChar.char[0].wordIndex].string; 478 let actWord = crossword.find('.ymc-clueBlock .ymc-word[value="'+ word +'"]'). 479 siblings('.ymc-clue').addClass('ymc-active'); 480 actWord[0].scrollIntoView({block: "center", behavior: "smooth"}); 481 } 482 else { 483 word = wordsActive[boardChar.char[0].wordIndex].string; 484 word2 = wordsActive[boardChar.char[1].wordIndex].string; 485 crossword.find('.ymc-clueBlock .ymc-word[value="'+ word +'"], .ymc-clueBlock .ymc-word[value="'+ word2 +'"]'). 486 siblings('.ymc-clue').each(function() { 487 $(this).addClass('ymc-active'); 488 }); 489 } 490 } 491 492 /*if ( boardChar.char.length > 1 ) {
493 if ( focusIndex >= boardChar.char.length-1 ){ 494 focusIndex = 0; 495 } 496 else { 497 focusIndex++; 498 } 499 }*/ 500 } 501 } 502 ele.addEventListener('click', BoardCharClick(boardChar)); 503 504 let BoardCharFocus = function( boardChar ) { 505 return function () { 506 507 if (mode === 1){ 508 return; 509 } 510 511 if (!(boardChar.char[focusIndex] && boardChar.char[focusIndex].prev === focusChar)){ 512 focusIndex = Math.max(0,boardChar.char.indexOf(focusChar)); 513 } 514 515 this.onkeydown = function(e){ 516 if (mode === 1){ 517 return; 518 } 519 let key = e.keyCode || e.which; 520 521 if (key === 8) { 522 if (boardChar.char[focusIndex].prev !== null) { 523 focusChar = boardChar.char[focusIndex].prev; 524 525 //let isEnd = (boardChar.char[focusIndex].next !== null) ? true : false; 526 document.getElementsByClassName('ymc-char') 527 [boardChar.char[focusIndex].prev.index].focus(); 528 529 /*if (isEnd) { 530 document.getElementsByClassName('ymc-char') 531 [boardChar.char[focusIndex].index].value = ""; 532 document.getElementsByClassName('ymc-char') 533 [boardChar.char[focusIndex].next.index].value = ""; 534 }*/ 535 } 536 } 537 } 538 539 this.onkeypress = function(){ 540 if (mode === 1){ 541 return; 542 } 543 if (boardChar.char[focusIndex].next !== null){ 544 focusChar = boardChar.char[focusIndex].next; 545 document.getElementsByClassName('ymc-char') 546 [boardChar.char[focusIndex].next.index].focus(); 547 } 548 } 549 } 550 } 551 //ele.addEventListener('focus', BoardCharFocus(boardChar)); 552 553 let KeyUpChar = function( boardChar ) { 554 return function(e) { 555 // wordsActive | wordIndex 556 // boardMap | index 557 558 let key = e.keyCode || e.which; 559 560 // X 561 if ( boardChar.char.length === 1 ) { 562 if( boardChar.char[0].next !== null && key !== 8 && key !== 46 ) { 563 document.getElementsByClassName('ymc-char') 564 [boardChar.char[0].next.index].focus(); 565 } 566 } 567 // Y 568 else { 569 if( boardChar.char[1].next !== null && key !== 8 && key !== 46 ) { 570 document.getElementsByClassName('ymc-char') 571 [boardChar.char[1].next.index].focus(); 572 } 573 // else { 574 // document.getElementsByClassName('ymc-char') 575 // [boardChar.char[0].next.index].focus(); 576 // } 577 } 578 579 if( key === 8 ) { 580 if ( boardChar.char[0].prev !== null ) { 581 document.getElementsByClassName('ymc-char') 582 [boardChar.char[0].prev.index].focus(); 583 584 } 585 } 586 } 587 }
588 ele.addEventListener('keyup', KeyUpChar(boardChar)); 589 } 590 591 // HELPER FUNCTIONS 592 function EleStr( e,c,h ){ 593 h = (h)?h:""; 594 for(var i=0,s="<"+e+" "; i<c.length; i++){ 595 s+=c[i].a+ "='"+ArrayToString(c[i].v," ")+"' "; 596 } 597 return (s+">"+h+"</"+e+">"); 598 } 599 600 function ArrayToString( a,s ){ 601 if(a===null || a.length<1) return ""; 602 if(s===null) s=","; 603 for(var r=a[0],i=1;i<a.length;i++){r+=s+a[i];} 604 return r; 605 } 606 607 function AddClass( ele,classStr ){ 608 ele.className = ele.className.replaceAll(' '+classStr,'')+' '+classStr; 609 } 610 611 function RemoveClass( ele,classStr ){ 612 ele.className = ele.className.replaceAll(' '+classStr,''); 613 } 614 615 function ToggleClass( ele,classStr ){ 616 var str = ele.className.replaceAll(' '+classStr,''); 617 ele.className = (str.length===ele.className.length)?str+' '+classStr:str; 618 } 619 620 function checkCrossword( crossword ) { 621 let modeCheckCrossword = true; 622 crossword.find(".ymc-square .ymc-char").each(function() { 623 if ( !($(this).attr('data-letter') === ($(this).val().toUpperCase())) ) { 624 modeCheckCrossword = false; 625 } 626 }); 627 return modeCheckCrossword; 628 } 629 630 function clearCrossword( crossword ) { 631 crossword.find(".ymc-square .ymc-char").each(function() { 632 $(this).val(''); 633 }); 634 crossword.find(".ymc-square").each(function() { 635 $(this).removeClass('ymc-correct'); 636 }); 637 crossword.find(".ymc-crossword-panel .ymc-clue").each(function() { 638 $(this).removeClass('ymc-completed'); 639 }); 640 } 641 642 function audioSound( sound ) { 643 let src = ''; 644 switch (sound) { 645 case 'ready' : src = _ymc_crossword_object.path + '/assets/media/ready.mp3'; break; 646 case 'error' : src = _ymc_crossword_object.path + '/assets/media/error.mp3'; break; 647 case 'win' : src = _ymc_crossword_object.path + '/assets/media/win.mp3'; break; 648 } 649 let audio = new Audio(); 650 audio.src = src; 651 audio.autoplay = true; 652 } 653 654 function OverflowScreen() { 655 656 let countCharsX = (Bounds.right + 2) - (Bounds.left - 1); 657 let widthCrossword = (countCharsX * 30) + (countCharsX * 2); 658 659 if( widthCrossword > crossword.find('.ymc-crossword').width() ) { 660 crossword.find('.ymc-crossword').addClass('ymc-scrollX'); 661 crossword.find('.ymc-crossword .ymc-row').css({'minWidth':widthCrossword+'px'}); 662 } 663 } 664 665 function ClearSessionStorage() { 666 sessionStorage.clear(); 667 } 668 669 function ProgressBar() { 670 crossword.find('.ymc-progress-bar .ymc-total-words').html(wordArr.length); 671 crossword.find('.ymc-progress-bar .ymc-completed-words').html( 672 crossword.find('.ymc-clueBlock .ymc-line .ymc-completed').length); 673 } 674 675 function ScoreCrossword( counter, letter ) { 676 677 // wordsActive | wordIndex 678 // boardMap | index 679 680 //console.log(letter); 681 //console.log('wordArr: ', wordArr); 682 //console.log('wordsActive:', wordsActive); 683 //console.log('boardMap', boardMap); 684 685 //let letterW = letter; 686 // boardMap.forEach((el) => { 687 // if( el.value === letter ) { 688 // console.log(el.value); 689 // el.char.forEach((ch) => { 690 // //console.log(ch.wordIndex); 691 // console.log(wordsActive[ch.wordIndex].x); 692 // console.log(wordsActive[ch.wordIndex].y); 693 // }) 694 // } 695 // }); 696 697 if( sessionStorage.getItem('incorrect_answers') ) 698 { 699 let iaMap = new Map(JSON.parse(sessionStorage.getItem('incorrect_answers'))); 700 701 //console.log(counter); 702 703 for (let item of iaMap.keys()) 704 { 705 706 if( item === counter ) 707 { 708 iaMap.get(item).push(1); 709 710 iaMap.set(counter, iaMap.get(item)); 711 712 sessionStorage.setItem('incorrect_answers', JSON.stringify(Array.from(iaMap.entries()))); 713 714 console.log(iaMap.get(item)); 715 } 716 } 717 } 718 else 719 { 720 let incorrectMap = new Map(); 721 incorrectMap.set(counter, [1]); 722 sessionStorage.setItem('incorrect_answers', JSON.stringify(Array.from(incorrectMap.entries()))); 723 } 724 725 } 726 727 String.prototype.replaceAll = function (replaceThis, withThis) { 728 let re = new RegExp(replaceThis,"g"); 729 return this.replace(re, withThis); 730 }; 731 732 733 // INITIAL LOAD 734 ClearSessionStorage(); 735 Generate(); 736 OverflowScreen(); 737 ProgressBar(); 738 Play(); 739 740 741 // ADDITIONAL FUNCTIONS 742 crossword.find('.ymc-char').hover( 743 function () { 744 if( $(this).val() !== "" ) { 745 $(this).css({'cursor': 'pointer'}); 746 } else { 747 $(this).css({'cursor': 'text'}); 748 } 749 }, 750 function () {} 751 ); 752 753 crossword.find('.ymc-char').on("keyup", function (e) { 754 755 let isNextElem = $(this).closest('.ymc-square').next('[data-c]'); 756 let isPrevElem = $(this).closest('.ymc-square').prev('[data-c]'); 757 let isParentElem = $(this).closest('.ymc-square'); 758 let mute = crossword.data('mute'); 759 let popup = crossword.data('popup'); 760 761 // Move cursor 762 if( e.key === "ArrowRight" ) { 763 if( isNextElem.length > 0 ) { 764 isNextElem.find('input').focus().select(); 765 } 766 } 767 if( e.key === "ArrowLeft" ) { 768 if( isPrevElem.length > 0 ) { 769 isPrevElem.find('input').focus().select(); 770 } 771 } 772 if( e.key === "ArrowDown" ) { 773 let x = isParentElem.attr('data-x'); 774 isParentElem.closest('.ymc-row').next('.ymc-row').find('[data-x="'+x+'"] input').focus().select(); 775 } 776 if( e.key === "ArrowUp" ) { 777 let x = isParentElem.attr('data-x'); 778 isParentElem.closest('.ymc-row').prev('.ymc-row').find('[data-x="'+x+'"] input').focus().select(); 779 } 780 781 crossword.find('.ymc-square').removeClass('ymc-correct ymc-error ymc-highlighted-line').find('.ymc-num').show(); 782 crossword.find('.ymc-clueBlock .ymc-clue').removeClass('ymc-completed ymc-clue-error ymc-active'); 783 784 crossword.find('.ymc-square.ymc-first-letter').each(function (i, elem) { 785 let el_i = $(elem)[0].dataset.el; 786 let arr_el = el_i.split(','); 787 for (let v = 0; v < arr_el.length; v++) { 788 let el = arr_el[v]; 789 let arr = wordsActive[el]; 790 let arr_char = arr.char; 791 let dir = arr.dir; 792 let x = arr.x; 793 let y = arr.y; 794 let c = $(elem)[0].dataset.c; 795 let df = ''; 796 let flag_empty = ''; 797 let flag_correct = true; 798 799 if ( dir === 0 ) { df = x; } 800 else { df = y; } 801 802 // Сheck for character matches 803 // Horizontally 804 if (dir === 0) { 805 let index = 0; 806 for (let z = df; z < arr_char.length + df; z++) { 807 let it = crossword.find('.ymc-square[data-x="' + z + '"][data-y="' + y + '"] .ymc-ch
807ar').val().toUpperCase(); 808 if (it) { 809 if ( it !== arr_char[index] ) { 810 flag_correct = false; 811 } 812 } 813 else { 814 flag_empty = 'empty'; 815 } 816 index++; 817 } 818 } 819 820 // Сheck for character matches 821 // Vertically 822 else { 823 let index = 0; 824 for (let z = df; z < arr_char.length + df; z++) { 825 let it = crossword.find('.ymc-square[data-y="' + z + '"][data-x="' + x + '"] .ymc-char').val().toUpperCase(); 826 if (it) { 827 if (it !== arr_char[index]) { 828 flag_correct = false; 829 } 830 } 831 else { 832 flag_empty = 'empty'; 833 } 834 index++; 835 } 836 } 837 838 // Correct Word 839 if ( flag_empty !== 'empty' && flag_correct === true ) { 840 841 // Horizontally 842 if (dir === 0) { 843 844 let counterElem = crossword.find('.ymc-square[data-x="' + df + '"][data-y="' + y + '"]'); 845 let counter = counterElem.data('c'); 846 crossword.find('.ymc-clueBlock .ymc-clue[data-num="'+ counter +'"][data-dir="0"]').addClass('ymc-completed'); 847 848 if( mute ) { 849 sessionStorage.removeItem('w_x_e_h_'+counter); 850 if(Object.keys(sessionStorage).length === 0) { 851 sessionStorage.setItem('w_x_h_'+counter, 'x_h_'+counter); 852 audioSound('ready'); 853 } 854 else { 855 let mode_key = true; 856 let keys = Object.keys(sessionStorage); 857 for(let key of keys) { 858 if(sessionStorage.getItem(key) === 'x_h_'+counter) { 859 mode_key = false; 860 } 861 } 862 if( mode_key ) { 863 sessionStorage.setItem('w_x_h_'+counter, 'x_h_'+counter); 864 audioSound('ready'); 865 } 866 } 867 } 868 869 for (let z = df; z < arr_char.length + df; z++) { 870 crossword.find('.ymc-square[data-x="' + z + '"][data-y="' + y + '"]').addClass('ymc-correct'); 871 } 872 } 873 874 // Vertically 875 else { 876 877 let counterElem = crossword.find('.ymc-square[data-y="' + df + '"][data-x="' + x + '"]'); 878 let counter = counterElem.data('c'); 879 crossword.find('.ymc-clueBlock .ymc-clue[data-num="'+ counter +'"][data-dir="1"]').addClass('ymc-completed'); 880 881 if( mute ) { 882 sessionStorage.removeItem('w_y_e_v_'+counter); 883 if(Object.keys(sessionStorage).length === 0) { 884 sessionStorage.setItem('w_y_v_'+counter, 'y_v_'+counter); 885 audioSound('ready'); 886 } 887 else { 888 let mode_key = true; 889 let keys = Object.keys(sessionStorage); 890 for( let key of keys ) { 891 if( sessionStorage.getItem(key) === 'y_v_'+counter ) { 892 mode_key = false;
893 } 894 } 895 if( mode_key ) { 896 sessionStorage.setItem('w_y_v_'+counter, 'y_v_'+counter); 897 audioSound('ready'); 898 } 899 } 900 } 901 902 for (let z = df; z < arr_char.length + df; z++) { 903 crossword.find('.ymc-square[data-y="' + z + '"][data-x="' + x + '"]').addClass('ymc-correct'); 904 } 905 } 906 } 907 908 // Incorrect Word 909 if ( flag_empty !== 'empty' && flag_correct === false ) { 910 911 // Horizontally 912 if ( dir === 0 ) { 913 914 let counterElem = crossword.find('.ymc-square[data-x="' + df + '"][data-y="' + y + '"] '); 915 let counter = counterElem.data('c'); 916 crossword.find('.ymc-clueBlock .ymc-clue[data-num="'+ counter +'"][data-dir="0"]').addClass('ymc-clue-error'); 917 918 if( mute ) { 919 sessionStorage.removeItem('w_x_h_'+counter); 920 if(Object.keys(sessionStorage).length === 0) { 921 sessionStorage.setItem('w_x_e_h_'+counter, 'x_e_h_'+counter); 922 audioSound('error'); 923 } 924 else { 925 let mode_key = true; 926 let keys = Object.keys(sessionStorage); 927 for(let key of keys) { 928 if(sessionStorage.getItem(key) === 'x_e_h_'+counter) { 929 mode_key = false; 930 } 931 } 932 if(mode_key) { 933 sessionStorage.setItem('w_x_e_h_'+counter, 'x_e_h_'+counter); 934 audioSound('error'); 935 } 936 } 937 } 938 939 for (let z = df; z < arr_char.length + df; z++) { 940 crossword.find('.ymc-square[data-x="' + z + '"][data-y="' + y + '"] ').addClass('ymc-error'); 941 } 942 } 943 944 // Vertically 945 else { 946 947 let counterElem = crossword.find('.ymc-square[data-y="' + df + '"][data-x="' + x + '"] '); 948 let counter = counterElem.data('c'); 949 crossword.find('.ymc-clueBlock .ymc-clue[data-num="'+ counter +'"][data-dir="1"]').addClass('ymc-clue-error'); 950 951 if( mute ) { 952 sessionStorage.removeItem('w_y_v_'+counter); 953 if(Object.keys(sessionStorage).length === 0) { 954 sessionStorage.setItem('w_y_e_v_'+counter, 'y_e_v_'+counter); 955 audioSound('error'); 956 } 957 else { 958 let mode_key = true; 959 let keys = Object.keys(sessionStorage); 960 for(let key of keys) { 961 if(sessionStorage.getItem(key) === 'y_e_v_'+counter) { 962 mode_key = false; 963 } 964 } 965 if(mode_key) { 966 sessionStorage.setItem('w_y_e_v_'+counter, 'y_e_v_'+counter); 967 audioSound('error'); 968 } 969 } 970 } 971 972 for (let z = df; z < arr_char.length + df; z++) { 973 crossword.find('.ymc-square[data-y="' + z + '"][data-x="' + x + '"] ').addClass('ymc-error'); 974 } 975 } 976 } 977 } 978 }); 979 980 // Run Timer 981 Timer.start( crossword ); 982 crossword.find('.ymc-actions .ymc-button').removeClass('active'); 983 984 ProgressBar(); 985 986 // If Game Out 987 if(checkCrossword( crossword )) { 988 989 Timer.pause( crossword ); 990 991 if( popup ) { 992 crossword.find('.ymc-popup-crossword').show(); 993 //clearCrossword(crossword); 994 } 995 if( mute ) { 996 sessionStorage.clear(); 997 audioSound('win'); 998 } 999 } 1000 }); 1001 1002 crossword.find('.ymc-popup-crossword .ymc-crossword-btn-close').on('click', function (){ 1003 crossword.find('.ymc-popup-crossword').hide(); 1004 }); 1005 1006 crossword.find('.ymc-clueBlock .ymc-line .ymc-clue').on("click", function (e) { 1007 e.preventDefault(); 1008 let num = $(this).data('num'); 1009 let dir = $(this).data('dir'); 1010 $(this). 1011 addClass('ymc-active'). 1012 closest('.ymc-line'). 1013 siblings('.ymc-line'). 1014 find('.ymc-clue'). 1015 removeClass('ymc-active'). 1016 closest('.ymc-col'). 1017 siblings('.ymc-col'). 1018 find('.ymc-clue'). 1019 removeClass('ymc-active'); 1020 1021 crossword.find('.ymc-square').removeClass('ymc-highlighted-line');
1022 crossword.find('.ymc-crossword .ymc-row .ymc-first-letter .ymc-num').each(function () { 1023 if( num === parseInt($(this).text()) ) 1024 { 1025 $(this).siblings('.ymc-char').focus(); 1026 let elem = $(this).closest('.ymc-first-letter'); 1027 let x = elem.data('x'); 1028 let y = elem.data('y'); 1029 1030 wordsActive.forEach((el) => { 1031 if( x === el.x && y === el.y && dir === el.dir ) { 1032 if (el.dir === 0 ) { 1033 for (let z = el.x; z < el.char.length + el.x; z++) { 1034 crossword.find('.ymc-square[data-x="' + z + '"][data-y="' + y + '"]').addClass('ymc-highlighted-line'); 1035 } 1036 } 1037 else { 1038 for (let z = el.y; z < el.char.length + el.y; z++) { 1039 crossword.find('.ymc-square[data-y="' + z + '"][data-x="' + x + '"]').addClass('ymc-highlighted-line'); 1040 } 1041 } 1042 } 1043 }); 1044 } 1045 }); 1046 }); 1047 1048 crossword.find('.ymc-actions .ymc-button-pause').on("click", function (e) { 1049 Timer.pause( crossword ); 1050 $(this).addClass('active').siblings('.ymc-button').removeClass('active'); 1051 sessionStorage.removeItem('_ymc_timer'); 1052 }); 1053 1054 crossword.find('.ymc-actions .ymc-button-start').on("click", function (e) { 1055 Timer.start( crossword ); 1056 $(this).addClass('active').siblings('.ymc-button').removeClass('active'); 1057 }); 1058 1059 crossword.find('.ymc-actions .ymc-button-reset').on("click", function (e) { 1060 Timer.reset( crossword ); 1061 $(this).addClass('active').siblings('.ymc-button').removeClass('active'); 1062 sessionStorage.removeItem('_ymc_timer'); 1063 }); 1064 1065 crossword.find('.ymc-actions .ymc-button-reload').on("click", function (e) { 1066 $(this).addClass('active').siblings('.ymc-button').removeClass('active'); 1067 document.location.reload(); 1068 }); 1069 1070 } 1071 1072 }); 1073 1074}( jQuery ));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.