crosswords.min.js 1.4 KB

123
  1. var e=[];function h(){}function k(){this.g=!1;this.b=null}k.prototype.update=function(a){null===a.type?this.g=!0:void 0!==a.definitions&&(this.b=[],a.definitions.forEach(function(){this.b.push(new h)}.bind(this)));return 0};function l(a){this.f=a.w;this.c=a.h;this.a=[];for(a=0;a<this.f;a++){this.a[a]=[];for(var b=0;b<this.c;b++)this.a[a][b]=new k}}l.prototype.update=function(a){var b=null,c=this.a;a.forEach(function(a){b=Math.max(b||0,c[a.x][a.y].update(a))});return b};var m,n=0,p;function q(a){var b="/api/poll?grid="+m+"&v="+n,c=new XMLHttpRequest;c.onreadystatechange=function(){if(4===c.readyState){var b=null;if(200===c.status){b=c.response;try{b=JSON.parse(b)}catch(d){b=null}}a(b)}};c.open("GET",b,!0);c.send(null)}
  2. function r(){q(function(a){p=new l(a);if(a.grid){n=Math.max(p.update(a.grid)||0,n);a=document.createDocumentFragment();for(var b=0;b<p.c;b++){var c=document.createElement("div");c.className="crossword-line";a.appendChild(c);for(var f=0;f<p.f;f++){var d;d=p.a[f][b];var g=document.createElement("div");g.className="cell";d.g?g.classList.add("cell-disabled"):null!==d.b?g.classList.add("cell-definition"):(g.classList.add("cell-letter"),console.log(d));d=g;c.appendChild(d);e.push({x:f,y:b,i:d,data:p.a[f][b]})}}document.body.textContent=
  3. "";document.body.appendChild(a)}})}document.addEventListener("DOMContentLoaded",function(){m=document.location.hash.substr(1);""==m?document.location.href="/":r()});