make focus work for element with id == 0; some fixes for map

This commit is contained in:
rlx 2011-03-04 06:00:46 +00:00
parent ee027fb760
commit 925904527e

View file

@ -428,8 +428,10 @@ requires
88: 'x', 88: 'x',
89: 'y', 89: 'y',
90: 'z', 90: 'z',
91: 'meta.left', //91: 'meta.left',
92: 'meta.right', //92: 'meta.right',
91: 'meta',
92: 'meta',
93: 'select', 93: 'select',
96: '0.numpad', 96: '0.numpad',
97: '1.numpad', 97: '1.numpad',
@ -538,7 +540,7 @@ requires
buffer += key == 'SPACE' ? ' ' : key; buffer += key == 'SPACE' ? ' ' : key;
bufferTime = time; bufferTime = time;
} }
focused && $elements[focused].triggerEvent('key_' + key); focused !== null && $elements[focused].triggerEvent('key_' + key);
if (['down', 'space', 'up'].indexOf(key) > -1 && !$elements[focused].hasClass('OxInput')) { if (['down', 'space', 'up'].indexOf(key) > -1 && !$elements[focused].hasClass('OxInput')) {
// prevent chrome from scrolling // prevent chrome from scrolling
return false; return false;
@ -7129,9 +7131,9 @@ requires
} }
function getSelectedIds() { function getSelectedIds() {
Ox.print('gSI', self.selected, self.$items) //Ox.print('gSI', self.selected, self.$items)
return $.map(self.selected, function(pos) { return $.map(self.selected, function(pos) {
Ox.print('....', pos, self.options.unique, self.$items[pos].options('data')[self.options.unique]) //Ox.print('....', pos, self.options.unique, self.$items[pos].options('data')[self.options.unique])
return self.$items[pos].options('data')[self.options.unique]; return self.$items[pos].options('data')[self.options.unique];
}); });
} }
@ -9276,7 +9278,7 @@ requires
} }
function selectPlace(event, data) { function selectPlace(event, data) {
Ox.print('selectPlace', data.id) Ox.print('selectPlace', data, data.id)
data.id[0] != '_' && self.$list.options({ data.id[0] != '_' && self.$list.options({
selected: data.id ? [data.id] : [] selected: data.id ? [data.id] : []
}); });
@ -9339,6 +9341,7 @@ requires
key_down: function() { key_down: function() {
pan(0, 1); pan(0, 1);
}, },
key_l: toggleLabels,
key_left: function() { key_left: function() {
pan(-1, 0); pan(-1, 0);
}, },
@ -9346,19 +9349,28 @@ requires
pan(1, 0); pan(1, 0);
}, },
key_0: reset, key_0: reset,
key_meta: function() {
self.metaKey = true;
$(document).one({
keyup: function() {
self.metaKey = false;
}
});
},
key_minus: function() { key_minus: function() {
zoom(-1); zoom(-1);
}, },
key_equal: function() { key_equal: function() {
zoom(1); zoom(1);
}, },
key_enter: focusOnPlace, key_enter: panToPlace,
key_shift_enter: zoomToPlace, key_shift_enter: zoomToPlace,
key_escape: function() { key_escape: function() {
selectPlace(''); selectPlace('');
} }
}); });
self.metaKey = false;
self.resultPlace = null; self.resultPlace = null;
if (self.options.toolbar) { if (self.options.toolbar) {
@ -9390,7 +9402,7 @@ requires
self.$map = new Ox.Element('div') self.$map = new Ox.Element('div')
.css({ .css({
width: self.options.width + 'px', width: self.options.width + 'px',
height: getMapHeight() height: getMapHeight() + 'px'
}) })
.appendTo(that); .appendTo(that);
@ -9529,12 +9541,6 @@ requires
} }
} }
function focusOnPlace() {
if (self.options.selected > -1) {
self.map.panTo(self.options.places[self.options.selected].center);
}
}
function getPlaceById(id) { function getPlaceById(id) {
var place = Ox.getObjectById(self.places, id); var place = Ox.getObjectById(self.places, id);
if (!place && self.resultPlace && self.resultPlace.id == id) { if (!place && self.resultPlace && self.resultPlace.id == id) {
@ -9597,12 +9603,10 @@ requires
} }
function getMapHeight() { function getMapHeight() {
return ( return self.options.height -
self.options.height -
self.options.statusbar * 24 - self.options.statusbar * 24 -
self.options.toolbar * 24 - self.options.toolbar * 24 -
self.options.zoombar * 16 self.options.zoombar * 16;
) + 'px';
} }
function getMapType() { function getMapType() {
@ -9624,6 +9628,9 @@ requires
self.geocoder = new google.maps.Geocoder(); self.geocoder = new google.maps.Geocoder();
self.places = []; self.places = [];
self.options.places.forEach(function(place, i) { self.options.places.forEach(function(place, i) {
if (Ox.isUndefined(place.id)) {
place.id = Ox.uid();
}
self.places[i] = Place(Ox.clone(place)); self.places[i] = Place(Ox.clone(place));
if (i == 0) { if (i == 0) {
Ox.print('0000', self.places[i].bounds, self.places[i].bounds.union) Ox.print('0000', self.places[i].bounds, self.places[i].bounds.union)
@ -9631,7 +9638,10 @@ requires
Ox.print('$$$$', self.bounds) Ox.print('$$$$', self.bounds)
} }
self.bounds = i == 0 ? self.bounds = i == 0 ?
self.places[i].bounds : new google.maps.LatLngBounds(
new google.maps.LatLng(self.places[i].south, self.places[i].west),
new google.maps.LatLng(self.places[i].north, self.places[i].east)
) :
self.bounds.union(self.places[i].bounds); self.bounds.union(self.places[i].bounds);
}); });
self.center = self.bounds ? self.bounds.getCenter() : new google.maps.LatLng(0, 0); self.center = self.bounds ? self.bounds.getCenter() : new google.maps.LatLng(0, 0);
@ -9639,6 +9649,7 @@ requires
self.map = new google.maps.Map(self.$map.$element[0], { self.map = new google.maps.Map(self.$map.$element[0], {
center: self.center, center: self.center,
disableDefaultUI: true, disableDefaultUI: true,
disableDoubleClickZoom: true,
mapTypeId: google.maps.MapTypeId[getMapType()], mapTypeId: google.maps.MapTypeId[getMapType()],
zoom: self.zoom zoom: self.zoom
}); });
@ -9657,9 +9668,16 @@ requires
} }
function pan(x, y) { function pan(x, y) {
self.map.panBy(x * 256, y * 256); self.map.panBy(x * self.options.width / 2, y * getMapHeight() / 2);
}; };
function panToPlace() {
Ox.print('panToPlace:', self.options.selected)
if (self.options.selected !== null) {
self.map.panTo(getPlaceById(self.options.selected).center);
}
}
function removePlace(id) { function removePlace(id) {
} }
@ -9680,10 +9698,22 @@ requires
place = getPlaceById(id); place = getPlaceById(id);
place && place.select(); place && place.select();
} }
if (id) {
//self.map.setCenter(place.center);
/*
if (
self.map.getBounds().contains(place.bounds.getSouthWest()) &&
self.map.getBounds().contains(place.bounds.getNorthEast())
) {
} else {
self.map.fitBounds(place.bounds);
}
*/
}
self.options.selected = id; self.options.selected = id;
self.selected = id; self.selected = id;
setStatus(); setStatus();
that.triggerEvent('select', place); //that.triggerEvent('select', place);
/* /*
that.triggerEvent('select', { that.triggerEvent('select', {
id: self.options.selected id: self.options.selected
@ -9738,8 +9768,9 @@ requires
} }
function zoomToPlace() { function zoomToPlace() {
if (self.options.selected > -1) { Ox.print('zoomToPlace')
self.map.fitBounds(self.options.places[self.options.selected].bounds); if (self.options.selected !== null) {
self.map.fitBounds(getPlaceById(self.options.selected).bounds);
} }
} }
@ -9748,25 +9779,35 @@ requires
position: place.center, position: place.center,
title: place.name title: place.name
}), }),
selected = false; selected = false,
timeout = 0;
setOptions(); setOptions();
Ox.print('MARKER', marker) Ox.print('MARKER', marker)
function click(event) { function click() {
// fixme: metaKey used to work var metaKey = self.metaKey;
/* timeout = setTimeout(function() {
Ox.print('click event', event, 'metakey', event.metaKey, 'selected', selected) Ox.print('$$$$ CLICK', metaKey, selected)
if (event.metaKey == selected) { if (!selected) {
selected = !event.metaKey; selected = true;
selectPlace(selected ? place.id : ''); selectPlace(place.id);
} } else if (!metaKey) {
*/ panToPlace(place);
selected = !selected; } else {
selectPlace(selected ? place.id : ''); selected = false;
selectPlace(null);
}
}, 250);
Ox.print('$$$$ TIMEOUT')
} }
function dblclick() { function dblclick() {
Ox.print('PLACE.BOUNDS', place.bounds) Ox.print('$$$$ DBLCLICK', timeout)
self.bounds = place.bounds; clearTimeout(timeout);
self.map.fitBounds(self.bounds); if (!selected) {
selected = true;
selectPlace(place.id);
}
self.map.fitBounds(place.bounds);
return false;
} }
function setOptions() { function setOptions() {
marker.setOptions({ marker.setOptions({