From 3c7f164823d7f77230475b91650530b7d7166fda Mon Sep 17 00:00:00 2001 From: FrozenCow Date: Sat, 1 Jan 2011 19:36:28 +0100 Subject: [PATCH] Better browser compatiblity --- web/map.js | 91 +++++++++++++++++++++++++----------------------- web/minecraft.js | 22 ++++++------ 2 files changed, 58 insertions(+), 55 deletions(-) diff --git a/web/map.js b/web/map.js index e32deb8b..7c631262 100644 --- a/web/map.js +++ b/web/map.js @@ -202,19 +202,25 @@ function makeRequest(url, func, type, fail, post, contenttype) m.setPosition(mi.position); } else { var contentfun = function(div,mi) { - div.className = 'Marker ' + mi.type + 'Marker'; - div.innerHTML = ' ' + mi.text + ''; + $(div) + .addClass('Marker') + .addClass(mi.type + 'Marker') + .append($('').attr({src: mi.type + '.png'})) + .append($('').text(mi.text)); }; if (mi.type == 'player') { contentfun = function(div, mi) { - div.className = 'Marker playerMarker'; - var span = document.createElement('span'); - span.className = 'playerName'; - span.appendChild(document.createTextNode(mi.text)); - div.appendChild(span); + $(div) + .addClass('Marker') + .addClass('playerMarker') + .append($('') + .addClass('playerName') + .text(mi.text)); + getMinecraftHead(mi.text, 32, function(head) { - head.className = 'playerIcon'; - div.insertBefore(head, div.firstChild); + $(head) + .addClass('playerIcon') + .prependTo(div); }); }; } @@ -224,38 +230,33 @@ function makeRequest(url, func, type, fail, post, contenttype) markers[mi.id] = marker; if (mi.type == 'player') { - var playerRow = document.createElement('div'); - playerRow.id = 'playerrow_' + mi.text; - playerRow.className = 'playerrow'; - - var followButton = document.createElement('input'); - followButton.type = 'checkbox'; - followButton.name = 'followPlayer'; - followButton.checked = false; - followButton.value = mi.text; - marker.followButton = followButton; - followButton.className = 'followButton'; - followButton.onclick = function(e) { - plfollow(mi.id != followPlayer ? mi.id : ''); - }; - playerRow.appendChild(followButton); - - var playerIconContainer = document.createElement('span'); - playerRow.appendChild(playerIconContainer); + marker.playerRow = $('
') + .attr({ id: 'playerrow_' + mi.text }) + .addClass('playerrow') + .append(marker.followButton = $('') + .attr({ type: 'checkbox', + name: 'followPlayer', + checked: false, + value: mi.text + }) + .addClass('followButton') + .click(function(e) { + plfollow(mi.id != followPlayer ? mi.id : ''); + })) + .append(marker.playerIconContainer = $('')) + .append($('') + .text(mi.text) + .attr({ href: '#' }) + .click(function(e) { map.panTo(markers[mi.id].getPosition()); }) + ); + getMinecraftHead(mi.text, 16, function(head) { - head.className = 'playerIcon'; - playerRow.icon = head; - playerIconContainer.appendChild(head); + marker.playerRow.icon = $(head) + .addClass('playerIcon') + .appendTo(marker.playerIconContainer); }); - var playerText = document.createElement('a'); - playerText.appendChild(document.createTextNode(mi.text)); - playerText.href = '#'; - playerText.onclick = function(e) { map.panTo(markers[mi.id].getPosition()); }; - playerRow.appendChild(playerText); - marker.playerRow = playerRow; - var playerlst = document.getElementById('playerlst'); - playerlst.appendChild(playerRow); + $('#playerlst').append(marker.playerRow); } } @@ -323,21 +324,23 @@ function makeRequest(url, func, type, fail, post, contenttype) } var time = { - hours: parseInt(servertime / 1000), + // Assuming it is day at 8:00 + hours: (parseInt(servertime / 1000)+8) % 24, minutes: parseInt(((servertime / 1000) % 1) * 60), seconds: parseInt(((((servertime / 1000) % 1) * 60) % 1) * 60) }; - var clock = document.getElementById('clock'); - clock.className = (servertime > 12000 ? 'night' : 'day'); - clock.innerText = formatTime(time); + $('#clock') + .addClass(servertime > 12000 ? 'night' : 'day') + .removeClass(servertime > 12000 ? 'day' : 'night') + .text(formatTime(time)); for(var m in markers) { if(!(m in loggedin)) { markers[m].remove(null); - if (markers[m].markerType == 'player') { - playerlst.removeChild(markers[m].playerRow); + if (markers[m].playerRow) { + markers[m].playerRow.remove(); } delete markers[m]; } diff --git a/web/minecraft.js b/web/minecraft.js index 61b10472..4a1a8eff 100644 --- a/web/minecraft.js +++ b/web/minecraft.js @@ -7,14 +7,14 @@ var cloneCanvas = function(self) { return c; }; -CanvasRenderingContext2D.prototype.blitImage = function(image, sx ,sy, sw, sh, dx, dy, dw, dh) { +function blitImage(ctx, image, sx ,sy, sw, sh, dx, dy, dw, dh) { var x; var y; for (x=0;x