"use strict"; //if (!console) console = { log: function() {} }; var maptypes = {}; var clocks = {}; function splitArgs(s) { var r = s.split(' '); delete arguments[0]; var obj = {}; var index = 0; $.each(arguments, function(argumentIndex, argument) { if (!argumentIndex) { return; } var value = r[argumentIndex-1]; obj[argument] = value; }); return obj; } function swtch(value, options, defaultOption) { return (options[value] || defaultOption)(value); } (function( $ ){ $.fn.scrollHeight = function(height) { return this[0].scrollHeight; }; })($); function DynMapType() { } DynMapType.prototype = { onTileUpdated: function(tile, tileName) { var src = this.dynmap.getTileUrl(tileName); tile.attr('src', src); tile.show(); }, updateTileSize: function(zoom) {} }; function Location(world, x, y, z) { this.world = world; this.x = x; this.y = y; this.z = z; } function DynMap(options) { var me = this; me.options = options; $.getJSON(me.options.updateUrl + 'configuration', function(configuration) { me.configure(configuration); me.initialize(); }, function(status, statusMessage) { alert('Could not retrieve configuration: ' + statusMessage); }); } DynMap.prototype = { worlds: {}, registeredTiles: [], players: {}, chatPopups: [], lasttimestamp: '0', followingPlayer: '', configure: function(configuration) { var me = this; $.extend(me.options, configuration); $.each(me.options.worlds, function(index, worldentry) { var world = me.worlds[worldentry.name] = $.extend({}, worldentry, { maps: {} }); $.each(worldentry.maps, function(index, mapentry) { var map = $.extend({}, mapentry, { world: world, dynmap: me }); map = world.maps[mapentry.name] = maptypes[mapentry.type](map); world.defaultmap = world.defaultmap || map; }); me.defaultworld = me.defaultworld || world; }); }, initialize: function() { var me = this; var container = $(me.options.container); container.addClass('dynmap'); var mapContainer; (mapContainer = $('
')) .addClass('map') .appendTo(container); var map = this.map = new google.maps.Map(mapContainer.get(0), { zoom: 1, center: new google.maps.LatLng(0, 1), navigationControl: true, navigationControlOptions: { style: google.maps.NavigationControlStyle.DEFAULT }, scaleControl: false, mapTypeControl: false, streetViewControl: false, backgroundColor: 'none' }); map.zoom_changed = function() { me.maptype.updateTileSize(me.map.zoom); }; google.maps.event.addListener(map, 'dragstart', function(mEvent) { me.followPlayer(null); }); // TODO: Enable hash-links. /*google.maps.event.addListener(map, 'zoom_changed', function() { me.updateLink(); }); google.maps.event.addListener(map, 'center_changed', function() { me.updateLink(); });*/ // Sidebar var sidebar = me.sidebar = $('
') .addClass('sidebar') .appendTo(container); var panel = $('
') .addClass('panel') .appendTo(sidebar); // Pin button. var pinbutton = $('
') .addClass('pin') .click(function() { sidebar.toggleClass('pinned'); }) .appendTo(panel); // Worlds var worldlist; $('
') .append($('').text('Map Types')) .append(me.worldlist = worldlist = $('