makeArray -> toArray

This commit is contained in:
rlx 2011-02-22 18:52:26 +00:00
parent 2f457f6ad0
commit 4326c307b4
4 changed files with 12598 additions and 11736 deletions

View file

@ -185,7 +185,7 @@ Ox.COUNTRIES = [
{code: 'TG', continent: 'Africa', name: 'Togo', region: 'Western Africa', type: 'sovereign'}, {code: 'TG', continent: 'Africa', name: 'Togo', region: 'Western Africa', type: 'sovereign'},
{code: 'TO', continent: 'Oceania', name: 'Tonga', region: 'Polynesia', type: 'sovereign'}, {code: 'TO', continent: 'Oceania', name: 'Tonga', region: 'Polynesia', type: 'sovereign'},
{code: 'TT', continent: 'North America', name: 'Trinidad and Tobago', region: 'Carribean', type: 'sovereign'}, {code: 'TT', continent: 'North America', name: 'Trinidad and Tobago', region: 'Carribean', type: 'sovereign'},
{code: 'TN', continent: 'Africa', name: 'Tunisia', type: 'sovereign'}, {code: 'TN', continent: 'Africa', name: 'Tunisia', region: 'Northern Africa', type: 'sovereign'},
{code: 'TR', continent: 'Asia', name: 'Turkey', region: 'Western Asia', type: 'sovereign'}, {code: 'TR', continent: 'Asia', name: 'Turkey', region: 'Western Asia', type: 'sovereign'},
{code: 'TM', continent: 'Asia', name: 'Turkmenistan', region: 'Central Asia', type: 'sovereign'}, {code: 'TM', continent: 'Asia', name: 'Turkmenistan', region: 'Central Asia', type: 'sovereign'},
{code: 'TV', continent: 'Oceania', name: 'Tuvalu', region: 'Polynesia', type: 'sovereign'}, {code: 'TV', continent: 'Oceania', name: 'Tuvalu', region: 'Polynesia', type: 'sovereign'},
@ -231,7 +231,7 @@ Ox.COUNTRIES = [
{code: 'MQ', continent: 'North America', country: 'France', name: 'Martinique', region: 'Carribean', type: 'dependent'}, {code: 'MQ', continent: 'North America', country: 'France', name: 'Martinique', region: 'Carribean', type: 'dependent'},
{code: 'YT', continent: 'Africa', country: 'France', name: 'Mayotte', region: 'Eastern Africa', type: 'dependent'}, {code: 'YT', continent: 'Africa', country: 'France', name: 'Mayotte', region: 'Eastern Africa', type: 'dependent'},
{code: 'NC', continent: 'Oceania', country: 'France', name: 'New Caledonia', region: 'Melanesia', type: 'dependent'}, {code: 'NC', continent: 'Oceania', country: 'France', name: 'New Caledonia', region: 'Melanesia', type: 'dependent'},
{code: 'RE', continent: 'Africa', country: 'France', name: 'Réunion', region: 'Eastern Africa', type: 'dependent'}, {code: 'RE', continent: 'Africa', country: 'France', name: 'Réunion', region: 'Eastern Africa', type: 'dependent', flag: 'png'},
{code: 'BL', continent: 'North America', country: 'France', name: 'Saint Barthélemy', region: 'Carribean', type: 'dependent'}, {code: 'BL', continent: 'North America', country: 'France', name: 'Saint Barthélemy', region: 'Carribean', type: 'dependent'},
{code: 'MF', continent: 'North America', country: 'France', name: 'Saint Martin', region: 'Carribean', type: 'dependent'}, {code: 'MF', continent: 'North America', country: 'France', name: 'Saint Martin', region: 'Carribean', type: 'dependent'},
{code: 'PM', continent: 'North America', country: 'France', name: 'Saint Pierre and Miquelon', region: 'Northern America', type: 'dependent'}, {code: 'PM', continent: 'North America', country: 'France', name: 'Saint Pierre and Miquelon', region: 'Northern America', type: 'dependent'},
@ -281,7 +281,7 @@ Ox.COUNTRIES = [
{code: 'CSHH', continent: 'Europe', name: 'Czechoslovakia', region: 'Eastern Europe', type: 'former'}, {code: 'CSHH', continent: 'Europe', name: 'Czechoslovakia', region: 'Eastern Europe', type: 'former'},
{code: 'DYBJ', continent: 'Africa', name: 'Dahomey', region: 'Western Africa', type: 'former'}, {code: 'DYBJ', continent: 'Africa', name: 'Dahomey', region: 'Western Africa', type: 'former'},
{code: 'TPTL', continent: 'Asia', name: 'East Timor', region: 'South-Eastern Asia', type: 'former'}, {code: 'TPTL', continent: 'Asia', name: 'East Timor', region: 'South-Eastern Asia', type: 'former'},
{code: 'DDDE', continent: 'Europe', name: 'East Germany', region: 'Western Europe', type: 'former'}, {code: 'DDDE', continent: 'Europe', name: 'East Germany', region: 'Eastern Europe', type: 'former'},
{code: 'GEHH', name: 'Gilbert and Ellice Islands', type: 'former'}, {code: 'GEHH', name: 'Gilbert and Ellice Islands', type: 'former'},
{code: 'KOHH', continent: 'Asia', name: 'Korea', region: 'Eastern Asia', type: 'former'}, {code: 'KOHH', continent: 'Asia', name: 'Korea', region: 'Eastern Asia', type: 'former'},
{code: 'NTHH', continent: 'Asia', name: 'Neutral Zone', region: 'Western Asia', type: 'former'}, {code: 'NTHH', continent: 'Asia', name: 'Neutral Zone', region: 'Western Asia', type: 'former'},
@ -293,10 +293,10 @@ Ox.COUNTRIES = [
{code: 'YDYE', continent: 'Asia', name: 'South Yemen', region: 'Western Asia', type: 'former'}, {code: 'YDYE', continent: 'Asia', name: 'South Yemen', region: 'Western Asia', type: 'former'},
{code: 'SUHH', continent: 'Europe', name: 'Soviet Union', region: 'Eastern Europe', type: 'former'}, {code: 'SUHH', continent: 'Europe', name: 'Soviet Union', region: 'Eastern Europe', type: 'former'},
{code: 'HVBF', continent: 'Africa', name: 'Upper Volta', region: 'Western Africa', type: 'former'}, {code: 'HVBF', continent: 'Africa', name: 'Upper Volta', region: 'Western Africa', type: 'former'},
{code: 'DE', continent: 'Europe', name: 'West Germany', region: 'Western Europe', type: 'former'}, {code: 'DEDE', continent: 'Europe', name: 'West Germany', region: 'Western Europe', type: 'former'},
{code: 'YUCS', continent: 'Europe', name: 'Yugoslavia', type: 'former'}, {code: 'YUCS', continent: 'Europe', name: 'Yugoslavia', region: 'Southern Europe', type: 'former'},
{code: 'ZRCD', continent: 'Africa', name: 'Zaire', region: 'Middle Africa', type: 'former'}, {code: 'ZRCD', continent: 'Africa', name: 'Zaire', region: 'Middle Africa', type: 'former'},
{code: 'AIDJ', country: 'France',name: 'French Afar and Issas', type: 'former'}, {code: 'AIDJ', continent: 'Africa', country: 'France', name: 'French Afar and Issas', region: 'Eastern Africa', type: 'former'},
{code: 'FQHH', continent: 'Antarctica', country: 'France', name: 'French Southern and Antarctic Territories', type: 'former'}, {code: 'FQHH', continent: 'Antarctica', country: 'France', name: 'French Southern and Antarctic Territories', type: 'former'},
{code: 'FXFR', continent: 'Europe', country: 'France', name: 'Metropolitan France', type: 'former'}, {code: 'FXFR', continent: 'Europe', country: 'France', name: 'Metropolitan France', type: 'former'},
{code: 'NHVU', country: ['France', 'United Kingdom'], name: 'New Hebrides', region: 'Melanesia', type: 'former'}, {code: 'NHVU', country: ['France', 'United Kingdom'], name: 'New Hebrides', region: 'Melanesia', type: 'former'},
@ -306,9 +306,9 @@ Ox.COUNTRIES = [
{code: 'JTUM', continent: 'Oceania', country: 'United States', name: 'Johnston Island', region: 'Mictonesia', type: 'former'}, {code: 'JTUM', continent: 'Oceania', country: 'United States', name: 'Johnston Island', region: 'Mictonesia', type: 'former'},
{code: 'MIUM', continent: 'Oceania', country: 'United States', name: 'Midway Islands', type: 'former'}, {code: 'MIUM', continent: 'Oceania', country: 'United States', name: 'Midway Islands', type: 'former'},
{code: 'PCHH', continent: 'Oceania', country: 'United States', name: 'Pacific Islands', region: 'Micronesia', type: 'former'}, {code: 'PCHH', continent: 'Oceania', country: 'United States', name: 'Pacific Islands', region: 'Micronesia', type: 'former'},
{code: 'PZPA', continent: 'North America', country: 'United States', name: 'Panama Canal Zone', region: 'Central America', type: 'former'}, {code: 'PZPA', continent: 'North America', country: 'United States', name: 'Panama Canal Zone', region: 'Central America', type: 'former', flag: 'png'},
{code: 'PUUM', continent: 'Oceania', country: 'United States', name: 'United States Miscellaneous Pacific Islands', type: 'former'}, {code: 'PUUM', continent: 'Oceania', country: 'United States', name: 'United States Miscellaneous Pacific Islands', type: 'former'},
{code: 'WKUM', continent: 'Oceania', country: 'United States', name: 'Wake Island', region: 'Micronesia', type: 'former'} {code: 'WKUM', continent: 'Oceania', country: 'United States', name: 'Wake Island', region: 'Micronesia', type: 'former'},
{code: 'EU', continent: 'Europe', name: 'European Union', type: 'other'}, {code: 'EU', continent: 'Europe', name: 'European Union', type: 'other'},
{code: 'UK', continent: 'Europe', name: 'United Kingdom', region: 'Northern Europe', type: 'other'} {code: 'UK', continent: 'Europe', name: 'United Kingdom', region: 'Northern Europe', type: 'other'}
]; ];

View file

@ -7970,12 +7970,13 @@ requires
columnsVisible: false, columnsVisible: false,
columnWidth: [40, 800], columnWidth: [40, 800],
id: '', id: '',
items: null,
max: -1, max: -1,
min: 0, min: 0,
pageLength: 100, pageLength: 100,
scrollbarVisible: false, scrollbarVisible: false,
selected: [], selected: [],
request: function() {}, // {sort, range, keys, callback} request: null, // function() {} {sort, range, keys, callback}
sort: [] sort: []
}) })
.options(options || {}) .options(options || {})
@ -8079,6 +8080,7 @@ requires
that.$body = new Ox.List({ that.$body = new Ox.List({
construct: constructItem, construct: constructItem,
id: self.options.id, id: self.options.id,
items: self.options.items,
itemHeight: 16, itemHeight: 16,
itemWidth: getItemWidth(), itemWidth: getItemWidth(),
format: self.format, // fixme: not needed, happens in TextList format: self.format, // fixme: not needed, happens in TextList
@ -8844,10 +8846,19 @@ requires
that = new Ox.Element('div', self) that = new Ox.Element('div', self)
.defaults({ .defaults({
clickable: false, clickable: false,
height: 256,
labels: false,
places: [], places: [],
type: 'satellite' statusbar: false,
toolbar: false,
width: 256,
zoombar: false
}) })
.options(options || {}) .options(options || {})
.css({
width: self.options.width + 'px',
height: self.options.height + 'px'
})
.bindEvent({ .bindEvent({
key_up: function() { key_up: function() {
pan(0, -1); pan(0, -1);
@ -8873,16 +8884,76 @@ requires
key_escape: deselectPlace key_escape: deselectPlace
}); });
if (Ox.isUndefined(window.google)) { if (self.options.toolbar) {
window.google = function() {}; self.$toolbar = new Ox.Bar({
$.getScript('http://maps.google.com/maps/api/js?callback=google&sensor=false', function() { size: 24
var interval = setInterval(function() { })
if (!Ox.isUndefined(google.maps)) { .appendTo(that);
clearInterval(interval); self.$labelsButton = new Ox.Button({
initMap(); title: 'Show Labels',
width: 80
})
.css({float: 'left', margin: '4px'})
.bindEvent({
click: toggleLabels
})
.appendTo(self.$toolbar)
self.$findInput = new Ox.Input({
clear: true,
placeholder: 'Find on Map',
width: 192
})
.css({float: 'right', margin: '4px'})
.bindEvent({
submit: submitFind
})
.appendTo(self.$toolbar)
} }
}, 100); self.$map = new Ox.Element('div')
}); .css({
width: self.options.width + 'px',
height: (
self.options.height -
self.options.statusbar * 16 -
self.options.toolbar * 24 -
self.options.zoombar * 16
) + 'px'
})
.appendTo(that);
if (self.options.zoombar) {
self.$zoombar = new Ox.Bar({
size: 16
})
.appendTo(that);
self.$zoomInput = new Ox.Range({
arrows: true,
max: 22,
size: self.options.width,
thumbSize: 32,
thumbValue: true
})
.bindEvent({
change: changeZoom
})
.appendTo(self.$zoombar)
}
if (self.options.statusbar) {
self.$statusbar = new Ox.Bar({
size: 16
})
.appendTo(that);
self.$status = new Ox.Element()
.css({float: 'right', margin: '2px 4px'})
.appendTo(self.$statusbar);
}
if (Ox.isUndefined(window.google)) {
googleCallback = function() {
Ox.print('googleCallback')
delete googleCallback;
initMap();
};
$.getScript('http://maps.google.com/maps/api/js?callback=googleCallback&sensor=false');
} else { } else {
initMap(); initMap();
} }
@ -8892,46 +8963,17 @@ requires
geocoder: new google.maps.Geocoder(), geocoder: new google.maps.Geocoder(),
selected: -1 selected: -1
}); });
if (self.options.places.length == 0 || Ox.isObject(self.options.places[0])) { loadPlaces(loadMap);
$.each(self.options.places, function(i, place) {
place.bounds = getBounds(),
place.center = place.bounds.getCenter();
$.extend(place, {
marker: new Marker(place),
polygon: new Polygon(place)
});
self.bounds = i == 0 ? getBounds() : self.bounds.union(place.bounds);
self.options.places[i] = place;
function getBounds() {
return new google.maps.LatLngBounds(
new google.maps.LatLng(place.points.southwest[0], place.points.southwest[1]),
new google.maps.LatLng(place.points.northeast[0], place.points.northeast[1])
);
}
});
loadMap();
} else {
self.counter = 0;
$.each(self.options.places, function(i, place) {
getLocationByName(place, function(place) {
//Ox.print(self.counter, i, place);
self.options.places[i] = place;
if (self.counter++ == self.options.places.length - 1) {
loadMap();
}
});
});
}
} }
function loadMap() { function loadMap() {
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);
self.zoom = 1; self.zoom = 1;
$.extend(self, { $.extend(self, {
map: new google.maps.Map(that.$element[0], { map: new google.maps.Map(self.$map.$element[0], {
center: self.center, center: self.center,
disableDefaultUI: true, disableDefaultUI: true,
mapTypeId: google.maps.MapTypeId[self.options.type.toUpperCase()], mapTypeId: google.maps.MapTypeId[getMapType()],
zoom: self.zoom zoom: self.zoom
}) })
}); });
@ -8950,6 +8992,40 @@ requires
that.triggerEvent('loaded'); that.triggerEvent('loaded');
} }
function loadPlaces(callback) {
if (self.options.places.length == 0 || Ox.isObject(self.options.places[0])) {
$.each(self.options.places, function(i, place) {
place.bounds = getBounds(),
place.center = place.bounds.getCenter();
$.extend(place, {
marker: new Marker(place),
polygon: new Polygon(place)
});
self.bounds = i == 0 ? getBounds() : self.bounds.union(place.bounds);
self.options.places[i] = place;
function getBounds() {
return new google.maps.LatLngBounds(
new google.maps.LatLng(place.points.southwest[0], place.points.southwest[1]),
new google.maps.LatLng(place.points.northeast[0], place.points.northeast[1])
);
}
});
callback && callback();
} else {
self.counter = 0;
$.each(self.options.places, function(i, place) {
getLocationByName(place, function(place) {
//Ox.print(self.counter, i, place);
self.options.places[i] = place;
if (self.counter++ == self.options.places.length - 1) {
callback && callback();
}
});
});
}
}
function canContain(outerBounds, innerBounds) { function canContain(outerBounds, innerBounds) {
var outerSpan = outerBounds.toSpan(), var outerSpan = outerBounds.toSpan(),
innerSpan = innerBounds.toSpan(); innerSpan = innerBounds.toSpan();
@ -8957,6 +9033,10 @@ requires
outerSpan.lng() > innerSpan.lng(); outerSpan.lng() > innerSpan.lng();
} }
function changeZoom(event, data) {
self.map.setZoom(data.value);
}
function click(event) { function click(event) {
//Ox.print('event', event); //Ox.print('event', event);
that.gainFocus(); that.gainFocus();
@ -8978,6 +9058,12 @@ requires
} }
function submitFind(event, data) {
that.find(data.value, function(data) {
self.options.statusbar && self.$status.html(data.geoname);
});
}
function focusOnPlace() { function focusOnPlace() {
if (self.selected > -1) { if (self.selected > -1) {
self.map.panTo(self.options.places[self.selected].center); self.map.panTo(self.options.places[self.selected].center);
@ -9029,12 +9115,16 @@ requires
callback(null); callback(null);
} }
} else { } else {
//Ox.print('geocode failed:', status); Ox.print('geocode failed:', status);
callback(null); callback(null);
} }
}); });
} }
function getMapType() {
return self.options.labels ? 'HYBRID' : 'SATELLITE'
}
function getPositionByName(name) { function getPositionByName(name) {
var position = -1; var position = -1;
$.each(self.options.places, function(i, place) { $.each(self.options.places, function(i, place) {
@ -9061,9 +9151,12 @@ requires
self.map.fitBounds(self.bounds); self.map.fitBounds(self.bounds);
} }
function zoomChanged() { function toggleLabels() {
that.triggerEvent('zoom', { self.options.labels = !self.options.labels
value: self.map.getZoom() self.map.setMapTypeId(google.maps.MapTypeId[getMapType()]);
self.$labelsButton.options({
title: self.$labelsButton.options('title') == 'Show Labels' ?
'Hide Labels' : 'Show Labels'
}); });
} }
@ -9071,6 +9164,14 @@ requires
self.map.setZoom(self.map.getZoom() + z); self.map.setZoom(self.map.getZoom() + z);
} }
function zoomChanged() {
var zoom = self.map.getZoom();
self.options.zoombar && self.$zoomInput.options({value: zoom});
that.triggerEvent('zoom', {
value: zoom
});
}
function zoomToPlace() { function zoomToPlace() {
if (self.selected > -1) { if (self.selected > -1) {
self.map.fitBounds(self.options.places[self.selected].bounds); self.map.fitBounds(self.options.places[self.selected].bounds);
@ -9263,7 +9364,9 @@ requires
} }
self.onChange = function(key, value) { self.onChange = function(key, value) {
if (key == 'type') { if (key == 'places') {
loadPlaces(loadMap);
} else if (key == 'type') {
} }
}; };
@ -10259,7 +10362,7 @@ requires
}) })
.options($.extend(options, { .options($.extend(options, {
keyboard: parseKeyboard(options.keyboard || self.defaults.keyboard), keyboard: parseKeyboard(options.keyboard || self.defaults.keyboard),
title: Ox.makeArray(options.title || self.defaults.title) title: Ox.toArray(options.title || self.defaults.title)
})) }))
.addClass('OxItem' + (self.options.disabled ? ' OxDisabled' : '')) .addClass('OxItem' + (self.options.disabled ? ' OxDisabled' : ''))
/* /*
@ -10274,6 +10377,7 @@ requires
} }
// construct // construct
Ox.print('@@@@', self.options.title[0])
that.append( that.append(
that.$status = $('<td>', { that.$status = $('<td>', {
'class': 'OxCell OxStatus', 'class': 'OxCell OxStatus',
@ -10328,7 +10432,7 @@ requires
} else if (key == 'disabled') { } else if (key == 'disabled') {
that.toggleClass('OxDisabled'); // fixme: this will only work if onChange is only invoked on actual change that.toggleClass('OxDisabled'); // fixme: this will only work if onChange is only invoked on actual change
} else if (key == 'title') { } else if (key == 'title') {
self.options.title = Ox.makeArray(value); self.options.title = Ox.toArray(value);
that.$title.html(self.options.title[0]); that.$title.html(self.options.title[0]);
} }
} }

File diff suppressed because it is too large Load diff

View file

@ -63,6 +63,7 @@
<script src="../../build/js/ox.js"></script> <script src="../../build/js/ox.js"></script>
<script src="../../build/js/ox.data.js"></script> <script src="../../build/js/ox.data.js"></script>
<script src="../../build/js/ox.geo.js"></script> <script src="../../build/js/ox.geo.js"></script>
<script src="../../build/js/ox.map.js"></script>
<script src="http://maps.google.com/maps/api/js?sensor=false"></script> <script src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script> <script>
$(function() { $(function() {
@ -79,41 +80,31 @@
}) })
.appendTo($body), .appendTo($body),
aliases = { aliases = {
"Ascension Island": "Ascension Island, Saint Helena", 'Byelorussian Soviet Socialist Republic': 'Belarus',
"England": "England, United Kingdom",
"Georgia": "Georgia, Europe", "Georgia": "Georgia, Europe",
"Holy See": "Vatican City",
// "Palestine": ["West Bank", "Gaza Strip"], // "Palestine": ["West Bank", "Gaza Strip"],
"Palestine": "West Bank",
"Saint Martin": "Sint Maarten",
"Scotland": "Scotland, United Kingdom",
"Svalbard and Jan Mayen": "Svalbard",
"Wales": "Wales, United Kingdom",
"Yugoslavia": "Serbia" "Yugoslavia": "Serbia"
}, },
json = {}; json = {};
///* ///*
$.getJSON("geo.json", function(data) { $.getJSON("geo.json", function(data) {
json = data; json = data;
getPlacemarks($.map(Ox.getCountries(true), function(v) { getPlacemarks(Ox.COUNTRIES);
return v.code.length == 2 ? v : null;
}));
}); });
//*/ //*/
/* /*
getPlacemarks($.map(Ox.getCountries(true), function(v) { getPlacemarks(Ox.COUNTRIES);
return v.code.length == 2 ? v : null;
}));
*/ */
function getPlacemarks(countries) { function getPlacemarks(countries) {
var country = countries.shift(); var country = countries.shift();
if (!(country.code in json)) { if (!(country.code in json)) {
console.log(country); console.log(country);
Ox.getPlacemarks(aliases[country.name] || country.name, function(geodata) { Ox.getPlacemarks(aliases[country.name] || country.name, function(geodata) {
if (!geodata.results) { if (!geodata.results.length) {
console.log(country.name, geodata.status); console.log(country.name, geodata.status);
} } else {
geodata = geodata.results[0]; geodata = geodata.results[0];
Ox.print('geodata', geodata)
data = { data = {
address: aliases[country.name] || country.name, address: aliases[country.name] || country.name,
geocode: { geocode: {
@ -154,6 +145,7 @@
if (country.name != geodata.formatted_address) { if (country.name != geodata.formatted_address) {
console.log(country.name, geodata.formatted_address, geodata); console.log(country.name, geodata.formatted_address, geodata);
} }
}
if (countries.length) { if (countries.length) {
setTimeout(function() { setTimeout(function() {
getPlacemarks(countries); getPlacemarks(countries);
@ -228,8 +220,8 @@
} }
$("<img/>") $("<img/>")
.attr({ .attr({
src: "../../tools/flags/png/16/" + (country.flag.indexOf("-") == 2 ? src: '/static/oxjs/build/svg/' + country.code + '.' +
country.flag.substr(0, 2) + "/" : "") + country.flag + ".png", (country.flag == 'png' ? 'png' : 'svg'),
title: country.name + " ((" + bounds.southWest.lat + ", " + bounds.southWest.lng + "), (" + bounds.northEast.lat + ", " + bounds.northEast.lng + "))" title: country.name + " ((" + bounds.southWest.lat + ", " + bounds.southWest.lng + "), (" + bounds.northEast.lat + ", " + bounds.northEast.lng + "))"
}) })
.addClass("flag") .addClass("flag")