mirror of
https://github.com/webbukkit/dynmap.git
synced 2025-01-12 10:50:37 +01:00
Simplified component-creation, dropping IE8 compatibility.
This commit is contained in:
parent
6eface57ae
commit
6622db1b2c
@ -7,39 +7,35 @@ $.ajax({
|
||||
});
|
||||
|
||||
componentconstructors['chat'] = function(dynmap, configuration) {
|
||||
return {
|
||||
dynmap: dynmap,
|
||||
initialize: function() {
|
||||
// Provides 'chat'-events by monitoring the world-updates.
|
||||
$(dynmap).bind('worldupdate', function(event, update) {
|
||||
swtch(update.type, {
|
||||
chat: function() {
|
||||
$(dynmap).trigger('chat', [{source: 'player', name: update.playerName, text: update.message}]);
|
||||
},
|
||||
webchat: function() {
|
||||
$(dynmap).trigger('chat', [{source: 'web', name: update.playerName, text: update.message}]);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
if (dynmap.options.allowwebchat) {
|
||||
// Accepts 'sendchat'-events to send chat messages to the server.
|
||||
$(dynmap).bind('sendchat', function(event, message) {
|
||||
var data = '{"name":"'+ip+'","message":"'+message+'"}';
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: 'up/sendmessage',
|
||||
data: data,
|
||||
dataType: 'json',
|
||||
success: function(response) {
|
||||
//handle response
|
||||
if(response) {
|
||||
$(dynmap).trigger('chat', [{source: 'me', name: ip, text: message}]);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
var me = this;
|
||||
// Provides 'chat'-events by monitoring the world-updates.
|
||||
$(dynmap).bind('worldupdate', function(event, update) {
|
||||
swtch(update.type, {
|
||||
chat: function() {
|
||||
$(dynmap).trigger('chat', [{source: 'player', name: update.playerName, text: update.message}]);
|
||||
},
|
||||
webchat: function() {
|
||||
$(dynmap).trigger('chat', [{source: 'web', name: update.playerName, text: update.message}]);
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
if (dynmap.options.allowwebchat) {
|
||||
// Accepts 'sendchat'-events to send chat messages to the server.
|
||||
$(dynmap).bind('sendchat', function(event, message) {
|
||||
var data = '{"name":"'+ip+'","message":"'+message+'"}';
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: 'up/sendmessage',
|
||||
data: data,
|
||||
dataType: 'json',
|
||||
success: function(response) {
|
||||
//handle response
|
||||
if(response) {
|
||||
$(dynmap).trigger('chat', [{source: 'me', name: ip, text: message}]);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
@ -1,53 +1,47 @@
|
||||
componentconstructors['chatballoon'] = function(dynmap, configuration) {
|
||||
return {
|
||||
dynmap: dynmap,
|
||||
options: configuration,
|
||||
chatpopups: {},
|
||||
initialize: function() {
|
||||
var me = this;
|
||||
$(dynmap).bind('chat', function(event, message) {
|
||||
if (message.source != 'player') {
|
||||
return;
|
||||
}
|
||||
var player = dynmap.players[message.name];
|
||||
var playerMarker = player && player.marker;
|
||||
if (!playerMarker) {
|
||||
return;
|
||||
}
|
||||
var popup = me.chatpopups[message.name];
|
||||
if (!popup) {
|
||||
popup = { lines: [ message.text ] };
|
||||
} else {
|
||||
popup.lines[popup.lines.length] = message.text;
|
||||
}
|
||||
|
||||
var MAX_LINES = 5;
|
||||
if (popup.lines.length > MAX_LINES) {
|
||||
popup.lines = popup.lines.slice(1);
|
||||
}
|
||||
var htmlMessage = '<div id="content"><b>' + message.name + "</b><br/><br/>";
|
||||
var line;
|
||||
for (line in popup.lines) {
|
||||
htmlMessage = htmlMessage + popup.lines[line] + "<br/>";
|
||||
}
|
||||
htmlMessage = htmlMessage + "</div>";
|
||||
if (!popup.infoWindow) {
|
||||
popup.infoWindow = new google.maps.InfoWindow({
|
||||
disableAutoPan: !(me.options.focuschatballoons || false),
|
||||
content: htmlMessage
|
||||
});
|
||||
} else {
|
||||
popup.infoWindow.setContent(htmlMessage);
|
||||
}
|
||||
popup.infoWindow.open(dynmap.map, playerMarker);
|
||||
me.chatpopups[message.name] = popup;
|
||||
if (popup.timeout) { window.clearTimeout(popup.timeout); }
|
||||
popup.timeout = window.setTimeout(function() {
|
||||
popup.infoWindow.close();
|
||||
popup.infoWindow = null;
|
||||
delete me.chatpopups[message.name];
|
||||
}, 8000);
|
||||
});
|
||||
var me = this;
|
||||
me.chatpopups = {};
|
||||
$(dynmap).bind('chat', function(event, message) {
|
||||
if (message.source != 'player') {
|
||||
return;
|
||||
}
|
||||
};
|
||||
var player = dynmap.players[message.name];
|
||||
var playerMarker = player && player.marker;
|
||||
if (!playerMarker) {
|
||||
return;
|
||||
}
|
||||
var popup = me.chatpopups[message.name];
|
||||
if (!popup) {
|
||||
popup = { lines: [ message.text ] };
|
||||
} else {
|
||||
popup.lines[popup.lines.length] = message.text;
|
||||
}
|
||||
|
||||
var MAX_LINES = 5;
|
||||
if (popup.lines.length > MAX_LINES) {
|
||||
popup.lines = popup.lines.slice(1);
|
||||
}
|
||||
var htmlMessage = '<div id="content"><b>' + message.name + "</b><br/><br/>";
|
||||
var line;
|
||||
for (line in popup.lines) {
|
||||
htmlMessage = htmlMessage + popup.lines[line] + "<br/>";
|
||||
}
|
||||
htmlMessage = htmlMessage + "</div>";
|
||||
if (!popup.infoWindow) {
|
||||
popup.infoWindow = new google.maps.InfoWindow({
|
||||
disableAutoPan: !(me.options.focuschatballoons || false),
|
||||
content: htmlMessage
|
||||
});
|
||||
} else {
|
||||
popup.infoWindow.setContent(htmlMessage);
|
||||
}
|
||||
popup.infoWindow.open(dynmap.map, playerMarker);
|
||||
me.chatpopups[message.name] = popup;
|
||||
if (popup.timeout) { window.clearTimeout(popup.timeout); }
|
||||
popup.timeout = window.setTimeout(function() {
|
||||
popup.infoWindow.close();
|
||||
popup.infoWindow = null;
|
||||
delete me.chatpopups[message.name];
|
||||
}, 8000);
|
||||
});
|
||||
};
|
@ -1,74 +1,70 @@
|
||||
componentconstructors['chatbox'] = function(dynmap, configuration) {
|
||||
return {
|
||||
dynmap: dynmap,
|
||||
initialize: function() {
|
||||
var chat = $('<div/>')
|
||||
.addClass('chat')
|
||||
.appendTo(dynmap.options.container);
|
||||
var messagelist = $('<div/>')
|
||||
.addClass('messagelist')
|
||||
.appendTo(chat);
|
||||
|
||||
if (dynmap.options.allowwebchat) {
|
||||
var chatinput = $('<input/>')
|
||||
.addClass('chatinput')
|
||||
.attr({
|
||||
id: 'chatinput',
|
||||
type: 'text',
|
||||
value: ''
|
||||
})
|
||||
.keydown(function(event) {
|
||||
if (event.keyCode == '13') {
|
||||
event.preventDefault();
|
||||
if(chatinput.val() != '') {
|
||||
$(dynmap).trigger('sendchat', [chatinput.val()]);
|
||||
chatinput.val('');
|
||||
}
|
||||
}
|
||||
})
|
||||
.appendTo(chat);
|
||||
}
|
||||
|
||||
$(dynmap).bind('chat', function(event, message) {
|
||||
var playerName = message.name;
|
||||
var messageRow = $('<div/>')
|
||||
.addClass('messagerow');
|
||||
|
||||
var playerIconContainer = $('<span/>')
|
||||
.addClass('messageicon');
|
||||
|
||||
if (message.source === 'player' && configuration.showplayerfaces) {
|
||||
getMinecraftHead(playerName, 16, function(head) {
|
||||
messageRow.icon = $(head)
|
||||
.addClass('playerIcon')
|
||||
.appendTo(playerIconContainer);
|
||||
});
|
||||
var me = this;
|
||||
var chat = $('<div/>')
|
||||
.addClass('chat')
|
||||
.appendTo(dynmap.options.container);
|
||||
var messagelist = $('<div/>')
|
||||
.addClass('messagelist')
|
||||
.appendTo(chat);
|
||||
|
||||
if (dynmap.options.allowwebchat) {
|
||||
var chatinput = $('<input/>')
|
||||
.addClass('chatinput')
|
||||
.attr({
|
||||
id: 'chatinput',
|
||||
type: 'text',
|
||||
value: ''
|
||||
})
|
||||
.keydown(function(event) {
|
||||
if (event.keyCode == '13') {
|
||||
event.preventDefault();
|
||||
if(chatinput.val() != '') {
|
||||
$(dynmap).trigger('sendchat', [chatinput.val()]);
|
||||
chatinput.val('');
|
||||
}
|
||||
}
|
||||
})
|
||||
.appendTo(chat);
|
||||
}
|
||||
|
||||
$(dynmap).bind('chat', function(event, message) {
|
||||
var playerName = message.name;
|
||||
var messageRow = $('<div/>')
|
||||
.addClass('messagerow');
|
||||
|
||||
if (message.source === 'player' && configuration.showworld) {
|
||||
var playerWorldContainer = $('<span/>')
|
||||
.addClass('messagetext')
|
||||
.text('['+dynmap.players[message.name].location.world.name+']')
|
||||
.appendTo(messageRow);
|
||||
}
|
||||
var playerIconContainer = $('<span/>')
|
||||
.addClass('messageicon');
|
||||
|
||||
var playerNameContainer = $('<span/>')
|
||||
.addClass('messagetext')
|
||||
.text(' '+message.name+': ');
|
||||
|
||||
var playerMessageContainer = $('<span/>')
|
||||
.addClass('messagetext')
|
||||
.text(message.text);
|
||||
|
||||
messageRow.append(playerIconContainer,playerNameContainer,playerMessageContainer);
|
||||
//messageRow.append(playerIconContainer,playerWorldContainer,playerGroupContainer,playerNameContainer,playerMessageContainer);
|
||||
setTimeout(function() { messageRow.remove(); }, (configuration.messagettl * 1000));
|
||||
messagelist.append(messageRow);
|
||||
|
||||
messagelist.show();
|
||||
//var scrollHeight = jQuery(me.messagelist).attr('scrollHeight');
|
||||
messagelist.scrollTop(messagelist.scrollHeight());
|
||||
if (message.source === 'player' && configuration.showplayerfaces) {
|
||||
getMinecraftHead(playerName, 16, function(head) {
|
||||
messageRow.icon = $(head)
|
||||
.addClass('playerIcon')
|
||||
.appendTo(playerIconContainer);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
if (message.source === 'player' && configuration.showworld) {
|
||||
var playerWorldContainer = $('<span/>')
|
||||
.addClass('messagetext')
|
||||
.text('['+dynmap.players[message.name].location.world.name+']')
|
||||
.appendTo(messageRow);
|
||||
}
|
||||
|
||||
var playerNameContainer = $('<span/>')
|
||||
.addClass('messagetext')
|
||||
.text(' '+message.name+': ');
|
||||
|
||||
var playerMessageContainer = $('<span/>')
|
||||
.addClass('messagetext')
|
||||
.text(message.text);
|
||||
|
||||
messageRow.append(playerIconContainer,playerNameContainer,playerMessageContainer);
|
||||
//messageRow.append(playerIconContainer,playerWorldContainer,playerGroupContainer,playerNameContainer,playerMessageContainer);
|
||||
setTimeout(function() { messageRow.remove(); }, (configuration.messagettl * 1000));
|
||||
messagelist.append(messageRow);
|
||||
|
||||
messagelist.show();
|
||||
//var scrollHeight = jQuery(me.messagelist).attr('scrollHeight');
|
||||
messagelist.scrollTop(messagelist.scrollHeight());
|
||||
});
|
||||
};
|
@ -280,10 +280,8 @@ DynMap.prototype = {
|
||||
me.selectMap(me.defaultworld.defaultmap);
|
||||
|
||||
$.each(me.options.components, function(index, configuration) {
|
||||
me.components.push(componentconstructors[configuration.type](me, configuration));
|
||||
});
|
||||
$.each(me.components, function(index, component) {
|
||||
component.initialize();
|
||||
var componentconstructor = componentconstructors[configuration.type];
|
||||
me.components.push(new componentconstructor(me, configuration));
|
||||
});
|
||||
|
||||
setTimeout(function() { me.update(); }, me.options.updaterate);
|
||||
|
@ -1,40 +1,37 @@
|
||||
componentconstructors['playermarkers'] = function(dynmap, configuration) {
|
||||
return {
|
||||
initialize: function() {
|
||||
$(dynmap).bind('playeradded', function(event, player) {
|
||||
// Create the player-marker.
|
||||
var markerPosition = dynmap.map.getProjection().fromWorldToLatLng(player.location.x, player.location.y, player.location.z);
|
||||
player.marker = new CustomMarker(markerPosition, dynmap.map, function(div) {
|
||||
var playerImage;
|
||||
$(div)
|
||||
.addClass('Marker')
|
||||
.addClass('playerMarker')
|
||||
.append(playerImage = $('<img/>')
|
||||
.attr({ src: 'images/player.png' }))
|
||||
.append($('<span/>')
|
||||
.addClass('playerName')
|
||||
.text(player.name));
|
||||
|
||||
if (configuration.showplayerfaces) {
|
||||
getMinecraftHead(player.name, 32, function(head) {
|
||||
$(head)
|
||||
.addClass('playericon')
|
||||
.prependTo(div);
|
||||
playerImage.remove();
|
||||
});
|
||||
}
|
||||
var me = this;
|
||||
$(dynmap).bind('playeradded', function(event, player) {
|
||||
// Create the player-marker.
|
||||
var markerPosition = dynmap.map.getProjection().fromWorldToLatLng(player.location.x, player.location.y, player.location.z);
|
||||
player.marker = new CustomMarker(markerPosition, dynmap.map, function(div) {
|
||||
var playerImage;
|
||||
$(div)
|
||||
.addClass('Marker')
|
||||
.addClass('playerMarker')
|
||||
.append(playerImage = $('<img/>')
|
||||
.attr({ src: 'images/player.png' }))
|
||||
.append($('<span/>')
|
||||
.addClass('playerName')
|
||||
.text(player.name));
|
||||
|
||||
if (configuration.showplayerfaces) {
|
||||
getMinecraftHead(player.name, 32, function(head) {
|
||||
$(head)
|
||||
.addClass('playericon')
|
||||
.prependTo(div);
|
||||
playerImage.remove();
|
||||
});
|
||||
});
|
||||
$(dynmap).bind('playerremoved', function(event, player) {
|
||||
// Remove the marker.
|
||||
player.marker.remove();
|
||||
});
|
||||
$(dynmap).bind('playerupdated', function(event, player) {
|
||||
// Update the marker.
|
||||
var markerPosition = dynmap.map.getProjection().fromWorldToLatLng(player.location.x, player.location.y, player.location.z);
|
||||
player.marker.toggle(dynmap.world === player.location.world);
|
||||
player.marker.setPosition(markerPosition);
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
});
|
||||
$(dynmap).bind('playerremoved', function(event, player) {
|
||||
// Remove the marker.
|
||||
player.marker.remove();
|
||||
});
|
||||
$(dynmap).bind('playerupdated', function(event, player) {
|
||||
// Update the marker.
|
||||
var markerPosition = dynmap.map.getProjection().fromWorldToLatLng(player.location.x, player.location.y, player.location.z);
|
||||
player.marker.toggle(dynmap.world === player.location.world);
|
||||
player.marker.setPosition(markerPosition);
|
||||
});
|
||||
};
|
Loading…
Reference in New Issue
Block a user