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);
|
Ox.theme(Ox.UI.DEFAULT_THEME);
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
$elements: {},
|
elements: {},
|
||||||
DEFAULT_THEME: 'classic',
|
DEFAULT_THEME: 'classic',
|
||||||
DIMENSIONS: {
|
DIMENSIONS: {
|
||||||
horizontal: ['width', 'height'],
|
horizontal: ['width', 'height'],
|
||||||
|
@ -362,7 +362,7 @@ requires
|
||||||
stack.splice(stack.length - 2, 0, stack.pop());
|
stack.splice(stack.length - 2, 0, stack.pop());
|
||||||
//$elements[id].removeClass('OxFocus');
|
//$elements[id].removeClass('OxFocus');
|
||||||
$('.OxFocus').removeClass('OxFocus'); // fixme: the above is better, and should work
|
$('.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);
|
Ox.print('blur', id, stack);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -372,7 +372,7 @@ requires
|
||||||
index > -1 && stack.splice(index, 1);
|
index > -1 && stack.splice(index, 1);
|
||||||
stack.push(id);
|
stack.push(id);
|
||||||
$('.OxFocus').removeClass('OxFocus'); // fixme: see above
|
$('.OxFocus').removeClass('OxFocus'); // fixme: see above
|
||||||
Ox.UI.$elements[id].addClass('OxFocus');
|
Ox.UI.elements[id].addClass('OxFocus');
|
||||||
Ox.print('focus', id, stack);
|
Ox.print('focus', id, stack);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -568,8 +568,8 @@ requires
|
||||||
buffer += key == 'SPACE' ? ' ' : key;
|
buffer += key == 'SPACE' ? ' ' : key;
|
||||||
bufferTime = time;
|
bufferTime = time;
|
||||||
}
|
}
|
||||||
focused !== null && Ox.UI.$elements[focused].triggerEvent('key_' + key);
|
focused !== null && Ox.UI.elements[focused].triggerEvent('key_' + key);
|
||||||
if (['down', 'space', 'up'].indexOf(key) > -1 && !Ox.UI.$elements[focused].hasClass('OxInput')) {
|
if (['down', 'space', 'up'].indexOf(key) > -1 && !Ox.UI.elements[focused].hasClass('OxInput')) {
|
||||||
// prevent chrome from scrolling
|
// prevent chrome from scrolling
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -834,44 +834,38 @@ requires
|
||||||
return that;
|
return that;
|
||||||
};
|
};
|
||||||
|
|
||||||
Ox.jQueryElement = (function() {
|
// Basic jQuery element
|
||||||
// Basic jQuery element
|
Ox.$Element = function($element) {
|
||||||
var jQueryFunctions = (function() {
|
var that = this;
|
||||||
var functions = [];
|
that.id = Ox.uid();
|
||||||
Ox.each($('<div>'), function(key, val) {
|
that.ox = Ox.VERSION;
|
||||||
typeof val == 'function' && functions.push(key);
|
that.$element = $element.data({
|
||||||
});
|
oxid: that.id
|
||||||
return functions.sort();
|
});
|
||||||
})();
|
Ox.UI.elements[that.id] = that;
|
||||||
return function(element) {
|
return that;
|
||||||
var that = {};
|
};
|
||||||
Ox.each(jQueryFunctions, function(i, fn) {
|
Ox.each($('<div>'), function(key, val) {
|
||||||
that[fn] = function() {
|
if (Ox.isFunction(val)) {
|
||||||
var args = arguments, id, ret;
|
Ox.$Element.prototype[key] = function() {
|
||||||
$.each(args, function(i, arg) {
|
var args = arguments, id, ret, that = this;
|
||||||
// if an ox object was passed
|
Ox.forEach(args, function(arg, i) {
|
||||||
// then pass its $element instead
|
// if an ox object was passed
|
||||||
// so that we can do oxObj.jqFn(oxObj)
|
// then pass its $element instead
|
||||||
if (arg && arg.ox) {
|
// so that we can do oxObj.jqFn(oxObj)
|
||||||
args[i] = arg.$element;
|
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)
|
|
||||||
}
|
}
|
||||||
*/
|
});
|
||||||
return ret.jquery && Ox.UI.$elements[id = ret.data('ox')] ?
|
ret = that.$element[key].apply(that.$element, args);
|
||||||
Ox.UI.$elements[id] : ret;
|
// if the $element of an ox object was returned
|
||||||
};
|
// then return the ox object instead
|
||||||
});
|
// so that we can do oxObj.jqFn().oxFn()
|
||||||
return that;
|
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)
|
// check out http://ejohn.org/apps/learn/#36 (-#38, making fns work w/o new)
|
||||||
|
|
||||||
|
@ -889,28 +883,18 @@ requires
|
||||||
|
|
||||||
self = self || {};
|
self = self || {};
|
||||||
self.options = options || {};
|
self.options = options || {};
|
||||||
if (!self.$eventHandler) {
|
|
||||||
self.$eventHandler = $('<div>');
|
|
||||||
}
|
|
||||||
var that = this;
|
|
||||||
|
|
||||||
// allow for Ox.Element('tagname', self)
|
// allow for Ox.Element('tagname', self)
|
||||||
if (typeof self.options == 'string') {
|
if (typeof self.options == 'string') {
|
||||||
self.options = {
|
self.options = {
|
||||||
element: self.options
|
element: self.options
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
that.ox = Ox.VERSION;
|
if (!self.$eventHandler) {
|
||||||
that.id = Ox.uid();
|
self.$eventHandler = $('<div>');
|
||||||
that.$element = $('<' + (self.options.element || 'div') + '/>', {
|
}
|
||||||
data: {
|
|
||||||
ox: that.id
|
|
||||||
},
|
|
||||||
mousedown: mousedown
|
|
||||||
});
|
|
||||||
Ox.UI.$elements[that.id] = that;
|
|
||||||
|
|
||||||
$.extend(that, Ox.jQueryElement(that));
|
var that = new Ox.$Element($('<' + (self.options.element || 'div') + '>'));
|
||||||
|
that.$element.mousedown(mousedown);
|
||||||
|
|
||||||
function mousedown(e) {
|
function mousedown(e) {
|
||||||
/*
|
/*
|
||||||
|
@ -1088,7 +1072,7 @@ requires
|
||||||
that.loseFocus();
|
that.loseFocus();
|
||||||
delete self.$eventHandler;
|
delete self.$eventHandler;
|
||||||
that.$element.remove();
|
that.$element.remove();
|
||||||
delete Ox.UI.$elements[that.ox];
|
delete Ox.UI.elements[that.id];
|
||||||
return that;
|
return that;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,51 @@
|
||||||
|
import json
|
||||||
import os
|
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 = []
|
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:
|
for filename in filenames:
|
||||||
if filename[:1] != '.':
|
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')
|
for dirname, dirnames, filenames in os.walk(build_path + 'svg'):
|
||||||
f.write(simplejson.dumps(images))
|
for filename in filenames:
|
||||||
f.close()
|
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%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
#data {
|
#data0 {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
left: 0;
|
left: 0;
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
width: 100%;
|
width: 50%;
|
||||||
height: 100px;
|
height: 100px;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
border: 0;
|
border: 0;
|
||||||
|
@ -29,6 +29,21 @@
|
||||||
#data:focus {
|
#data:focus {
|
||||||
outline: none;
|
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 {
|
.flag {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
width: 8px;
|
width: 8px;
|
||||||
|
@ -74,22 +89,72 @@
|
||||||
src: "map.png"
|
src: "map.png"
|
||||||
})
|
})
|
||||||
.appendTo($body),
|
.appendTo($body),
|
||||||
$data = $("<textarea/>")
|
$data0 = $("<textarea/>")
|
||||||
.attr({
|
.attr({
|
||||||
id: "data"
|
id: "data0"
|
||||||
|
})
|
||||||
|
.appendTo($body),
|
||||||
|
$data1 = $("<textarea/>")
|
||||||
|
.attr({
|
||||||
|
id: "data1"
|
||||||
})
|
})
|
||||||
.appendTo($body),
|
.appendTo($body),
|
||||||
aliases = {
|
aliases = {
|
||||||
'Byelorussian Soviet Socialist Republic': 'Belarus',
|
'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"],
|
// "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 = {};
|
json = {};
|
||||||
///*
|
///*
|
||||||
$.getJSON("geo.json", function(data) {
|
$.getJSON("geo.json", function(data) {
|
||||||
json = data;
|
json = data;
|
||||||
getPlacemarks(Ox.COUNTRIES);
|
getPlacemarks(Ox.COUNTRIES);
|
||||||
|
setTimeout(parse, 2000);
|
||||||
});
|
});
|
||||||
//*/
|
//*/
|
||||||
/*
|
/*
|
||||||
|
@ -97,7 +162,7 @@
|
||||||
*/
|
*/
|
||||||
function getPlacemarks(countries) {
|
function getPlacemarks(countries) {
|
||||||
var country = countries.shift();
|
var country = countries.shift();
|
||||||
if (!(country.code in json)) {
|
if (!(country.code in json) || !(country.name in unions)) {
|
||||||
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.length) {
|
if (!geodata.results.length) {
|
||||||
|
@ -164,7 +229,7 @@
|
||||||
}
|
}
|
||||||
function addData(json) {
|
function addData(json) {
|
||||||
//var scroll = $data[0].scrollTop == $data[0].scrollHeight;
|
//var scroll = $data[0].scrollTop == $data[0].scrollHeight;
|
||||||
$data.html(
|
$data0.html(
|
||||||
JSON.stringify(json, null, 4)
|
JSON.stringify(json, null, 4)
|
||||||
);
|
);
|
||||||
/*
|
/*
|
||||||
|
@ -220,7 +285,7 @@
|
||||||
}
|
}
|
||||||
$("<img/>")
|
$("<img/>")
|
||||||
.attr({
|
.attr({
|
||||||
src: '/static/oxjs/build/svg/' + country.code + '.' +
|
src: '../../build/svg/' + country.code + '.' +
|
||||||
(country.flag == 'png' ? 'png' : 'svg'),
|
(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 + "))"
|
||||||
})
|
})
|
||||||
|
@ -245,6 +310,97 @@
|
||||||
.appendTo($body);
|
.appendTo($body);
|
||||||
window.status = Ox.length(json) + " " + data.address;
|
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>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
|
Loading…
Reference in a new issue