1if (document.getElementById("wha-crossword")) { 2 //---------------------------------// 3 // GLOBAL VARIABLES // 4 //---------------------------------// 5 6 /* Start Options Page Variables */ 7 var bgColor = crossword_vars.whacw_bg_color; 8 var borderColor = crossword_vars.whacw_border_color; 9 var txtColor = crossword_vars.whacw_txt_color; 10 var crossword_ansver_var = crossword_vars.whacw_ansver; 11 var crossword_ansver_incorect = crossword_vars.whacw_ansver_incorect; 12 var crossword_align_question = crossword_vars.whacw_align_question; 13 var crossword_width_question = crossword_vars.whacw_question_width; 14 var crossword_question_color = crossword_vars.whacw_question_txt_color; 15 var counter_color = crossword_vars.whacw_counter_color; 16 17 /* End Options Page Variables */ 18 19 /* Start Optional vars */ 20 var useGlobalOptions = optional_crossword_vars.whacw_use_global_options; 21 var optional_bgColor = optional_crossword_vars.whacw_optional_bg_color; 22 var optional_borderColor = optional_crossword_vars.whacw_optional_border_color; 23 var optional_textColor = optional_crossword_vars.whacw_optional_text_color; 24 var optional_questionColor = optional_crossword_vars.whacw_optional_question_color; 25 var optional_counterColor = optional_crossword_vars.whacw_optional_counter_color; 26 var correct_ansver_var = optional_crossword_vars.whacw_correct_ansver; 27 var incorrect_ansver = optional_crossword_vars.whacw_incorrect_ansver; 28 var align_question = optional_crossword_vars.whacw_align_question; 29 var question_width = optional_crossword_vars.whacw_question_width; 30 31 var crossword_ansver = 'yes'; 32 var correct_ansver = 'yes'; 33 34 /* End Optional vars */ 35 36 var board, wordArr, wordBank, wordsActive, mode; 37 38 var Bounds = { 39 top: 0, right: 0, bottom: 0, left: 0, 40 41 Update: function (x, y) { 42 this.top = Math.min(y, this.top); 43 this.right = Math.max(x, this.right); 44 this.bottom = Math.max(y, this.bottom); 45 this.left = Math.min(x, this.left); 46 }, 47 48 Clean: function () { 49 this.top = 999; 50 this.right = 0; 51 this.bottom = 0; 52 this.left = 999; 53 } 54 }; 55 56 //---------------------------------// 57 // MAIN // 58 //---------------------------------// 59 60 function Play() { 61 var letterArr = document.getElementsByClassName('wha-letter'); 62 63 for (var i = 0; i < letterArr.length; i++) { 64 65 if (useGlobalOptions == 'yes') { 66 letterArr[i].innerHTML = "<input " + 67 "class='wha-char' " + 68 "type='text' " + 69 "maxlength='1' " + 70 "style='" + 71 "color:#" + txtColor + ";" + "'" + 72 "></input>"; 73 } else { 74 letterArr[i].innerHTML = "<input " + 75 "class='wha-char' " + 76 "type='text' " + 77 "maxlength='1' " + 78 "style='" + 79 "color:#" + optional_textColor + ";" + "'" + 80 "></input>"; 81 } 82 } 83 84 mode = 0; 85 ToggleInputBoxes(false); 86 87 jQuery('.wha-square.wha-letter.wha-first').each(function (index, value) { 88 var r = jQuery(this).attr('data-c'); 89 90 jQuery(this).append("<div class='wha-counter'>" + r.replace(' , ', ',').replace(/ /g,'') + "</div>"); 91 }); 92 93 } 94 95 function Create() { 96 if (mode === 0) { 97 ToggleInputBoxes(true); 98 document.getElementById("wha-crossword").innerHTML = BoardToHtml(" "); 99 mode = 1; 100 } 101 else { 102 GetWordsFromInput(); 103 104 for (var i = 0, isSuccess = false; i < 10 && !isSuccess; i++) { 105 CleanVars(); 106 isSuccess = PopulateBoard(); 107 } 108 109 document.getElementById("wha-crossword").innerHTML = 110 (isSuccess) ? BoardToHtml(" ") : "Failed to find crossword."; 111 } 112 } 113 114 function ToggleInputBoxes(active) { 115 var w = document.getElementsByClassName('wha-word'), 116 d = document.getElementsByClassName('wha-clue'); 117 118 for (var i = 0; i < w.length; i++) { 119 if (active === true) { 120 RemoveClass(w[i], 'wha-hide'); 121 RemoveClass(d[i], 'wha-clueReadOnly'); 122 d[i].disabled = ''; 123 } 124 else { 125 AddClass(w[i], 'wha-hide'); 126 AddClass(d[i], 'wha-clueReadOnly'); 127 d[i].disabled = 'readonly'; 128 } 129 } 130 } 131 132 function GetWordsFromInput() { 133 wordArr = []; 134 for (var i = 0, val, w = document.getElementsByClassName("wha-word"); i < w.length; i++) { 135 val = w[i].value.toUpperCase(); 136 if (val !== null && val.length > 1) { 137 wordArr.push(val); 138 } 139 } 140 } 141 142 function CleanVars() { 143 Bounds.Clean(); 144 wordBank = []; 145 wordsActive = []; 146 board = []; 147 148 for (var i = 0; i < 32; i++) { 149 board.push([]); 150 for (var j = 0; j < 32; j++) { 151 board[i].push(null); 152 } 153 } 154 } 155 156 function PopulateBoard() { 157 PrepareBoard(); 158 159 for (var i = 0, isOk = true, len = wordBank.length; i < len && isOk; i++) { 160 isOk = AddWordToBoard(); 161 } 162 return isOk; 163 } 164 165 function PrepareBoard() { 166 wordBank = []; 167 168 for (var i = 0, len = wordArr.length; i < len; i++) { 169 wordBank.push(new WordObj(wordArr[i])); 170 } 171 172 for (i = 0; i < wordBank.length; i++) { 173 for (var j = 0, wA = wordBank[i]; j < wA.char.length; j++) { 174 for (var k = 0, cA = wA.char[j]; k < wordBank.length; k++) {
175 for (var l = 0, wB = wordBank[k]; k !== i && l < wB.char.length; l++) { 176 wA.totalMatches += (cA === wB.char[l]) ? 1 : 0; 177 } 178 } 179 } 180 } 181 } 182 183 // TODO: Clean this guy up 184 function AddWordToBoard() { 185 var i, len, curIndex, curWord, curChar, curMatch, testWord, testChar, 186 minMatchDiff = 9999, curMatchDiff; 187 188 if (wordsActive.length < 1) { 189 curIndex = 0; 190 for (i = 0, len = wordBank.length; i < len; i++) { 191 if (wordBank[i].totalMatches < wordBank[curIndex].totalMatches) { 192 curIndex = i; 193 } 194 } 195 wordBank[curIndex].successfulMatches = [{x: 12, y: 12, dir: 0}]; 196 } 197 else { 198 curIndex = -1; 199 200 for (i = 0, len = wordBank.length; i < len; i++) { 201 curWord = wordBank[i]; 202 curWord.effectiveMatches = 0; 203 curWord.successfulMatches = []; 204 for (var j = 0, lenJ = curWord.char.length; j < lenJ; j++) { 205 curChar = curWord.char[j]; 206 for (var k = 0, lenK = wordsActive.length; k < lenK; k++) { 207 testWord = wordsActive[k]; 208 for (var l = 0, lenL = testWord.char.length; l < lenL; l++) { 209 testChar = testWord.char[l]; 210 if (curChar === testChar) { 211 curWord.effectiveMatches++; 212 213 var curCross = {x: testWord.x, y: testWord.y, dir: 0}; 214 if (testWord.dir === 0) { 215 curCross.dir = 1; 216 curCross.x += l; 217 curCross.y -= j; 218 } 219 else { 220 curCross.dir = 0; 221 curCross.y += l; 222 curCross.x -= j; 223 } 224 225 var isMatch = true; 226 227 for (var m = -1, lenM = curWord.char.length + 1; m < lenM; m++) { 228 var crossVal = []; 229 if (m !== j) { 230 if (curCross.dir === 0) { 231 var xIndex = curCross.x + m; 232 233 if (xIndex < 0 || xIndex >= board.length) { 234 isMatch = false; 235 break; 236 } 237 238 crossVal.push(board[xIndex][curCross.y]); 239 crossVal.push(board[xIndex][curCross.y + 1]); 240 crossVal.push(board[xIndex][curCross.y - 1]); 241 } 242 else { 243 var yIndex = curCross.y + m; 244 245 if (yIndex < 0 || yIndex > board[curCross.x].length) { 246 isMatch = false; 247 break; 248 } 249 250 crossVal.push(board[curCross.x][yIndex]); 251 crossVal.push(board[curCross.x + 1][yIndex]); 252 crossVal.push(board[curCross.x - 1][yIndex]); 253 } 254 255 if (m > -1 && m < lenM - 1) { 256 if (crossVal[0] !== curWord.char[m]) { 257 if (crossVal[0] !== null) { 258 isMatch = false; 259 break; 260 } 261 else if (crossVal[1] !== null) { 262 isMatch = false; 263 break; 264 } 265 else if (crossVal[2] !== null) { 266 isMatch = false; 267 break; 268 } 269 } 270 } 271 else if (crossVal[0] !== null) { 272 isMatch = false; 273 break; 274 } 275 } 276 } 277 278 if (isMatch === true) { 279 curWord.successfulMatches.push(curCross); 280 } 281 } 282 } 283 } 284 } 285 286 curMatchDiff = curWord.totalMatches - curWord.effectiveMatches; 287 288 if (curMatchDiff < minMatchDiff && curWord.successfulMatches.length > 0) { 289 curMatchDiff = minMatchDiff; 290 curIndex = i; 291 } 292 else if (curMatchDiff <= 0) { 293 return false; 294 } 295 } 296 } 297 298 if (curIndex === -1) { 299 return false; 300 } 301 302 var spliced = wordBank.splice(curIndex, 1); 303 wordsActive.push(spliced[0]); 304 305 var pushIndex = wordsActive.length - 1, 306 rand = Math.random(), 307 matchArr = wordsActive[pushIndex].successfulMatches, 308 matchIndex = Math.floor(rand * matchArr.length), 309 matchData = matchArr[matchIndex]; 310 311 wordsActive[pushIndex].x = matchData.x; 312 wordsActive[pushIndex].y = matchData.y; 313 wordsActive[pushIndex].dir = matchData.dir; 314 315 for (i = 0, len = wordsActive[pushIndex].char.length; i < len; i++) { 316 var xIndex = matchData.x, 317 yIndex = matchData.y; 318 319 if (matchData.dir === 0) { 320 xIndex += i;
321 board[xIndex][yIndex] = wordsActive[pushIndex].char[i]; 322 } 323 else { 324 yIndex += i; 325 board[xIndex][yIndex] = wordsActive[pushIndex].char[i]; 326 } 327 328 Bounds.Update(xIndex, yIndex); 329 } 330 331 return true; 332 } 333 334 function BoardToHtml(blank) { 335 for (var i = Bounds.top - 1, str = ""; i < Bounds.bottom + 2; i++) { 336 str += "<div class='wha-row'>"; 337 for (var j = Bounds.left - 1; j < Bounds.right + 2; j++) { 338 str += BoardCharToElement(board[j][i], j, i); 339 } 340 str += "</div>"; 341 } 342 343 return str; 344 } 345 346 function BoardCharToElement(c, j, i) { 347 var s = ''; 348 var co = ''; 349 var el = ''; 350 var counter = ''; 351 var arr1 = []; 352 var arr1_el = []; 353 for (var m = 0; m < wordsActive.length; m++) { 354 355 if (wordsActive[m].x == j && wordsActive[m].y == i) { 356 s = 'wha-first'; 357 el = m; 358 arr1_el.push(el); 359 360 for (var g = 0, val, w = document.getElementsByClassName("wha-word"); g < w.length; g++) { 361 val = w[g].value.toUpperCase(); 362 if (val == wordsActive[m].string) { 363 co = parseInt(w[g].dataset['counter']); 364 arr1.push(co); 365 } 366 367 } 368 369 } 370 } 371 arr1.reverse(); 372 var arr = (c) ? ['wha-square', 'wha-letter ' + s] : ['wha-square']; 373 var arr_x = (c) ? [j] : ['']; 374 var arr_y = (c) ? [i] : ['']; 375 var arr_el = (c) ? [arr1_el.join(',')] : ['']; 376 return EleStr('div', [{a: 'class', v: arr}, {a: 'data-c', v: arr1.join(',')}, {a: 'data-x', v: arr_x}, { 377 a: 'data-y', 378 v: arr_y 379 }, {a: 'data-el', v: arr_el}], c); 380 } 381 382 //---------------------------------// 383 // OBJECT DEFINITIONS // 384 //---------------------------------// 385 386 function WordObj(stringValue) { 387 this.string = stringValue; 388 this.char = stringValue.split(""); 389 this.totalMatches = 0; 390 this.effectiveMatches = 0; 391 this.successfulMatches = []; 392 } 393 394 //---------------------------------// 395 // EVENTS // 396 //---------------------------------// 397 398 function RegisterEvents() { 399 document.getElementById("wha-crossword").onfocus = function () { 400 return false; 401 }; 402 /*document.getElementById("btnCreate").addEventListener('click',Create,false); 403 document.getElementById("btnPlay").addEventListener('click',Play,false);*/ 404 } 405 406 RegisterEvents(); 407 408 //---------------------------------// 409 // HELPER FUNCTIONS // 410 //---------------------------------// 411 412 function EleStr(e, c, h) { 413 h = (h) ? h : ""; 414 for (var i = 0, s = "<" + e + " "; i < c.length; i++) { 415 s += c[i].a + "='" + ArrayToString(c[i].v, " ") + "' "; 416 } 417 return (s + ">" + h + "</" + e + ">"); 418 } 419 420 function ArrayToString(a, s) { 421 if (a === null || a.length < 1) return ""; 422 if (s === null) s = ","; 423 for (var r = a[0], i = 1; i < a.length; i++) { 424 r += s + a[i]; 425 } 426 return r; 427 } 428 429 function AddClass(ele, classStr) { 430 ele.className = ele.className.replaceAll(' ' + classStr, '') + ' ' + classStr; 431 } 432 433 function RemoveClass(ele, classStr) { 434 ele.className = ele.className.replaceAll(' ' + classStr, ''); 435 } 436 437 function ToggleClass(ele, classStr) { 438 var str = ele.className.replaceAll(' ' + classStr, ''); 439 ele.className = (str.length === ele.className.length) ? str + ' ' + classStr : str; 440 } 441 442 String.prototype.replaceAll = function (replaceThis, withThis) { 443 var re = new RegExp(replaceThis, "g"); 444 return this.replace(re, withThis); 445 }; 446 447 //---------------------------------// 448 // INITIAL LOAD // 449 //---------------------------------// 450 451 Create(); 452 Play(); 453 jQuery(document).ready(function () { 454 jQuery(".wha-square.wha-letter .wha-char").keyup(function (event) { 455 jQuery('.wha-square.wha-letter').removeClass('wha-correct'); 456 jQuery('.wha-square.wha-letter').removeClass('wha-error'); 457 jQuery('.wha-square.wha-letter.wha-first').each(function (i, elem) { 458 var el_i = jQuery(elem)[0].dataset.el; 459 var arr_el = el_i.split(','); 460 for (var v = 0; v < arr_el.length; v++) { 461 var el = arr_el[v]; 462 var arr = wordsActive[el]; 463 var arr_char = arr.char; 464 var dir = arr.dir; 465 var x = arr.x; 466 var y = arr.y; 467 var c = jQuery(elem)[0].dataset.c; 468 var df = ''; 469 var flag_empty = ''; 470 var flag_correct = true; 471 472 if (dir == 0) { 473 df = x; 474 } 475 else { 476 477 df = y; 478 } 479 480 if (dir == 0) { 481 var index = 0; 482 for (var z = df; z < arr_char.length + df; z++) { 483 var it = jQuery('.wha-square.wha-letter[data-x="' + z + '"][data-y="' + y + '"] .wha-char').val().toUpperCase(); 484 if (it) { 485 if (it != arr_char[index]) { 486 flag_correct = false; 487 } 488 } 489 else { 490 flag_empty = 'empty'; 491 } 492 index++; 493 } 494 } 495 else { 496 var index = 0; 497 for (var z = df; z < arr_char.length + df; z++) { 498 var it = jQuery('.wha-square.wha-letter[data-y="' + z + '"][data-x="' + x + '"] .wha-char').val().toUpperCase(); 499 if (it) { 500 if (it != arr_char[index]) { 501 flag_correct = false; 502 } 503 } 504 else { 505 flag_empty = 'empty'; 506 } 507 index++; 508 } 509 } 510 if (useGlobalOptions == 'yes') { 511 512 if (flag_empty != 'empty' && flag_correct == true) { 513 514 if (dir == 0 && crossword_ansver == 'yes') { 515 516 //gorizontale 517 /* added check if crossword_ansver value 'yes' */ 518 for (var z = df; z < arr_char.length + df; z++) { 519 520 if (crossword_ansver_var == 'yes') { 521 jQuery('.wha-square.wha-letter[data-x="' + z + '"][data-y="' + y + '"] ').addClass('wha-correct').css({"background-color": "#b3ffb4"}); 522 } else { 523 jQuery('.wha-square.wha-letter[data-x="' + z + '"][data-y="' + y + '"] ').addClass('wha-correct').css({"background-color": "none"}); 524 } 525 } 526 } 527 else { //verticale 528 for (var z = df; z < arr_char.length + df; z++) { 529 530 if (crossword_ansver_var == 'yes') { 531 jQuery('.wha-square.wha-letter[data-y="' + z + '"][data-x="' + x + '"] ').addClass('wha-correct').css({"background-color": "#b3ffb4"}); 532 } else { 533 jQuery('.wha-square.wha-letter[data-y="' + z + '"][data-x="' + x + '"] ').addClass('wha-correct').css({"background-color": "none"}); 534 } 535 } 536 } 537 } 538 /* added check if crossword_ansver value 'no' */ 539 if (crossword_ansver == 'no') { 540 jQuery('.wha-square.wha-letter').removeClass('wha-correct'); 541 } 542 543 if (flag_empty != 'empty' && flag_correct == false) { 544 545 if (dir == 0 && crossword_ansver_incorect == 'yes') { 546 547 /* added check if crossword_ansver_incorect value 'yes' */ 548 for (var z = df; z < arr_char.length + df; z++) { 549 jQuery('.wha-square.wha-letter[data-x="' + z + '"][data-y="' + y + '"] ').addClass('wha-error'); 550 } 551 } 552 else { 553 for (var z = df; z < arr_char.length + df; z++) { 554 jQuery('.wha-square.wha-letter[data-y="' + z + '"][data-x="' + x + '"] ').addClass('wha-error'); 555 } 556 } 557 } 558 /* added check if crossword_ansver_incorect value 'no' */ 559 if (crossword_ansver_incorect == 'no') { 560 jQuery('.wha-square.wha-letter').removeClass('wha-error'); 561 } 562 } 563 else { 564 if (flag_empty != 'empty' && flag_correct == true) { 565 566 if (dir == 0 && correct_ansver == 'yes') { 567 568 //gorizontale 569 /* added check if crossword_ansver value 'yes' */ 570 for (var z = df; z < arr_char.length + df; z++) { 571 572 if (correct_ansver_var == 'yes') { 573 jQuery('.wha-square.wha-letter[data-x="' + z + '"][data-y="' + y + '"] ').addClass('wha-correct').css({"background-color": "#b3ffb4"}); 574 } else { 575 jQuery('.wha-square.wha-letter[data-x="' + z + '"][data-y="' + y + '"] ').addClass('wha-correct').css({"background-color": "none"}); 576 } 577 } 578 } 579 else { //verticale 580 for (var z = df; z < arr_char.length + df; z++) { 581 582 if (correct_ansver_var == 'yes') { 583 jQuery('.wha-square.wha-letter[data-y="' + z + '"][data-x="' + x + '"] ').addClass('wha-correct').css({"background-color": "#b3ffb4"}); 584 } else { 585 jQuery('.wha-square.wha-letter[data-y="' + z + '"][data-x="' + x + '"] ').addClass('wha-correct').css({"background-color": "none"}); 586 } 587 588 } 589 } 590 } 591 /* added check if crossword_ansver value 'no' */ 592 if (correct_ansver == 'no') { 593 jQuery('.wha-square.wha-letter').removeClass('wha-correct'); 594 } 595 596 if (flag_empty != 'empty' && flag_correct == false) { 597 if (dir == 0 && incorrect_ansver == 'yes') { /* added check if crossword_ansver_incorect value 'yes' */ 598 for (var z = df; z < arr_char.length + df; z++) { 599 jQuery('.wha-square.wha-letter[data-x="' + z + '"][data-y="' + y + '"] ').addClass('wha-error'); 600 } 601 } 602 else { 603 for (var z = df; z < arr_char.length + df; z++) { 604 jQuery('.wha-square.wha-letter[data-y="' + z + '"][data-x="' + x + '"] ').addClass('wha-error'); 605 } 606 } 607 } 608 /* added check if crossword_ansver_incorect value 'no' */ 609 if (incorrect_ansver == 'no') { 610 jQuery('.wha-square.wha-letter').removeClass('wha-error'); 611 } 612 } 613 } 614 615 }); 616 617 if (jQuery(".wha-square.wha-letter").length == jQuery(".wha-square.wha-letter.wha-correct").length) { 618 619 jQuery('#overlay').fadeIn(400, 620 function () { 621 jQuery('#modal_form_crossword') 622 .css('display', 'block') 623 .animate({opacity: 1, top: '50%'}, 200); 624 }); 625 626 } 627 }); 628 629 /* Added check for crrosword questin align */ 630 if (useGlobalOptions == 'yes') { 631 if (crossword_align_question == 'left') { 632 jQuery('.crossword_wrapper').css('flex-direction', 'row-reverse'); 633 } else if (crossword_align_question == 'right') { 634 jQuery('.crossword_wrapper').css('flex-direction', 'row'); 635 } else if (crossword_align_question == 'bottom') { 636 jQuery('.crossword_wrapper').css('flex-direction', 'column'); 637 } 638 } else { 639 if (align_question == 'left') { 640 jQuery('.crossword_wrapper').css('flex-direction', 'row-reverse'); 641 } else if (align_question == 'right') { 642 jQuery('.crossword_wrapper').css('flex-direction', 'row'); 643 } else if (align_question == 'bottom') { 644 jQuery('.crossword_wrapper').css('flex-direction', 'column'); 645 } 646 } 647 648 /* Added Question block width */ 649 650 if (useGlobalOptions == 'yes') { 651 jQuery('.wha-crossword-questions').css('max-width', crossword_width_question + 'px'); 652 } else { 653 jQuery('.wha-crossword-questions').css('max-width', question_width + 'px'); 654 } 655 656 /* Added border-color and background color for crosswords squares */ 657 if (useGlobalOptions == 'yes') { 658 jQuery('.wha-square.wha-letter').css({ 659 'border-color': '#' + borderColor, 660 'background-color': '#' + bgColor 661 }); 662 663 jQuery('.wha-crossword-questions .wha-line .wha-clue').css('color', '#' + crossword_question_color); 664 jQuery('.wha-crossword .wha-counter').css('color', '#' + counter_color); 665 } else { 666 jQuery('.wha-square.wha-letter').css({ 667 'border-color': '#' + optional_borderColor, 668 'background-color': '#' + optional_bgColor 669 }); 670 671 jQuery('.wha-crossword-questions .wha-line .wha-clue').css('color', '#' + optional_questionColor); 672 jQuery('.wha-crossword .wha-counter').css('color', '#' + optional_counterColor); 673 } 674 675 // Close modal window --- 676 jQuery('#modal_close, #overlay').click(function () { 677 678 var src = jQuery('#modal_form_crossword iframe').attr('src'); 679 jQuery('#modal_form_crossword iframe').attr('src', ''); 680 jQuery('#modal_form_crossword iframe').attr('src', src); 681 682 jQuery('#modal_form_crossword') 683 .animate({opacity: 0, top: '45%'}, 200, 684 function () { 685 jQuery(this).css('display', 'none'); 686 jQuery('#overlay').fadeOut(400); 687 } 688 ); 689 }); 690 });
691 692 //---------- Move, Delete, Update Chars in Fields of Crossword ----------// 693 694 jQuery(document).ready(function () { 695 696 lastMoveDirection = null; 697 698 // Change cursor 699 jQuery('.wha-char').hover(function () { 700 701 if (jQuery(this).val() == '') { 702 jQuery(this).css({'cursor': 'text'}); 703 } else { 704 jQuery(this).css({'cursor': 'pointer'}); 705 } 706 }, function () { 707 }); 708 709 // Selected char 710 jQuery('.wha-char').on('click touchstart', function () { 711 this.select(); 712 this.setSelectionRange(0, 99999); 713 }); 714 715 // Delete & move arrow 716 jQuery('.wha-char').on('keydown', function (e) { 717 718 var datax = parseInt(jQuery(this).parent().attr('data-x')); 719 var datay = parseInt(jQuery(this).parent().attr('data-y')); 720 721 // Delete value 722 if (e.which == 46 || e.which == 8) { 723 724 e.preventDefault(); 725 this.value = ''; 726 727 // Move X 728 if (jQuery(this).parent('div.wha-letter').next('div.wha-letter').length > 0) { 729 if (jQuery(window).width() > 769) { 730 jQuery(this).parent('div.wha-letter').next('div.wha-letter').find('input').focus(); 731 } 732 } 733 // Move Y 734 else { 735 var x = jQuery(this).parent('div.wha-letter').attr('data-x'); 736 if (jQuery(window).width() > 769) { 737 jQuery(this).parent('div.wha-letter').parent('div.wha-row').next('div.wha-row').find('[data-x="' + x + '"]').find('input').focus(); 738 } 739 } 740 } 741 // Left arrow 742 if (e.which == 37) { 743 datax--; 744 jQuery(this).parent().siblings('[data-x = "' + datax + '"][data-y = "' + datay + '"]').find('input').focus(); 745 } 746 // Right arrow 747 if (e.which == 39) { 748 datax++; 749 jQuery(this).parent().siblings('[data-x = "' + datax + '"][data-y = "' + datay + '"]').find('input').focus(); 750 } 751 // Up arrow 752 if (e.which == 38) { 753 datay--; 754 jQuery(this).parent().parent().prev().find('[data-x = "' + datax + '"][data-y = "' + datay + '"]').find('input').focus(); 755 } 756 // Down arrow 757 if (e.which == 40) { 758 datay++; 759 jQuery(this).parent().parent().next().find('[data-x = "' + datax + '"][data-y = "' + datay + '"]').find('input').focus(); 760 } 761 }); 762 763 // Move cursor when print user 764 765 function GetIEVersion() { 766 var sAgent = window.navigator.userAgent; 767 var Idx = sAgent.indexOf("MSIE"); 768 769 // If IE, return version number. 770 if (Idx > 0) 771 return parseInt(sAgent.substring(Idx + 5, sAgent.indexOf(".", Idx))); 772 773 // If IE 11 then look for Updated user agent string. 774 775 else if (!!navigator.userAgent.match(/Trident\/7\./) || navigator.userAgent.match(/ Edge\//) ) 776 return 11; 777 778 else 779 return 0; //It is not IE 780 } 781 782 if (jQuery(window).width() < 769) { 783 784 var elems = document.getElementById('wha-crossword').childNodes; 785 786 for (var i = 0; i < elems.length; i++) { 787 788 var div = elems[i].childNodes; 789 790 for (var j = 0; j < div.length; j++) { 791 792 var div_ch = div[j].childNodes; 793 794 for (var k = 0; k < div_ch.length; k++) { 795 796 if (div_ch[k].nodeName == "INPUT") { 797 798 div_ch[k].addEventListener('input', function (e) { 799 800 e.preventDefault(); 801 802 // Move X 803 if (lastMoveDirection == 'x' && this.parentNode.nextSibling.classList.contains('wha-letter')) { 804 lastMoveDirection = 'x'; 805 this.parentNode.nextSibling.querySelector(".wha-char").focus(); 806 this.parentNode.nextSibling.querySelector(".wha-char").setSelectionRange(0, 99999); 807 } 808 // Move Y 809 else { 810 lastMoveDirection = 'y'; 811 var x = this.parentNode.getAttribute('data-x'); 812 813 814 if (jQuery(this).parent('div.wha-letter').parent('div.wha-row').next('div.wha-row').find('[data-x="' + x + '"]').find('input').length > 0) { 815 816 var range = jQuery(this).parent('div.wha-letter').parent('div.wha-row').next('div.wha-row').find('[data-x="' + x + '"]').find('input'); 817 range.focus(); 818 range.get(0).setSelectionRange(0, 99999); 819 820 } else { 821 822 lastMoveDirection = 'x'; 823 this.parentNode.nextSibling.querySelector(".wha-char").focus(); 824 this.parentNode.nextSibling.querySelector(".wha-char").setSelectionRange(0, 99999); 825 826 } 827 828 } 829 }, false); 830 } 831 } 832 } 833 } 834 } 835 // Desktop 836 else { 837 if (GetIEVersion() > 0) { 838 jQuery('.wha-char').on('keyup', function (e) { 839 840 var x = jQuery(this).parent('div.wha-letter').attr('data-x'); 841 842 // Change data in input field 843 if (window.getSelection && window.getSelection().toString() != '') { 844 845 if (lastMoveDirection == 'x' && jQuery(this).parent('div.wha-letter').next('div.wha-letter').length > 0) { 846 lastMoveDirection = 'x'; 847 jQuery(this).val(e.char).parent('div.wha-letter').next('div.wha-letter').find('input').focus().select(); 848 } else { 849 850 if (jQuery(this).val(e.char).parent('div.wha-letter').parent('div.wha-row').next('div.wha-row').find('[data-x="' + x + '"]').find('input').length > 0) { 851 852 lastMoveDirection = 'y'; 853 jQuery(this).val(e.char).parent('div.wha-letter').parent('div.wha-row').next('div.wha-row').find('[data-x="' + x + '"]').find('input').focus().select(); 854 855 } 856 else { 857 858 lastMoveDirection = 'x'; 859 jQuery(this).val(e.char).parent('div.wha-letter').next('div.wha-letter').find('input').focus().select(); 860 861 } 862 } 863 } 864 else { 865 // Move X 866 if (lastMoveDirection == 'x' && jQuery(this).parent('div.wha-letter').next('div.wha-letter').length > 0) { 867 lastMoveDirection = 'x'; 868 jQuery(this).parent('div.wha-letter').next('div.wha-letter').find('input').focus().select(); 869 } 870 // Move Y 871 else { 872 873 if (jQuery(this).parent('div.wha-letter').parent('div.wha-row').next('div.wha-row').find('[data-x="' + x + '"]').find('input').length > 0) { 874 875 lastMoveDirection = 'y'; 876 jQuery(this).parent('div.wha-letter').parent('div.wha-row').next('div.wha-row').find('[data-x="' + x + '"]').find('input').focus().select(); 877 878 } 879 else { 880 881 lastMoveDirection = 'x'; 882 jQuery(this).parent('div.wha-letter').next('div.wha-letter').find('input').focus().select(); 883 884 } 885 886 } 887 } 888 }); 889 890 } else { 891 jQuery('.wha-char').on('keypress', function (e) { 892 893 var x = jQuery(this).parent('div.wha-letter').attr('data-x'); 894 895 // Change data in input field 896 if (window.getSelection && window.getSelection().toString() != '') { 897 898 if (lastMoveDirection == 'x' && jQuery(this).parent('div.wha-letter').next('div.wha-letter').length > 0) { 899 lastMoveDirection = 'x'; 900 jQuery(this).val(e.char).parent('div.wha-letter').next('div.wha-letter').find('input').focus().select(); 901 } else { 902 903 if (jQuery(this).val(e.char).parent('div.wha-letter').parent('div.wha-row').next('div.wha-row').find('[data-x="' + x + '"]').find('input').length > 0) { 904 905 lastMoveDirection = 'y'; 906 jQuery(this).val(e.char).parent('div.wha-letter').parent('div.wha-row').next('div.wha-row').find('[data-x="' + x + '"]').find('input').focus().select(); 907 908 } 909 else { 910 911 lastMoveDirection = 'x'; 912 jQuery(this).val(e.char).parent('div.wha-letter').next('div.wha-letter').find('input').focus().select(); 913 914 } 915 916 917 } 918 } 919 else { 920 // Move X 921 if (lastMoveDirection == 'x' && jQuery(this).parent('div.wha-letter').next('div.wha-letter').length > 0) { 922 923 lastMoveDirection = 'x'; 924 jQuery(this).parent('div.wha-letter').next('div.wha-letter').find('input').focus().select(); 925 } 926 // Move Y 927 else { 928 929 if (jQuery(this).parent('div.wha-letter').parent('div.wha-row').next('div.wha-row').find('[data-x="' + x + '"]').find('input').length > 0) { 930 931 lastMoveDirection = 'y'; 932 jQuery(this).parent('div.wha-letter').parent('div.wha-row').next('div.wha-row').find('[data-x="' + x + '"]').find('input').focus().select(); 933 934 } 935 else { 936 937 lastMoveDirection = 'x'; 938 jQuery(this).parent('div.wha-letter').next('div.wha-letter').find('input').focus().select(); 939 940 } 941 942 } 943 } 944 }); 945 } 946 } 947 948 // Focus input counter 949 jQuery('.wha-letter').hover( 950 function () { 951 jQuery(this).find('.wha-counter').hide() 952 }, 953 function () { 954 jQuery(this).find('.wha-counter').show() 955 } 956 ); 957 958 });
959} 960 961//--- End block -
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.