mirror of
https://github.com/webbukkit/dynmap.git
synced 2024-06-30 16:44:46 +02: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) {
|
componentconstructors['chat'] = function(dynmap, configuration) {
|
||||||
return {
|
var me = this;
|
||||||
dynmap: dynmap,
|
// Provides 'chat'-events by monitoring the world-updates.
|
||||||
initialize: function() {
|
$(dynmap).bind('worldupdate', function(event, update) {
|
||||||
// Provides 'chat'-events by monitoring the world-updates.
|
swtch(update.type, {
|
||||||
$(dynmap).bind('worldupdate', function(event, update) {
|
chat: function() {
|
||||||
swtch(update.type, {
|
$(dynmap).trigger('chat', [{source: 'player', name: update.playerName, text: update.message}]);
|
||||||
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}]);
|
||||||
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}]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
};
|
});
|
||||||
|
|
||||||
|
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) {
|
componentconstructors['chatballoon'] = function(dynmap, configuration) {
|
||||||
return {
|
var me = this;
|
||||||
dynmap: dynmap,
|
me.chatpopups = {};
|
||||||
options: configuration,
|
$(dynmap).bind('chat', function(event, message) {
|
||||||
chatpopups: {},
|
if (message.source != 'player') {
|
||||||
initialize: function() {
|
return;
|
||||||
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 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) {
|
componentconstructors['chatbox'] = function(dynmap, configuration) {
|
||||||
return {
|
var me = this;
|
||||||
dynmap: dynmap,
|
var chat = $('<div/>')
|
||||||
initialize: function() {
|
.addClass('chat')
|
||||||
var chat = $('<div/>')
|
.appendTo(dynmap.options.container);
|
||||||
.addClass('chat')
|
var messagelist = $('<div/>')
|
||||||
.appendTo(dynmap.options.container);
|
.addClass('messagelist')
|
||||||
var messagelist = $('<div/>')
|
.appendTo(chat);
|
||||||
.addClass('messagelist')
|
|
||||||
.appendTo(chat);
|
if (dynmap.options.allowwebchat) {
|
||||||
|
var chatinput = $('<input/>')
|
||||||
if (dynmap.options.allowwebchat) {
|
.addClass('chatinput')
|
||||||
var chatinput = $('<input/>')
|
.attr({
|
||||||
.addClass('chatinput')
|
id: 'chatinput',
|
||||||
.attr({
|
type: 'text',
|
||||||
id: 'chatinput',
|
value: ''
|
||||||
type: 'text',
|
})
|
||||||
value: ''
|
.keydown(function(event) {
|
||||||
})
|
if (event.keyCode == '13') {
|
||||||
.keydown(function(event) {
|
event.preventDefault();
|
||||||
if (event.keyCode == '13') {
|
if(chatinput.val() != '') {
|
||||||
event.preventDefault();
|
$(dynmap).trigger('sendchat', [chatinput.val()]);
|
||||||
if(chatinput.val() != '') {
|
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);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
.appendTo(chat);
|
||||||
|
}
|
||||||
|
|
||||||
|
$(dynmap).bind('chat', function(event, message) {
|
||||||
|
var playerName = message.name;
|
||||||
|
var messageRow = $('<div/>')
|
||||||
|
.addClass('messagerow');
|
||||||
|
|
||||||
if (message.source === 'player' && configuration.showworld) {
|
var playerIconContainer = $('<span/>')
|
||||||
var playerWorldContainer = $('<span/>')
|
.addClass('messageicon');
|
||||||
.addClass('messagetext')
|
|
||||||
.text('['+dynmap.players[message.name].location.world.name+']')
|
|
||||||
.appendTo(messageRow);
|
|
||||||
}
|
|
||||||
|
|
||||||
var playerNameContainer = $('<span/>')
|
if (message.source === 'player' && configuration.showplayerfaces) {
|
||||||
.addClass('messagetext')
|
getMinecraftHead(playerName, 16, function(head) {
|
||||||
.text(' '+message.name+': ');
|
messageRow.icon = $(head)
|
||||||
|
.addClass('playerIcon')
|
||||||
var playerMessageContainer = $('<span/>')
|
.appendTo(playerIconContainer);
|
||||||
.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.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);
|
me.selectMap(me.defaultworld.defaultmap);
|
||||||
|
|
||||||
$.each(me.options.components, function(index, configuration) {
|
$.each(me.options.components, function(index, configuration) {
|
||||||
me.components.push(componentconstructors[configuration.type](me, configuration));
|
var componentconstructor = componentconstructors[configuration.type];
|
||||||
});
|
me.components.push(new componentconstructor(me, configuration));
|
||||||
$.each(me.components, function(index, component) {
|
|
||||||
component.initialize();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
setTimeout(function() { me.update(); }, me.options.updaterate);
|
setTimeout(function() { me.update(); }, me.options.updaterate);
|
||||||
|
|
|
@ -1,40 +1,37 @@
|
||||||
componentconstructors['playermarkers'] = function(dynmap, configuration) {
|
componentconstructors['playermarkers'] = function(dynmap, configuration) {
|
||||||
return {
|
var me = this;
|
||||||
initialize: function() {
|
$(dynmap).bind('playeradded', function(event, player) {
|
||||||
$(dynmap).bind('playeradded', function(event, player) {
|
// Create the player-marker.
|
||||||
// Create the player-marker.
|
var markerPosition = dynmap.map.getProjection().fromWorldToLatLng(player.location.x, player.location.y, player.location.z);
|
||||||
var markerPosition = dynmap.map.getProjection().fromWorldToLatLng(player.location.x, player.location.y, player.location.z);
|
player.marker = new CustomMarker(markerPosition, dynmap.map, function(div) {
|
||||||
player.marker = new CustomMarker(markerPosition, dynmap.map, function(div) {
|
var playerImage;
|
||||||
var playerImage;
|
$(div)
|
||||||
$(div)
|
.addClass('Marker')
|
||||||
.addClass('Marker')
|
.addClass('playerMarker')
|
||||||
.addClass('playerMarker')
|
.append(playerImage = $('<img/>')
|
||||||
.append(playerImage = $('<img/>')
|
.attr({ src: 'images/player.png' }))
|
||||||
.attr({ src: 'images/player.png' }))
|
.append($('<span/>')
|
||||||
.append($('<span/>')
|
.addClass('playerName')
|
||||||
.addClass('playerName')
|
.text(player.name));
|
||||||
.text(player.name));
|
|
||||||
|
if (configuration.showplayerfaces) {
|
||||||
if (configuration.showplayerfaces) {
|
getMinecraftHead(player.name, 32, function(head) {
|
||||||
getMinecraftHead(player.name, 32, function(head) {
|
$(head)
|
||||||
$(head)
|
.addClass('playericon')
|
||||||
.addClass('playericon')
|
.prependTo(div);
|
||||||
.prependTo(div);
|
playerImage.remove();
|
||||||
playerImage.remove();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
$(dynmap).bind('playerremoved', function(event, player) {
|
});
|
||||||
// Remove the marker.
|
});
|
||||||
player.marker.remove();
|
$(dynmap).bind('playerremoved', function(event, player) {
|
||||||
});
|
// Remove the marker.
|
||||||
$(dynmap).bind('playerupdated', function(event, player) {
|
player.marker.remove();
|
||||||
// Update the marker.
|
});
|
||||||
var markerPosition = dynmap.map.getProjection().fromWorldToLatLng(player.location.x, player.location.y, player.location.z);
|
$(dynmap).bind('playerupdated', function(event, player) {
|
||||||
player.marker.toggle(dynmap.world === player.location.world);
|
// Update the marker.
|
||||||
player.marker.setPosition(markerPosition);
|
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