don't loop through all jQuery functions on every Ox.Element creation
This commit is contained in:
parent
f625493d9c
commit
9a61861bf5
4 changed files with 2757 additions and 518 deletions
|
@ -24,7 +24,7 @@ requires
|
|||
Ox.theme(Ox.UI.DEFAULT_THEME);
|
||||
});
|
||||
return {
|
||||
$elements: {},
|
||||
elements: {},
|
||||
DEFAULT_THEME: 'classic',
|
||||
DIMENSIONS: {
|
||||
horizontal: ['width', 'height'],
|
||||
|
@ -362,7 +362,7 @@ requires
|
|||
stack.splice(stack.length - 2, 0, stack.pop());
|
||||
//$elements[id].removeClass('OxFocus');
|
||||
$('.OxFocus').removeClass('OxFocus'); // fixme: the above is better, and should work
|
||||
stack.length && Ox.UI.$elements[stack[stack.length - 1]].addClass('OxFocus');
|
||||
stack.length && Ox.UI.elements[stack[stack.length - 1]].addClass('OxFocus');
|
||||
Ox.print('blur', id, stack);
|
||||
}
|
||||
},
|
||||
|
@ -372,7 +372,7 @@ requires
|
|||
index > -1 && stack.splice(index, 1);
|
||||
stack.push(id);
|
||||
$('.OxFocus').removeClass('OxFocus'); // fixme: see above
|
||||
Ox.UI.$elements[id].addClass('OxFocus');
|
||||
Ox.UI.elements[id].addClass('OxFocus');
|
||||
Ox.print('focus', id, stack);
|
||||
}
|
||||
},
|
||||
|
@ -568,8 +568,8 @@ requires
|
|||
buffer += key == 'SPACE' ? ' ' : key;
|
||||
bufferTime = time;
|
||||
}
|
||||
focused !== null && Ox.UI.$elements[focused].triggerEvent('key_' + key);
|
||||
if (['down', 'space', 'up'].indexOf(key) > -1 && !Ox.UI.$elements[focused].hasClass('OxInput')) {
|
||||
focused !== null && Ox.UI.elements[focused].triggerEvent('key_' + key);
|
||||
if (['down', 'space', 'up'].indexOf(key) > -1 && !Ox.UI.elements[focused].hasClass('OxInput')) {
|
||||
// prevent chrome from scrolling
|
||||
return false;
|
||||
}
|
||||
|
@ -834,44 +834,38 @@ requires
|
|||
return that;
|
||||
};
|
||||
|
||||
Ox.jQueryElement = (function() {
|
||||
// Basic jQuery element
|
||||
var jQueryFunctions = (function() {
|
||||
var functions = [];
|
||||
Ox.each($('<div>'), function(key, val) {
|
||||
typeof val == 'function' && functions.push(key);
|
||||
});
|
||||
return functions.sort();
|
||||
})();
|
||||
return function(element) {
|
||||
var that = {};
|
||||
Ox.each(jQueryFunctions, function(i, fn) {
|
||||
that[fn] = function() {
|
||||
var args = arguments, id, ret;
|
||||
$.each(args, function(i, arg) {
|
||||
// if an ox object was passed
|
||||
// then pass its $element instead
|
||||
// so that we can do oxObj.jqFn(oxObj)
|
||||
if (arg && arg.ox) {
|
||||
args[i] = arg.$element;
|
||||
}
|
||||
});
|
||||
ret = element.$element[fn].apply(element.$element, args);
|
||||
// if the $element of an ox object was returned
|
||||
// then return the ox object instead
|
||||
// so that we can do oxObj.jqFn().oxFn()
|
||||
/*
|
||||
if (fn == 'appendTo') {
|
||||
Ox.print('ret', ret, $element, ret.jquery && Ox.UI.$elements[id = ret.data('ox')] == true)
|
||||
// Basic jQuery element
|
||||
Ox.$Element = function($element) {
|
||||
var that = this;
|
||||
that.id = Ox.uid();
|
||||
that.ox = Ox.VERSION;
|
||||
that.$element = $element.data({
|
||||
oxid: that.id
|
||||
});
|
||||
Ox.UI.elements[that.id] = that;
|
||||
return that;
|
||||
};
|
||||
Ox.each($('<div>'), function(key, val) {
|
||||
if (Ox.isFunction(val)) {
|
||||
Ox.$Element.prototype[key] = function() {
|
||||
var args = arguments, id, ret, that = this;
|
||||
Ox.forEach(args, function(arg, i) {
|
||||
// if an ox object was passed
|
||||
// then pass its $element instead
|
||||
// so that we can do oxObj.jqFn(oxObj)
|
||||
if (arg && arg.ox) {
|
||||
args[i] = arg.$element;
|
||||
}
|
||||
*/
|
||||
return ret.jquery && Ox.UI.$elements[id = ret.data('ox')] ?
|
||||
Ox.UI.$elements[id] : ret;
|
||||
};
|
||||
});
|
||||
return that;
|
||||
});
|
||||
ret = that.$element[key].apply(that.$element, args);
|
||||
// if the $element of an ox object was returned
|
||||
// then return the ox object instead
|
||||
// so that we can do oxObj.jqFn().oxFn()
|
||||
return ret.jquery && Ox.UI.elements[id = ret.data('oxid')] ?
|
||||
Ox.UI.elements[id] : ret;
|
||||
};
|
||||
}
|
||||
})();
|
||||
});
|
||||
|
||||
// check out http://ejohn.org/apps/learn/#36 (-#38, making fns work w/o new)
|
||||
|
||||
|
@ -889,28 +883,18 @@ requires
|
|||
|
||||
self = self || {};
|
||||
self.options = options || {};
|
||||
if (!self.$eventHandler) {
|
||||
self.$eventHandler = $('<div>');
|
||||
}
|
||||
var that = this;
|
||||
|
||||
// allow for Ox.Element('tagname', self)
|
||||
if (typeof self.options == 'string') {
|
||||
self.options = {
|
||||
element: self.options
|
||||
};
|
||||
}
|
||||
that.ox = Ox.VERSION;
|
||||
that.id = Ox.uid();
|
||||
that.$element = $('<' + (self.options.element || 'div') + '/>', {
|
||||
data: {
|
||||
ox: that.id
|
||||
},
|
||||
mousedown: mousedown
|
||||
});
|
||||
Ox.UI.$elements[that.id] = that;
|
||||
if (!self.$eventHandler) {
|
||||
self.$eventHandler = $('<div>');
|
||||
}
|
||||
|
||||
$.extend(that, Ox.jQueryElement(that));
|
||||
var that = new Ox.$Element($('<' + (self.options.element || 'div') + '>'));
|
||||
that.$element.mousedown(mousedown);
|
||||
|
||||
function mousedown(e) {
|
||||
/*
|
||||
|
@ -1088,7 +1072,7 @@ requires
|
|||
that.loseFocus();
|
||||
delete self.$eventHandler;
|
||||
that.$element.remove();
|
||||
delete Ox.UI.$elements[that.ox];
|
||||
delete Ox.UI.elements[that.id];
|
||||
return that;
|
||||
};
|
||||
|
||||
|
|
|
@ -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))
|
2952
tools/geo/geo.json
2952
tools/geo/geo.json
File diff suppressed because it is too large
Load diff
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue