From 6e28e7607bd492c960f40260d1de64e26652e2ba Mon Sep 17 00:00:00 2001 From: Steven Thomas Date: Thu, 20 Mar 2014 09:31:21 -0700 Subject: Updated lookup so that it crosses word off list if found. --- js/wordsearch.js | 9 +++++++++ js/wordsearch.min.js | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/js/wordsearch.js b/js/wordsearch.js index 222b94f..17b54d8 100644 --- a/js/wordsearch.js +++ b/js/wordsearch.js @@ -330,6 +330,15 @@ el.classList.add('ws-found'); } + + //Cross word off list. + var wordList = document.querySelector(".ws-words"); + var wordListItems = wordList.getElementsByTagName("li"); + for(var i=0; i"; + } + } } } diff --git a/js/wordsearch.min.js b/js/wordsearch.min.js index a825a89..8bc3957 100644 --- a/js/wordsearch.min.js +++ b/js/wordsearch.min.js @@ -1 +1 @@ -!function(){"use strict";function t(t,e){this.wrapEl=t,this.wrapEl.classList.add("ws-area");var i={directions:["W","N","WN","EN"],gridSize:10,words:["one","two","three","four","five"],debug:!1};if(this.settings=Object.merge(e,i),this.parseWords(this.settings.gridSize)){for(var r=!1;0==r;)this.initialize(),r=this.addWords();this.settings.debug||this.fillUpFools(),this.drawmatrix()}}Element.prototype.wordSearch=function(e){return new t(this,e)},t.prototype.parseWords=function(t){for(var e=!0,i=0;it&&(alert("The length of word `"+r+"` is overflow the gridSize."),console.error("The length of word `"+r+"` is overflow the gridSize."),e=!1)}return e},t.prototype.addWords=function(){for(var t=!0,e=0,i=!0;t;){var r=this.settings.directions[Math.rangeInt(this.settings.directions.length-1)],s=this.addWord(this.settings.words[e],r),i=!0;0==s&&(t=!1,i=!1),e++,e>=this.settings.words.length&&(t=!1)}return i},t.prototype.addWord=function(t,e){var i,r,s=!0,o={W:[0,1],N:[1,0],WN:[1,1],EN:[1,-1]};switch(e){case"W":var i=Math.rangeInt(this.settings.gridSize-1),r=Math.rangeInt(this.settings.gridSize-t.length);break;case"N":var i=Math.rangeInt(this.settings.gridSize-t.length),r=Math.rangeInt(this.settings.gridSize-1);break;case"WN":var i=Math.rangeInt(this.settings.gridSize-t.length),r=Math.rangeInt(this.settings.gridSize-t.length);break;case"EN":var i=Math.rangeInt(this.settings.gridSize-t.length),r=Math.rangeInt(t.length-1,this.settings.gridSize-1);break;default:var n="UNKNOWN DIRECTION "+e+"!";alert(n),console.log(n)}for(var a=0;ae;e++)for(var i=0;t>i;i++){var r={letter:".",row:e,col:i};this.matrix[e]||(this.matrix[e]=[]),this.matrix[e][i]=r}},t.prototype.drawmatrix=function(){for(var t=0;tt?1:-1,n=e===r?0:r>e?1:-1,a=t,h=e;s.push(this.getItem(a,h));do a+=o,h+=n,s.push(this.getItem(a,h));while(a!==i||h!==r)}return s},t.prototype.getItem=function(t,e){return this.matrix[t]?this.matrix[t][e]:void 0},t.prototype.clearHighlight=function(){for(var t=document.querySelectorAll(".ws-selected"),e=0;e-1||this.settings.words.indexOf(e[1])>-1)for(var i=0;it&&(alert("The length of word `"+i+"` is overflow the gridSize."),console.error("The length of word `"+i+"` is overflow the gridSize."),e=!1)}return e},t.prototype.addWords=function(){for(var t=!0,e=0,r=!0;t;){var i=this.settings.directions[Math.rangeInt(this.settings.directions.length-1)],s=this.addWord(this.settings.words[e],i),r=!0;0==s&&(t=!1,r=!1),e++,e>=this.settings.words.length&&(t=!1)}return r},t.prototype.addWord=function(t,e){var r,i,s=!0,o={W:[0,1],N:[1,0],WN:[1,1],EN:[1,-1]};switch(e){case"W":var r=Math.rangeInt(this.settings.gridSize-1),i=Math.rangeInt(this.settings.gridSize-t.length);break;case"N":var r=Math.rangeInt(this.settings.gridSize-t.length),i=Math.rangeInt(this.settings.gridSize-1);break;case"WN":var r=Math.rangeInt(this.settings.gridSize-t.length),i=Math.rangeInt(this.settings.gridSize-t.length);break;case"EN":var r=Math.rangeInt(this.settings.gridSize-t.length),i=Math.rangeInt(t.length-1,this.settings.gridSize-1);break;default:var n="UNKNOWN DIRECTION "+e+"!";alert(n),console.log(n)}for(var a=0;ae;e++)for(var r=0;t>r;r++){var i={letter:".",row:e,col:r};this.matrix[e]||(this.matrix[e]=[]),this.matrix[e][r]=i}},t.prototype.drawmatrix=function(){for(var t=0;tt?1:-1,n=e===i?0:i>e?1:-1,a=t,h=e;s.push(this.getItem(a,h));do a+=o,h+=n,s.push(this.getItem(a,h));while(a!==r||h!==i)}return s},t.prototype.getItem=function(t,e){return this.matrix[t]?this.matrix[t][e]:void 0},t.prototype.clearHighlight=function(){for(var t=document.querySelectorAll(".ws-selected"),e=0;e-1||this.settings.words.indexOf(e[1])>-1){for(var r=0;r"+a[r].innerHTML+"")}},t.prototype.onMousedown=function(t){var e=this;return function(){e.selectFrom=t}},t.prototype.onMouseover=function(t){var e=this;return function(){if(e.selectFrom){e.selected=e.getItems(e.selectFrom.row,e.selectFrom.col,t.row,t.col),e.clearHighlight();for(var r=0;r