WordFind


SUBMITTED BY: geebar777

DATE: Feb. 19, 2021, 10:57 a.m.

FORMAT: JavaScript

SIZE: 29.4 kB

HITS: 463

  1. (function e(t, n, r) {
  2. function s(o, u) {
  3. if (!n[o]) {
  4. if (!t[o]) {
  5. var a = typeof require == "function" && require;
  6. if (!u && a) return a(o, !0);
  7. if (i) return i(o, !0);
  8. throw new Error("Cannot find module '" + o + "'")
  9. }
  10. var f = n[o] = {exports: {}};
  11. t[o][0].call(f.exports, function (e) {
  12. var n = t[o][1][e];
  13. return s(n ? n : e)
  14. }, f, f.exports, e, t, n, r)
  15. }
  16. return n[o].exports
  17. }
  18. var i = typeof require == "function" && require;
  19. for (var o = 0; o < r.length; o++) s(r[o]);
  20. return s
  21. })({
  22. 1: [function (require, module, exports) {
  23. (function (global) {
  24. (function () {
  25. var ALPHABET, Cell, DIRECTIONS, LetterGrid, NUM_COLORS, angular, defaultWordlist, wordFromPath, _,
  26. __indexOf = [].indexOf || function (item) {
  27. for (var i = 0, l = this.length; i < l; i++) {
  28. if (i in this && this[i] === item) return i;
  29. }
  30. return -1;
  31. };
  32. angular = (typeof window !== "undefined" ? window['angular'] : typeof global !== "undefined" ? global['angular'] : null);
  33. _ = (typeof window !== "undefined" ? window['_'] : typeof global !== "undefined" ? global['_'] : null);
  34. defaultWordlist = require('./wordlist');
  35. NUM_COLORS = 5;
  36. var whaws_alphabet_option = jQuery('#whaws_alphabet_option').val();
  37. var whaws_rightwards_arrow = jQuery('#whaws_rightwards_arrow').val();
  38. var whaws_downwards_arrow = jQuery('#whaws_downwards_arrow').val();
  39. var whaws_leftwards_arrow = jQuery('#whaws_leftwards_arrow').val();
  40. var whaws_upwards_arrow = jQuery('#whaws_upwards_arrow').val();
  41. var whaws_south_east_arrow = jQuery('#whaws_south_east_arrow').val();
  42. var whaws_north_east_arrow = jQuery('#whaws_north_east_arrow').val();
  43. var whaws_south_west_arrow = jQuery('#whaws_south_west_arrow').val();
  44. var whaws_north_west_arrow = jQuery('#whaws_north_west_arrow').val();
  45. var level_difficulty_val = optional_wordsearch_vars.whaws_level_difficulty;
  46. var use_global_options = optional_wordsearch_vars.whaws_use_global_options;
  47. var direction = [];
  48. if (whaws_rightwards_arrow == 'on') {
  49. direction.push([1, 0]);
  50. }
  51. if (whaws_downwards_arrow == 'on') {
  52. direction.push([0, 1]);
  53. }
  54. if (whaws_leftwards_arrow == 'on') {
  55. direction.push([-1, 0]);
  56. }
  57. if (whaws_upwards_arrow == 'on') {
  58. direction.push([0, -1]);
  59. }
  60. if (whaws_south_east_arrow == 'on') {
  61. direction.push([1, 1]);
  62. }
  63. if (whaws_north_east_arrow == 'on') {
  64. direction.push([1, -1]);
  65. }
  66. if (whaws_south_west_arrow == 'on') {
  67. direction.push([-1, 1]);
  68. }
  69. if (whaws_north_west_arrow == 'on') {
  70. direction.push([-1, -1]);
  71. }
  72. ALPHABET = 'AABBCCDDEEFFGGHHIIJKLLMMNNOOPPQRSSTTUUVWXYZ';
  73. if (jQuery('#whaws_alphabet_option').length > 0) {
  74. if (whaws_alphabet_option.trim().length != 0) {
  75. ALPHABET = whaws_alphabet_option.trim();
  76. }
  77. }
  78. if (direction.length > 0) {
  79. DIRECTIONS = _.shuffle(direction);
  80. }
  81. else {
  82. DIRECTIONS = _.shuffle([[1, 0], [0, 1], [-1, 0], [0, -1], [1, 1], [1, -1], [-1, 1], [-1, -1]]);
  83. }
  84. wordFromPath = function (path) {
  85. var cell, word, _i, _len;
  86. word = '';
  87. if (path != null) {
  88. for (_i = 0, _len = path.length; _i < _len; _i++) {
  89. cell = path[_i];
  90. word += cell.letter;
  91. }
  92. }
  93. return word
  94. };
  95. Cell = (function () {
  96. function Cell(x, y) {
  97. this.x = x;
  98. this.y = y;
  99. this.solvedColorClasses = [];
  100. this.isSelected = false;
  101. this.onPath = false;
  102. this.onCorrectPath = false;
  103. }
  104. Cell.prototype.willFitLetter = function (letter) {
  105. return (this.letter == null) || this.letter === letter;
  106. };
  107. Cell.prototype.randomFill = function () {
  108. if (this.letter == null) {
  109. return this.letter = _.sample(ALPHABET);
  110. }
  111. };
  112. return Cell;
  113. })();
  114. LetterGrid = (function () {
  115. function LetterGrid(width, height, maxWords, wordlist) {
  116. var cell, i, row, word, x, y, _i, _j, _k, _l, _len, _len1, _len2, _ref;
  117. this.width = width != null ? width : 8;
  118. this.height = height != null ? height : 8;
  119. if (maxWords == null) {
  120. maxWords = 20;
  121. }
  122. if (wordlist == null) {
  123. wordlist = defaultWordlist;
  124. }
  125. this.cells = (function () {
  126. var _i, _ref, _results;
  127. _results = [];
  128. for (y = _i = 0, _ref = this.height - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; y = 0 <= _ref ? ++_i : --_i) {
  129. _results.push((function () {
  130. var _j, _ref1, _results1;
  131. _results1 = [];
  132. for (x = _j = 0, _ref1 = this.width - 1; 0 <= _ref1 ? _j <= _ref1 : _j >= _ref1; x = 0 <= _ref1 ? ++_j : --_j) {
  133. _results1.push(new Cell(x, y));
  134. }
  135. return _results1;
  136. }).call(this));
  137. }
  138. return _results;
  139. }).call(this);
  140. this.words = [];
  141. wordlist = _.sortBy(_.shuffle(wordlist), function (word) {
  142. return -1 * word.length;
  143. });
  144. for (i = _i = 1; 1 <= maxWords ? _i <= maxWords : _i >= maxWords; i = 1 <= maxWords ? ++_i : --_i) {
  145. for (_j = 0, _len = wordlist.length; _j < _len; _j++) {
  146. // word = wordlist[_j].replace(/\s/g, '');
  147. word = wordlist[_j].replace(/([\s-'])/g, ''); // letter grid settings
  148. if (__indexOf.call(this.words, word) < 0) {
  149. if (this._tryPutWord(word)) {
  150. break;
  151. }
  152. }
  153. }
  154. }
  155. _ref = this.cells;
  156. for (_k = 0, _len1 = _ref.length; _k < _len1; _k++) {
  157. row = _ref[_k];
  158. for (_l = 0, _len2 = row.length; _l < _len2; _l++) {
  159. cell = row[_l];
  160. cell.randomFill();
  161. }
  162. }
  163. this.words = _.sortBy(this.words, function (word) {
  164. return -1 * word.length;
  165. });
  166. }
  167. LetterGrid.prototype._tryPutWord = function (word) {
  168. var cell, dirX, dirY, endX, endY, i, path, startX, startY, _i, _j, _len, _len1, _ref;
  169. _ref = DIRECTIONS[this.words.length % DIRECTIONS.length], dirX = _ref[0], dirY = _ref[1];
  170. if (dirX !== 0 && word.length > this.width || dirY !== 0 && word.length > this.height) {
  171. return false;
  172. }
  173. startX = _.random((dirX === -1 ? word.length - 1 : 0), (dirX === 1 ? this.width - word.length : this.width - 1));
  174. startY = _.random((dirY === -1 ? word.length - 1 : 0), (dirY === 1 ? this.height - word.length : this.height - 1));
  175. endX = startX + dirX * (word.length - 1);
  176. endY = startY + dirY * (word.length - 1);
  177. path = this._getPath([startX, startY], [endX, endY]);
  178. for (i = _i = 0, _len = path.length; _i < _len; i = ++_i) {
  179. cell = path[i];
  180. if (!cell.willFitLetter(word[i])) {
  181. return false;
  182. }
  183. }
  184. for (i = _j = 0, _len1 = path.length; _j < _len1; i = ++_j) {
  185. cell = path[i];
  186. cell.letter = word[i];
  187. }
  188. this.words.push(word);
  189. return true;
  190. };
  191. LetterGrid.prototype._getPath = function (start, end) {
  192. var cellList, diffX, diffY, endX, endY, stepX, stepY, x, y;
  193. x = start[0], y = start[1];
  194. endX = end[0], endY = end[1];
  195. diffX = endX - x;
  196. diffY = endY - y;
  197. stepX = diffX === 0 ? 0 : diffX / Math.abs(diffX);
  198. stepY = diffY === 0 ? 0 : diffY / Math.abs(diffY);
  199. cellList = [];
  200. while (x >= 0 && y >= 0 && x < this.width && y < this.height) {
  201. cellList.push(this.cells[y][x]);
  202. if (x === endX && y === endY) {
  203. return cellList;
  204. }
  205. x += stepX;
  206. y += stepY;
  207. }
  208. return null;
  209. };
  210. LetterGrid.prototype.getPathFromCells = function (start, end) {
  211. return this._getPath([start.x, start.y], [end.x, end.y]);
  212. };
  213. return LetterGrid;
  214. })();
  215. angular.module('wordsearchApp', []).controller('WordsearchCtrl', [
  216. '$scope', function ($scope) {
  217. if (use_global_options == "yes") {
  218. $scope.levels = [
  219. {
  220. width: 8,
  221. height: 8
  222. }, {
  223. width: 9,
  224. height: 9
  225. }, {
  226. width: 10,
  227. height: 10
  228. }, {
  229. width: 11,
  230. height: 11
  231. }, {
  232. width: 12,
  233. height: 12
  234. }, {
  235. width: 13,
  236. height: 13
  237. }, {
  238. width: 14,
  239. height: 14
  240. }, {
  241. width: 15,
  242. height: 15
  243. }, {
  244. width: 16,
  245. height: 16
  246. }, {
  247. width: 17,
  248. height: 17
  249. }, {
  250. width: 18,
  251. height: 18
  252. }, {
  253. width: 19,
  254. height: 19
  255. }, {
  256. width: 20,
  257. height: 20
  258. }
  259. ];
  260. } else if (level_difficulty_val != "" || level_difficulty_val != null) { // set the difficulty level
  261. $scope.levels = [
  262. {
  263. width: level_difficulty_val,
  264. height: level_difficulty_val
  265. }
  266. ];
  267. }
  268. $scope.loadLevel = function (level) {
  269. $scope.currentLevel = level;
  270. $scope.grid = new LetterGrid(level.width, level.height);
  271. $scope.words = $scope.grid.words;
  272. $scope.testwords = defaultWordlist;
  273. $scope.foundWords = [];
  274. $scope.enableInput = true;
  275. $scope.colorIndex = 1;
  276. return $scope.colorClass = 'wha-color1';
  277. };
  278. $scope.loadLevel($scope.levels[0]);
  279. $scope.cellClicked = function (cell) {
  280. var path;
  281. if (!$scope.enableInput) {
  282. return;
  283. }
  284. if ($scope.selectedCell == null) {
  285. cell.isSelected = true;
  286. return $scope.selectedCell = cell;
  287. } else {
  288. path = $scope.grid.getPathFromCells($scope.selectedCell, cell);
  289. $scope.selectedCell.isSelected = false;
  290. $scope.selectedCell = null;
  291. $scope._submitPath(path);
  292. return $scope.clearPath();
  293. }
  294. };
  295. $scope.updatePath = function (cell) {
  296. var path, _i, _len, _ref, _ref2, _results;
  297. if ($scope.selectedCell != null) {
  298. path = $scope.grid.getPathFromCells($scope.selectedCell, cell);
  299. if (path != null) {
  300. _results = [];
  301. for (_i = 0, _len = path.length; _i < _len; _i++) {
  302. cell = path[_i];
  303. cell.onPath = true;
  304. _ref = wordFromPath(path);
  305. _ref2 = wordFromPath(path).split("").reverse().join("");
  306. if (__indexOf.call($scope.words, _ref) >= 0 || __indexOf.call($scope.words, _ref2) >= 0) {
  307. _results.push(cell.onCorrectPath = true);
  308. } else {
  309. _results.push(void 0);
  310. }
  311. }
  312. return _results;
  313. }
  314. }
  315. };
  316. $scope.clearPath = function () {
  317. var cell, row, _i, _len, _ref, _results;
  318. _ref = $scope.grid.cells;
  319. _results = [];
  320. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  321. row = _ref[_i];
  322. _results.push((function () {
  323. var _j, _len1, _results1;
  324. _results1 = [];
  325. for (_j = 0, _len1 = row.length; _j < _len1; _j++) {
  326. cell = row[_j];
  327. cell.onPath = false;
  328. _results1.push(cell.onCorrectPath = false);
  329. }
  330. return _results1;
  331. })());
  332. }
  333. return _results;
  334. };
  335. $scope._submitPath = function (path) {
  336. var alertCongrats, cell, foundWord, foundWord2, mywords, _i, _len;
  337. foundWord = wordFromPath(path);
  338. foundWord2 = wordFromPath(path);
  339. mywords = defaultWordlist;
  340. if (__indexOf.call($scope.words, foundWord) >= 0 || __indexOf.call($scope.words, foundWord2.split("").reverse().join("")) >= 0) {
  341. if (__indexOf.call($scope.words, foundWord2.split("").reverse().join("")) >= 0) {
  342. foundWord = foundWord.split("").reverse().join("")
  343. }
  344. $scope.words.splice($scope.words.indexOf(foundWord), 1);
  345. // $scope.foundWords.unshift({
  346. //
  347. // word: qq[0],
  348. //
  349. // colorClass: $scope.colorClass
  350. //
  351. // });
  352. // ([\s-'])
  353. for (var j = 0; j < mywords.length; j++) {
  354. if (mywords[j].replace(/([\s-'])/g, '') == foundWord) {
  355. jQuery(".wha-word-list button").each(function () {
  356. var button_text = jQuery(this).text().replace(/([\s-'])/g, '');
  357. if (foundWord == button_text) {
  358. jQuery(this).addClass('wha-solved ' + $scope.colorClass + '');
  359. }
  360. });
  361. }
  362. }
  363. for (_i = 0, _len = path.length; _i < _len; _i++) {
  364. cell = path[_i];
  365. cell.solvedColorClasses.push($scope.colorClass);
  366. }
  367. $scope.nextColor();
  368. if ($scope.words.length === 0) {
  369. $scope.enableInput = false;
  370. alertCongrats = function () {
  371. var event = new CustomEvent("wordsearch-finish", { "detail": $scope.foundWords.length });
  372. document.dispatchEvent(event);
  373. jQuery('.wha-wordsearch-app .wha-modal-wordsearch .wha-scope-foundWords').text($scope.foundWords.length);
  374. jQuery('.wha-wordsearch-app .wha-modal-wordsearch').first().addClass('opened');
  375. };
  376. return setTimeout(alertCongrats, 400);
  377. }
  378. }
  379. };
  380. /* hide words if they don't fit in to grid */
  381. var gridwords = $scope.words
  382. jQuery(document).ready(function ($) {
  383. jQuery(".wha-word-list button").hide();
  384. for (var j = 0; j < gridwords.length; j++) {
  385. jQuery(".wha-word-list button").each(function () {
  386. var word_item = jQuery(this).text().replace(/([\s-'])/g, '');
  387. if (word_item == gridwords[j]) {
  388. if (jQuery(this).text().replace(/([\s-'])/g, '').match(word_item)) {
  389. jQuery(this).show();
  390. }
  391. }
  392. });
  393. }
  394. jQuery("#wha-level-select-dropdown li").click(function () {
  395. jQuery(".wha-word-list button").hide();
  396. var gridwords = $scope.words;
  397. for (var j = 0; j < gridwords.length; j++) {
  398. jQuery(".wha-word-list button").each(function () {
  399. var word_item = jQuery(this).text().replace(/([\s-'])/g, '');
  400. if (word_item == gridwords[j]) {
  401. if (jQuery(this).text().replace(/([\s-'])/g, '').match(word_item)) {
  402. jQuery(this).show();
  403. }
  404. }
  405. });
  406. }
  407. jQuery('.wha-word-list button').removeClass('wha-solved');
  408. });
  409. });
  410. return $scope.nextColor = function () {
  411. $scope.colorIndex = $scope.colorIndex % NUM_COLORS + 1;
  412. return $scope.colorClass = "wha-color" + $scope.colorIndex;
  413. };
  414. }
  415. ]);
  416. }).call(this);
  417. }).call(this, typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  418. }, {"./wordlist": 2}], 2: [function (require, module, exports) {
  419. (function () {
  420. var words = [];
  421. jQuery.each(jQuery('.wha-wordsearch-word'), function (i, val) {
  422. words.push(jQuery(this).val());
  423. });
  424. if (jQuery('#whaws_alphabet_option').length > 0) {
  425. var whaws_alphabet_option = jQuery('#whaws_alphabet_option').val();
  426. if (whaws_alphabet_option.trim().length == 0 && words.length == 0) {
  427. module.exports = ['ARCHAEOPTERYX', 'CARBONIFEROUS', 'TYRANNOSAURUS', 'BRACHIOSAURUS', 'ICHTHYOSAURUS', 'BRONTOSAURUS', 'PLESIOSAURUS', 'ANKYLOSAURUS', 'STEGOSAURUS', 'PLEISTOCENE', 'PTERODACTYL', 'ECHINODERM', 'EXTINCTION', 'CRETACEOUS', 'ALLOSAURUS', 'BAROSAURUS', 'ALLOSAURUS', 'PALAEOCENE', 'CEPHALOPOD', 'CRUSTACEAN', 'BELEMNITE', 'CROCODILE', 'OLIGOCENE', 'TRILOBITE', 'VERTEBRAE', 'CARNIVORE', 'IGUANODON', 'DINOSAUR', 'GASTONIA', 'DRACONYX', 'AMMONITE', 'TENTACLE', 'JURASSIC', 'TRIASSIC', 'DEINODON', 'CIONODON', 'CERATOPS', 'ASTEROID', 'BARYONYX', 'MOLLUSCS', 'MESOZOIC', 'RAPTOREX', 'HOLOCENE', 'OZRAPTOR', 'STARFISH', 'KILESKUS', 'ASTRODON', 'NAUTILUS', 'SAUROPOD', 'ECHINOID', 'FLIPPER', 'REPTILE', 'PERMIAN', 'MIOCENE', 'CALCITE', 'AETONYX', 'CRINOID', 'CRYSTAL', 'EXTINCT', 'SPECIES', 'BIVALVE', 'PACIFIC', 'CHISEL', 'FOSSIL', 'PERIOD', 'HAMMER', 'ISLAND', 'MAMMAL', 'EOCENE', 'INSECT', 'LIZARD', 'PEBBLE', 'PLANT', 'CORAL', 'STONE', 'AMBER', 'TOOTH', 'CLIFF', 'SHELL', 'OCEAN', 'SQUID', 'COAST', 'SHARK', 'SKULL', 'SPINE', 'CLAW', 'CAVE', 'TIDE', 'BIRD', 'LEAF', 'FISH', 'BONE', 'ROCK', 'PREY', 'COAL', 'FERN', 'LEAF', 'TAIL'];
  428. }
  429. else {
  430. module.exports = words;
  431. }
  432. }
  433. }).call(this);
  434. }, {}]
  435. }, {}, [1]);
  436. jQuery(document).ready(function ($) {
  437. // ul li dopdown (select level)
  438. function DropDown(el) {
  439. this.dd = el;
  440. this.placeholder = this.dd.children('span');
  441. this.opts = this.dd.find('ul.wha-drop li');
  442. this.val = '';
  443. this.index = -1;
  444. this.initEvents();
  445. }
  446. DropDown.prototype = {
  447. initEvents: function () {
  448. var obj = this;
  449. obj.dd.on('click', function (e) {
  450. e.preventDefault();
  451. e.stopPropagation();
  452. $(this).toggleClass('active');
  453. });
  454. obj.opts.on('click', function () {
  455. var opt = $(this);
  456. obj.val = opt.text();
  457. obj.index = opt.index();
  458. obj.placeholder.text(obj.val);
  459. opt.siblings().removeClass('selected');
  460. opt.filter(':contains("' + obj.val + '")').addClass('selected');
  461. }).change();
  462. },
  463. getValue: function () {
  464. return this.val;
  465. },
  466. getIndex: function () {
  467. return this.index;
  468. }
  469. };
  470. $(function () {
  471. // create new variable for each menu
  472. var dd1 = new DropDown($('#noble-gases'));
  473. $(document).click(function () {
  474. // close menu on document click
  475. $('.wha-wrap-drop').removeClass('active');
  476. });
  477. });
  478. // refresh game field after close window 'Congratulation'
  479. $('.wha-closemodale').click(function (e) {
  480. e.preventDefault();
  481. $('.wha-modale').removeClass('opened');
  482. if (jQuery("#wha-level-select-dropdown li").hasClass('selected')) {
  483. setTimeout(function () {
  484. $("#wha-level-select-dropdown li.selected a").trigger("click");
  485. $(".wha-wrap-drop").removeClass("active");
  486. }, 100);
  487. } else {
  488. setTimeout(function () {
  489. $("#wha-level-select-dropdown li:first-child a").trigger("click");
  490. $(".wha-wrap-drop").removeClass("active");
  491. }, 100);
  492. }
  493. jQuery('.wha-word-list button').removeClass('wha-solved wha-color')
  494. });
  495. //disable search on page (Ctrl+F)
  496. window.addEventListener("keydown", function (e) {
  497. if (e.keyCode === 114 || (e.ctrlKey && e.keyCode === 70)) {
  498. e.preventDefault();
  499. }
  500. })
  501. var difficulty = optional_wordsearch_vars.whaws_level_difficulty;
  502. var global_diff = jQuery('#wha-level-select-dropdown li:first-child a').val().replace(/x([0-9])/g, '');
  503. jQuery(".wha-word-list button").each(function () {
  504. var button_text = jQuery(this).text().replace(/\s/g, '').length;
  505. if (button_text > difficulty || button_text > global_diff) {
  506. jQuery(this).hide();
  507. }
  508. });
  509. var grid_height = jQuery('.wha-ws-grid').height();
  510. jQuery('.wha-word-list').css('max-height', grid_height + 80);
  511. jQuery("#wha-level-select-dropdown li").click(function () {
  512. var grid_height = jQuery('.wha-ws-grid').height();
  513. jQuery('.wha-word-list').css('max-height', grid_height + 80);
  514. })
  515. var wha_ws_grid_width = jQuery('.wha-ws-grid').width();
  516. jQuery('.wha-dir-bottom .wha-word-list').css('max-width', wha_ws_grid_width+'px');
  517. jQuery('.wha-dir-top .wha-word-list').css('max-width', wha_ws_grid_width+'px');
  518. //jQuery('.wha-wordsearch-row').removeClass('wha-hidden');
  519. });

comments powered by Disqus