mirror of
https://github.com/webbukkit/dynmap.git
synced 2024-12-25 18:17:37 +01:00
Better browser compatiblity
This commit is contained in:
parent
9aaa4c28df
commit
3c7f164823
87
web/map.js
87
web/map.js
@ -202,19 +202,25 @@ function makeRequest(url, func, type, fail, post, contenttype)
|
|||||||
m.setPosition(mi.position);
|
m.setPosition(mi.position);
|
||||||
} else {
|
} else {
|
||||||
var contentfun = function(div,mi) {
|
var contentfun = function(div,mi) {
|
||||||
div.className = 'Marker ' + mi.type + 'Marker';
|
$(div)
|
||||||
div.innerHTML = '<img src="' + mi.type + '.png" /> <span>' + mi.text + '</span>';
|
.addClass('Marker')
|
||||||
|
.addClass(mi.type + 'Marker')
|
||||||
|
.append($('<img/>').attr({src: mi.type + '.png'}))
|
||||||
|
.append($('<span/>').text(mi.text));
|
||||||
};
|
};
|
||||||
if (mi.type == 'player') {
|
if (mi.type == 'player') {
|
||||||
contentfun = function(div, mi) {
|
contentfun = function(div, mi) {
|
||||||
div.className = 'Marker playerMarker';
|
$(div)
|
||||||
var span = document.createElement('span');
|
.addClass('Marker')
|
||||||
span.className = 'playerName';
|
.addClass('playerMarker')
|
||||||
span.appendChild(document.createTextNode(mi.text));
|
.append($('<span/>')
|
||||||
div.appendChild(span);
|
.addClass('playerName')
|
||||||
|
.text(mi.text));
|
||||||
|
|
||||||
getMinecraftHead(mi.text, 32, function(head) {
|
getMinecraftHead(mi.text, 32, function(head) {
|
||||||
head.className = 'playerIcon';
|
$(head)
|
||||||
div.insertBefore(head, div.firstChild);
|
.addClass('playerIcon')
|
||||||
|
.prependTo(div);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -224,38 +230,33 @@ function makeRequest(url, func, type, fail, post, contenttype)
|
|||||||
markers[mi.id] = marker;
|
markers[mi.id] = marker;
|
||||||
|
|
||||||
if (mi.type == 'player') {
|
if (mi.type == 'player') {
|
||||||
var playerRow = document.createElement('div');
|
marker.playerRow = $('<div/>')
|
||||||
playerRow.id = 'playerrow_' + mi.text;
|
.attr({ id: 'playerrow_' + mi.text })
|
||||||
playerRow.className = 'playerrow';
|
.addClass('playerrow')
|
||||||
|
.append(marker.followButton = $('<input/>')
|
||||||
var followButton = document.createElement('input');
|
.attr({ type: 'checkbox',
|
||||||
followButton.type = 'checkbox';
|
name: 'followPlayer',
|
||||||
followButton.name = 'followPlayer';
|
checked: false,
|
||||||
followButton.checked = false;
|
value: mi.text
|
||||||
followButton.value = mi.text;
|
})
|
||||||
marker.followButton = followButton;
|
.addClass('followButton')
|
||||||
followButton.className = 'followButton';
|
.click(function(e) {
|
||||||
followButton.onclick = function(e) {
|
|
||||||
plfollow(mi.id != followPlayer ? mi.id : '');
|
plfollow(mi.id != followPlayer ? mi.id : '');
|
||||||
};
|
}))
|
||||||
playerRow.appendChild(followButton);
|
.append(marker.playerIconContainer = $('<span/>'))
|
||||||
|
.append($('<a/>')
|
||||||
|
.text(mi.text)
|
||||||
|
.attr({ href: '#' })
|
||||||
|
.click(function(e) { map.panTo(markers[mi.id].getPosition()); })
|
||||||
|
);
|
||||||
|
|
||||||
var playerIconContainer = document.createElement('span');
|
|
||||||
playerRow.appendChild(playerIconContainer);
|
|
||||||
getMinecraftHead(mi.text, 16, function(head) {
|
getMinecraftHead(mi.text, 16, function(head) {
|
||||||
head.className = 'playerIcon';
|
marker.playerRow.icon = $(head)
|
||||||
playerRow.icon = head;
|
.addClass('playerIcon')
|
||||||
playerIconContainer.appendChild(head);
|
.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;
|
$('#playerlst').append(marker.playerRow);
|
||||||
var playerlst = document.getElementById('playerlst');
|
|
||||||
playerlst.appendChild(playerRow);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -323,21 +324,23 @@ function makeRequest(url, func, type, fail, post, contenttype)
|
|||||||
}
|
}
|
||||||
|
|
||||||
var time = {
|
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),
|
minutes: parseInt(((servertime / 1000) % 1) * 60),
|
||||||
seconds: parseInt(((((servertime / 1000) % 1) * 60) % 1) * 60)
|
seconds: parseInt(((((servertime / 1000) % 1) * 60) % 1) * 60)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
var clock = document.getElementById('clock');
|
$('#clock')
|
||||||
clock.className = (servertime > 12000 ? 'night' : 'day');
|
.addClass(servertime > 12000 ? 'night' : 'day')
|
||||||
clock.innerText = formatTime(time);
|
.removeClass(servertime > 12000 ? 'day' : 'night')
|
||||||
|
.text(formatTime(time));
|
||||||
|
|
||||||
for(var m in markers) {
|
for(var m in markers) {
|
||||||
if(!(m in loggedin)) {
|
if(!(m in loggedin)) {
|
||||||
markers[m].remove(null);
|
markers[m].remove(null);
|
||||||
if (markers[m].markerType == 'player') {
|
if (markers[m].playerRow) {
|
||||||
playerlst.removeChild(markers[m].playerRow);
|
markers[m].playerRow.remove();
|
||||||
}
|
}
|
||||||
delete markers[m];
|
delete markers[m];
|
||||||
}
|
}
|
||||||
|
@ -7,14 +7,14 @@ var cloneCanvas = function(self) {
|
|||||||
return c;
|
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;
|
var x; var y;
|
||||||
for (x=0;x<dw;x++) {
|
for (x=0;x<dw;x++) {
|
||||||
for (y=0;y<dh;y++) {
|
for (y=0;y<dh;y++) {
|
||||||
this.drawImage(image,Math.floor(sx+x*(sw/dw)),Math.floor(sy+y*(sw/dw)),1,1,dx+x,dy+y,1,1);
|
ctx.drawImage(image,Math.floor(sx+x*(sw/dw)),Math.floor(sy+y*(sw/dw)),1,1,dx+x,dy+y,1,1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
function createMinecraftHead(player,completed) {
|
function createMinecraftHead(player,completed) {
|
||||||
var skinImage = new Image();
|
var skinImage = new Image();
|
||||||
@ -23,8 +23,8 @@ function createMinecraftHead(player,completed) {
|
|||||||
headCanvas.width = 8;
|
headCanvas.width = 8;
|
||||||
headCanvas.height = 8;
|
headCanvas.height = 8;
|
||||||
var headContext = headCanvas.getContext('2d');
|
var headContext = headCanvas.getContext('2d');
|
||||||
headContext.blitImage(skinImage, 8,8,8,8, 0,0,8,8);
|
blitImage(headContext, skinImage, 8,8,8,8, 0,0,8,8);
|
||||||
headContext.blitImage(skinImage, 40,8,8,8, 0,0,8,8);
|
blitImage(headContext, skinImage, 40,8,8,8, 0,0,8,8);
|
||||||
completed(headCanvas);
|
completed(headCanvas);
|
||||||
};
|
};
|
||||||
skinImage.src = 'http://www.minecraft.net/skin/' + player + '.png';
|
skinImage.src = 'http://www.minecraft.net/skin/' + player + '.png';
|
||||||
@ -35,14 +35,14 @@ function resizeImage(img,size) {
|
|||||||
canvas.width = size;
|
canvas.width = size;
|
||||||
canvas.height = size;
|
canvas.height = size;
|
||||||
var ctx = canvas.getContext('2d');
|
var ctx = canvas.getContext('2d');
|
||||||
ctx.blitImage(img, 0,0,img.width,img.height, 0,0,size,size);
|
blitImage(ctx, img, 0,0,img.width,img.height, 0,0,size,size);
|
||||||
return canvas;
|
return canvas;
|
||||||
}
|
}
|
||||||
|
|
||||||
var players = {};
|
var playerHeads = {};
|
||||||
|
|
||||||
function getMinecraftHead(player,size,completed) {
|
function getMinecraftHead(player,size,completed) {
|
||||||
var head = players[player];
|
var head = playerHeads[player];
|
||||||
// Synchronous
|
// Synchronous
|
||||||
if (!completed) {
|
if (!completed) {
|
||||||
return (!head || head.working) ? null : head;
|
return (!head || head.working) ? null : head;
|
||||||
@ -50,12 +50,12 @@ function getMinecraftHead(player,size,completed) {
|
|||||||
|
|
||||||
// Asynchronous
|
// Asynchronous
|
||||||
if (!head) {
|
if (!head) {
|
||||||
players[player] = { working: true, hooks: [{f:completed,s:size}] };
|
playerHeads[player] = { working: true, hooks: [{f:completed,s:size}] };
|
||||||
console.log('Creating head for ',player,'...');
|
console.log('Creating head for ',player,'...');
|
||||||
createMinecraftHead(player, function(head) {
|
createMinecraftHead(player, function(head) {
|
||||||
console.log('Created head for ',player,': ', head);
|
console.log('Created head for ',player,': ', head);
|
||||||
hooks = players[player].hooks;
|
hooks = playerHeads[player].hooks;
|
||||||
players[player] = head;
|
playerHeads[player] = head;
|
||||||
var i;
|
var i;
|
||||||
for(i=0;i<hooks.length;i++) {
|
for(i=0;i<hooks.length;i++) {
|
||||||
hooks[i].f(resizeImage(head,hooks[i].s));
|
hooks[i].f(resizeImage(head,hooks[i].s));
|
||||||
|
Loading…
Reference in New Issue
Block a user