1
0
Fork 0
forked from 0x2620/oxjs

don't loop through all jQuery functions on every Ox.Element creation

This commit is contained in:
rolux 2011-04-19 11:09:51 +02:00
commit 9a61861bf5
4 changed files with 2757 additions and 518 deletions

View file

@ -1,14 +1,51 @@
import json
import os
import simplejson
def read_file(file):
print 'reading', file
f = open(file)
data = f.read()
f.close()
return data
def write_file(file, data):
print 'writing', file
write_path(file)
f = open(file, 'w')
f.write(data)
f.close()
return len(data)
def write_path(file):
path = os.path.split(file)[0]
if path and not os.path.exists(path):
os.makedirs(path)
build_path = '../../build/'
# SVG
path = '../../source/svg/symbols/'
for dirname, dirnames, filenames in os.walk(path):
for filename in filenames:
if filename[0] != '.' and filename[0] != '_':
svg = read_file(path + filename)
new_filename = 'symbol' + filename[0].upper() + filename[1:]
write_file(build_path + 'svg/ox.ui.classic/' + new_filename, svg)
write_file(build_path + 'svg/ox.ui.modern/' + new_filename, svg.replace('#404040', '#FFFFFF').replace('#000000', '#FFFFFF'))
# JSON
images = []
path = '../../build/'
for dirname, dirnames, filenames in os.walk(path + 'png'):
for dirname, dirnames, filenames in os.walk(build_path + 'png'):
for filename in filenames:
if filename[:1] != '.':
images.append(os.path.join(dirname.replace(path, ''), filename))
images.append(os.path.join(dirname.replace(build_path, ''), filename))
f = open(path + 'json/ox.ui.images.json', 'w')
f.write(simplejson.dumps(images))
f.close()
for dirname, dirnames, filenames in os.walk(build_path + 'svg'):
for filename in filenames:
if filename[:1] != '.':
images.append(os.path.join(dirname.replace(build_path, ''), filename))
write_file(build_path + 'json/ox.ui.images.json', json.dumps(images, indent=4, sort_keys=True))

File diff suppressed because it is too large Load diff

View file

