var drag; var drop; var xhr = new XMLHttpRequest(); //xhr.open('GET', 'data/move.json', true); for (b=0; C('coord').length > b; b++) {C('coord')[b].onmousedown = function () { event.preventDefault(); //drop = null; drag = this.id; }} for (b=0; C('coord').length > b; b++) {C('coord')[b].onmouseup = function () { drop = this.id; //if (drop !== undefined && drag !== undefined) {console.log(drag + ' -> ' + drop)} //if (drop !== undefined && drop !== null && drag !== undefined && drag !== null) { //console.log(this); if (drop.length === 3 && drag.length === 3) { //console.log(this); xhr.open('GET', 'move/' + drag + '/' + drop , true); //xhr.send(drag + ',' + drop); xhr.send(null); xhr.onload = function () { if (xhr.status === 200) { responseObject = JSON.parse(xhr.responseText); if (responseObject.w.status.length === 1 || responseObject.w.status[1] !== 0) { I(drag).setAttribute('src', 'i/' + responseObject.w.src[0] + '.png'); I(drop).setAttribute('src', 'i/' + responseObject.w.src[1] + '.png'); I(drag).id = responseObject.w.src[0]; I(drop).id = responseObject.w.src[1]; // TODO: Display status and/or sleep. I('title').innerHTML = responseObject.b.src[1] + ' moves from ' + responseObject.b.src[0] + ' to ' + responseObject.b.dst[0]; if (responseObject.b.dst.length === 2) {I('title').innerHTML += ' and takes ' + responseObject.b.dst[1]} I('description').innerHTML = 'Turn ' + responseObject.w.status.length + ' of white.'; //I('title').innerHTML = responseObject.b.status[0]; //I('description').innerHTML = responseObject.b.status[1]; I(responseObject.b.src[1]).setAttribute('src', 'i/' + responseObject.b.src[0] + '.png'); I(responseObject.b.dst[responseObject.b.dst.length-1]).setAttribute('src', 'i/' + responseObject.b.src[1] + '.png'); I(responseObject.b.src[1]).id = responseObject.b.src[0]; I(responseObject.b.dst[responseObject.b.dst.length-1]).id = responseObject.b.src[1]; } } }; } //drag = null; }} //for (b=0; C('coord').length > b; b++) {C('coord')[b].onmousemove = function () { //if (drag !== null && drag !== undefined) {console.log(this.x + '.' + this.y)} //if (drag !== null && drag !== undefined) {I(this.id).style.position = 'absolute'; I(this.id).style.left = this.x + 'px'; I(this.id).style.up = this.y + 'px'} //}}