summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--js/wordsearch.js9
-rw-r--r--js/wordsearch.min.js2
2 files changed, 10 insertions, 1 deletions
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<wordListItems.length; i++){
+ if(words[0].toLowerCase() == wordListItems[i].innerHTML.toLowerCase()){
+ wordListItems[i].innerHTML = "<del>"+wordListItems[i].innerHTML+"</del>";
+ }
+ }
}
}
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;i<this.settings.words.length;i++){this.settings.words[i]=this.settings.words[i].toUpperCase();var r=this.settings.words[i];r.length>t&&(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;a<t.length;a++){var h=i+a*o[e][0],l=r+a*o[e][1],d=this.matrix[h][l].letter;"."==d||d==t[a]?this.matrix[h][l].letter=t[a]:s=!1}return s},t.prototype.initialize=function(){this.matrix=[],this.selectFrom=null,this.selected=[],this.initmatrix(this.settings.gridSize)},t.prototype.initmatrix=function(t){for(var e=0;t>e;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;t<this.settings.gridSize;t++){var e=document.createElement("div");e.setAttribute("class","ws-row"),this.wrapEl.appendChild(e);for(var i=0;i<this.settings.gridSize;i++){var r=document.createElement("canvas");r.setAttribute("class","ws-col"),r.setAttribute("width",40),r.setAttribute("height",40);var s=r.width/2,o=r.height/2,n=r.getContext("2d");n.font="400 28px Calibri",n.textAlign="center",n.textBaseline="middle",n.fillStyle="#333",n.fillText(this.matrix[t][i].letter,s,o),r.addEventListener("mousedown",this.onMousedown(this.matrix[t][i])),r.addEventListener("mouseover",this.onMouseover(this.matrix[t][i])),r.addEventListener("mouseup",this.onMouseup()),e.appendChild(r)}}},t.prototype.fillUpFools=function(){for(var t=0;t<this.settings.gridSize;t++)for(var e=0;e<this.settings.gridSize;e++)"."==this.matrix[t][e].letter&&(this.matrix[t][e].letter=String.fromCharCode(Math.rangeInt(65,90)))},t.prototype.getItems=function(t,e,i,r){var s=[];if(t===i||e===r||Math.abs(i-t)==Math.abs(r-e)){var o=t===i?0:i>t?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<t.length;e++)t[e].classList.remove("ws-selected")},t.prototype.lookup=function(t){for(var e=[""],i=0;i<t.length;i++)e[0]+=t[i].letter;if(e.push(e[0].split("").reverse().join("")),this.settings.words.indexOf(e[0])>-1||this.settings.words.indexOf(e[1])>-1)for(var i=0;i<t.length;i++){var r=t[i].row+1,s=t[i].col+1,o=document.querySelector(".ws-area .ws-row:nth-child("+r+") .ws-col:nth-child("+s+")");o.classList.add("ws-found")}},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 i=0;i<e.selected.length;i++){var r=e.selected[i],s=r.row+1,o=r.col+1,n=document.querySelector(".ws-area .ws-row:nth-child("+s+") .ws-col:nth-child("+o+")");n.className+=" ws-selected"}}}},t.prototype.onMouseup=function(){var t=this;return function(){t.selectFrom=null,t.clearHighlight(),t.lookup(t.selected),t.selected=[]}}}(); \ No newline at end of file
+!function(){"use strict";function t(t,e){this.wrapEl=t,this.wrapEl.classList.add("ws-area");var r={directions:["W","N","WN","EN"],gridSize:10,words:["one","two","three","four","five"],debug:!1};if(this.settings=Object.merge(e,r),this.parseWords(this.settings.gridSize)){for(var i=!1;0==i;)this.initialize(),i=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,r=0;r<this.settings.words.length;r++){this.settings.words[r]=this.settings.words[r].toUpperCase();var i=this.settings.words[r];i.length>t&&(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;a<t.length;a++){var h=r+a*o[e][0],l=i+a*o[e][1],d=this.matrix[h][l].letter;"."==d||d==t[a]?this.matrix[h][l].letter=t[a]:s=!1}return s},t.prototype.initialize=function(){this.matrix=[],this.selectFrom=null,this.selected=[],this.initmatrix(this.settings.gridSize)},t.prototype.initmatrix=function(t){for(var e=0;t>e;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;t<this.settings.gridSize;t++){var e=document.createElement("div");e.setAttribute("class","ws-row"),this.wrapEl.appendChild(e);for(var r=0;r<this.settings.gridSize;r++){var i=document.createElement("canvas");i.setAttribute("class","ws-col"),i.setAttribute("width",40),i.setAttribute("height",40);var s=i.width/2,o=i.height/2,n=i.getContext("2d");n.font="400 28px Calibri",n.textAlign="center",n.textBaseline="middle",n.fillStyle="#333",n.fillText(this.matrix[t][r].letter,s,o),i.addEventListener("mousedown",this.onMousedown(this.matrix[t][r])),i.addEventListener("mouseover",this.onMouseover(this.matrix[t][r])),i.addEventListener("mouseup",this.onMouseup()),e.appendChild(i)}}},t.prototype.fillUpFools=function(){for(var t=0;t<this.settings.gridSize;t++)for(var e=0;e<this.settings.gridSize;e++)"."==this.matrix[t][e].letter&&(this.matrix[t][e].letter=String.fromCharCode(Math.rangeInt(65,90)))},t.prototype.getItems=function(t,e,r,i){var s=[];if(t===r||e===i||Math.abs(r-t)==Math.abs(i-e)){var o=t===r?0:r>t?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<t.length;e++)t[e].classList.remove("ws-selected")},t.prototype.lookup=function(t){for(var e=[""],r=0;r<t.length;r++)e[0]+=t[r].letter;if(e.push(e[0].split("").reverse().join("")),this.settings.words.indexOf(e[0])>-1||this.settings.words.indexOf(e[1])>-1){for(var r=0;r<t.length;r++){var i=t[r].row+1,s=t[r].col+1,o=document.querySelector(".ws-area .ws-row:nth-child("+i+") .ws-col:nth-child("+s+")");o.classList.add("ws-found")}for(var n=document.querySelector(".ws-words"),a=n.getElementsByTagName("li"),r=0;r<a.length;r++)e[0].toLowerCase()==a[r].innerHTML.toLowerCase()&&(a[r].innerHTML="<del>"+a[r].innerHTML+"</del>")}},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<e.selected.length;r++){var i=e.selected[r],s=i.row+1,o=i.col+1,n=document.querySelector(".ws-area .ws-row:nth-child("+s+") .ws-col:nth-child("+o+")");n.className+=" ws-selected"}}}},t.prototype.onMouseup=function(){var t=this;return function(){t.selectFrom=null,t.clearHighlight(),t.lookup(t.selected),t.selected=[]}}}(); \ No newline at end of file