@ -11,11 +11,11 @@
width: 100%;
height: 100%;
}
#data {
#data0 {
position: absolute;
left: 0;
bottom: 0;
width: 100%;
width: 50%;
height: 100px;
padding: 0;
border: 0;
@ -29,6 +29,21 @@
#data:focus {
outline: none;
}
#data1 {
position: absolute;
right: 0;
bottom: 0;
width: 50%;
height: 100px;
padding: 0;
border: 0;
background: rgba(0, 0, 0, 0.5);
font-family: Consolas;
font-size: 8px;
color: rgb(255, 255, 255);
overflow: auto;
z-index: 1000;
}
.flag {
position: absolute;
width: 8px;
@ -74,22 +89,72 @@
src: "map.png"
})
.appendTo($body),
$data = $("<textarea/>")
$data0 = $("<textarea/>")
.attr({
id: "data"
id: "data0"
})
.appendTo($body),
$data1 = $("<textarea/>")
.attr({
id: "data1"
})
.appendTo($body),
aliases = {
'Byelorussian Soviet Socialist Republic': 'Belarus',
"Georgia": "Georgia, Europe",
'Dahomey': 'Benin',
'European Union': 'Europe',
'Georgia': 'Georgia, Europe',
'Johnston Island': 'Johnston Atoll',
'Metropolitan France': 'France',
'Neutral Zone': 'Neutral Zone, Saudi Arabia',
'Sahrawi': 'Western Sahara',
'Siam': 'Thailand',
'United States Minor Outlying Islands': 'Wake Island',
'Upper Volta': 'Burkina Faso'
// "Palestine": ["West Bank", "Gaza Strip"],
"Yugoslavia": "Serbia"
},
unions = {
/*
'Bonaire, Saint Eustatius and Saba': [
'Bonaire', 'Saba', 'Saint Eustatius'
],
*/
'Czechoslovakia': [
'Czech Republic', 'Slovakia'
],
'Korea': [
'North Korea', 'South Korea'
],
'Pacific Islands': [
'Marshall Islands', 'Micronesia', 'Northern Mariana Islands', 'Palau'
],
'Serbia and Montenegro': [
'Montenegro', 'Serbia'
],
'Soviet Union': [
'Armenia', 'Azerbaijan', 'Belarus', 'Estonia', 'Georgia',
'Latvia', 'Lithuania', 'Kazakhstan', 'Kyrgyzstan', 'Moldova',
'Russia', 'Tajikistan', 'Turkmenistan', 'Ukraine', 'Uzbekistan'
],
'United Kingdom': [
'England', 'Northern Ireland', 'Scotland', 'Wales'
],
/*
'West Germany': [
'Schleswig Holstein', 'Northrhine Westphalia', 'Bavaria'
],
*/
'Yugoslavia': [
'Bosnia and Herzegovina', 'Croatia', 'Serbia', 'Slovenia', 'Macedonia',
'Montenegro'
]
}
json = {};
///*
$.getJSON("geo.json", function(data) {
json = data;
getPlacemarks(Ox.COUNTRIES);
setTimeout(parse, 2000);
});
//*/
/*
@ -97,7 +162,7 @@
*/
function getPlacemarks(countries) {
var country = countries.shift();
if (!(country.code in json)) {
if (!(country.code in json) || !(country.name in unions)) {
console.log(country);
Ox.getPlacemarks(aliases[country.name] || country.name, function(geodata) {
if (!geodata.results.length) {
@ -164,7 +229,7 @@
}
function addData(json) {
//var scroll = $data[0].scrollTop == $data[0].scrollHeight;
$data.html(
$data0.html(
JSON.stringify(json, null, 4)
);
/*
@ -220,7 +285,7 @@
}
$("<img/>")
.attr({
src: '/static/oxjs/build/svg/' + country.code + '.' +
src: '../../build/svg/' + country.code + '.' +
(country.flag == 'png' ? 'png' : 'svg'),
title: country.name + " ((" + bounds.southWest.lat + ", " + bounds.southWest.lng + "), (" + bounds.northEast.lat + ", " + bounds.northEast.lng + "))"
})
@ -245,6 +310,97 @@
.appendTo($body);
window.status = Ox.length(json) + " " + data.address;
}
function parse() {
var bounds, center,
data = JSON.parse($data0.html()),
data_ = [],
union;
alert(Ox.COUNTRIES.length + ' ' + Ox.COUNTRIES[0].code)
Ox.COUNTRIES.forEach(function(country) {
if (country.code == 'AF') {
alert('AF')
}
Ox.print('CC', country.code)
if (country.code in data) {
bounds = data[country.code].geocode.geometry.bounds ||
data[country.code].geocode.geometry.viewport;
}
if (country.name in unions) {
unions[country.name].forEach(function(countryName, i) {
var countryCode = getCountryCode(countryName);
Ox.print('countryCode', countryCode)
bounds = data[countryCode].geocode.geometry.bounds ||
data[countryCode].geocode.geometry.viewport;
bounds = new google.maps.LatLngBounds(
new google.maps.LatLng(
bounds.southWest.lat,
bounds.southWest.lng
),
new google.maps.LatLng(
bounds.northEast.lat,
bounds.northEast.lng
)
);
union = i == 0 ? bounds : union.union(bounds);
});
bounds = {
southWest: {
lat: union.getSouthWest().lat(),
lng: union.getSouthWest().lng()
},
northEast: {
lat: union.getNorthEast().lat(),
lng: union.getNorthEast().lng()
}
};
}
if (country.name == 'Antarctica') {
bounds.southWest.lat = Ox.MIN_LATITUDE;
bounds.southWest.lng = -179.99999999;
bounds.northEast.lng = 179.99999999;
} else if (country.name == 'United Kingdom') {
}
var center = new google.maps.LatLngBounds(
new google.maps.LatLng(
bounds.southWest.lat, bounds.southWest.lng
),
new google.maps.LatLng(
bounds.northEast.lat, bounds.northEast.lng
)
).getCenter();
data_.push({
code: country.code,
name: country.name,
country: country.country,
region: country.region,
continent: country.continent,
type: country.type,
lat: center.lat(),
lng: center.lng(),
south: bounds.southWest.lat,
west: bounds.southWest.lng,
north: bounds.northEast.lat,
east: bounds.northEast.lng,
size: Ox.getArea(
bounds.southWest, bounds.northEast
)
});
});
$data1.html(JSON.stringify(data_.sort(function(a, b) {
return a.name < b.name ? -1 : (a.name > b.name ? 1 : 0);
}), null, 4));
function getCountryCode(countryName) {
var ret;
Ox.COUNTRIES.forEach(function(country) {
if (country.name == countryName) {
ret = country.code;
return false;
}
});
return ret;
}
}
});
</script>
</head>