/* * js.js * Neighbourhood Fix-It JavaScript * * TODO * Investigate jQuery * Tidy it all up * Don't wrap around tiles as it's quite confusing if the tile server is slow to respond * Selection of pin doesn't really need a server request, but I don't really care * */ YAHOO.util.Event.onContentReady('compass', function() { var points = this.getElementsByTagName('a'); points[1].onclick = function() { pan(0, tileheight); return false; }; points[3].onclick = function() { pan(tilewidth, 0); return false; }; points[4].onclick = function() { pan(-tilewidth, 0); return false; }; points[6].onclick = function() { pan(0, -tileheight); return false; }; points[0].onclick = function() { pan(tilewidth, tileheight); return false; }; points[2].onclick = function() { pan(-tilewidth, tileheight); return false; }; points[5].onclick = function() { pan(tilewidth, -tileheight); return false; }; points[7].onclick = function() { pan(-tilewidth, -tileheight); return false; }; }); YAHOO.util.Event.onContentReady('map', function() { var dragO = new YAHOO.util.DDMap('map'); update_tiles(0, 0, false, true); }); YAHOO.util.Event.onContentReady('mapForm', function() { this.onsubmit = function() { this.x.value = x + 2; this.y.value = y + 2; return true; } }); // I love the global var tile_x = 0; var tile_y = 0; var tilewidth = 254; var tileheight = 254; function image_rotate(i, j, x, y) { var id = 't' + i + '.' + j; var img = document.getElementById(id); if (x) img.style.left = (img.offsetLeft + x*tilewidth) + 'px'; if (y) img.style.top = (img.offsetTop + y*tileheight) + 'px'; } var myAnim; function pan(x, y) { if (!myAnim || !myAnim.isAnimated()) { update_tiles(x, y, true, false); myAnim = new YAHOO.util.Motion('drag', { points:{by:[x,y]} }, 10, YAHOO.util.Easing.easeOut); myAnim.useSeconds = false; myAnim.animate(); } } function update_tiles(dx, dy, noMove, force) { if (!dx && !dy && !force) return; var old_drag_x = drag_x; var old_drag_y = drag_y; drag_x += dx; drag_y += dy; if (!noMove) { var drag = document.getElementById('drag'); drag.style.left = drag_x + 'px'; drag.style.top = drag_y + 'px'; } var horizontal = Math.floor(old_drag_x/tilewidth) - Math.floor(drag_x/tilewidth); var vertical = Math.floor(old_drag_y/tileheight) - Math.floor(drag_y/tileheight); if (!horizontal && !vertical && !force) return; for (var j=0; j=0) return m % n; return (m % n) + n; } /* Called every mousemove, so on first call, overwrite itself with quicker version */ function get_posn(ev) { var posx, posy; if (ev.pageX || ev.pageY) { get_posn = function(e) { return { x: e.pageX, y: e.pageY }; }; } else if (ev.clientX || ev.clientY) { get_posn = function(e) { return { x: e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft, y: e.clientY + document.body.scrollTop + document.documentElement.scrollTop }; }; } else { get_posn = function(e) { return { x: undef, y: undef }; }; } return get_posn(ev); } function setCursor(s) { var drag = document.getElementById('drag'); var inputs = drag.getElementsByTagName('input'); for (var i=0; i