forked from 0x2620/oxjs
add geo module documentation and tests
This commit is contained in:
parent
7c3a40368f
commit
43fa75c8db
8 changed files with 203 additions and 98 deletions
|
|
@ -4,7 +4,13 @@ Ox.load('UI', {
|
||||||
}, function() {
|
}, function() {
|
||||||
Ox.Theme('classic');
|
Ox.Theme('classic');
|
||||||
Ox.DocPanel({
|
Ox.DocPanel({
|
||||||
files: ['Ox.js', 'Ox.UI/js/Map/Ox.Map.js', 'Ox.UI/js/Core/Ox.Element.js', 'Ox.UI/js/Core/Ox.JQueryElement.js'],
|
files: [
|
||||||
|
'Ox.js',
|
||||||
|
'Ox.Geo/Ox.Geo.js',
|
||||||
|
'Ox.UI/js/Map/Ox.Map.js',
|
||||||
|
'Ox.UI/js/Core/Ox.Element.js',
|
||||||
|
'Ox.UI/js/Core/Ox.JQueryElement.js'
|
||||||
|
],
|
||||||
getModule: function(item) {
|
getModule: function(item) {
|
||||||
var file = item.file.replace(Ox.PATH, '');
|
var file = item.file.replace(Ox.PATH, '');
|
||||||
return file == 'Ox.js' ? 'Ox' : file.split('/')[0];
|
return file == 'Ox.js' ? 'Ox' : file.split('/')[0];
|
||||||
|
|
|
||||||
|
|
@ -2,99 +2,114 @@ Ox.load('UI', {
|
||||||
debug: true,
|
debug: true,
|
||||||
theme: 'classic'
|
theme: 'classic'
|
||||||
}, function() {
|
}, function() {
|
||||||
var colors = [
|
Ox.load('Geo', function() {
|
||||||
[[255, 64, 64], [224, 32, 32]],
|
var $div = $('<div>')
|
||||||
[[64, 192, 64], [32, 160, 32]]
|
.css({
|
||||||
],
|
width: window.innerWidth,
|
||||||
gradients = [
|
height: window.innerHeight,
|
||||||
'-moz-linear-gradient(',
|
overflowY: 'scroll'
|
||||||
'-webkit-gradient(linear, '
|
})
|
||||||
];
|
.appendTo(Ox.UI.$body),
|
||||||
var $foo = $('<div>')
|
colors = [
|
||||||
.css({
|
[[255, 64, 64], [224, 32, 32]],
|
||||||
width: window.innerWidth,
|
[[64, 192, 64], [32, 160, 32]]
|
||||||
height: window.innerHeight,
|
],
|
||||||
overflowY: 'scroll'
|
counter = 0,
|
||||||
})
|
files = [
|
||||||
.appendTo(Ox.UI.$body);
|
Ox.PATH + 'Ox.js',
|
||||||
Ox.test(Ox.PATH + 'Ox.js', function(tests) {
|
Ox.PATH + 'Ox.Geo/Ox.Geo.js'
|
||||||
var total = tests.length,
|
],
|
||||||
succeeded = tests.filter(function(test) {
|
tests = [];
|
||||||
return test.success;
|
files.forEach(function(file) {
|
||||||
}).length,
|
Ox.test(file, function(fileTests) {
|
||||||
failed = total - succeeded,
|
tests = Ox.merge(tests, fileTests);
|
||||||
names = Ox.unique(tests.map(function(test) {
|
if (++counter == files.length) {
|
||||||
return test.name;
|
renderTests();
|
||||||
})).sort();
|
}
|
||||||
testsByName = {};
|
});
|
||||||
tests.forEach(function(test) {
|
|
||||||
if (!(test.name in testsByName)) {
|
|
||||||
testsByName[test.name] = [];
|
|
||||||
}
|
|
||||||
testsByName[test.name].push(test);
|
|
||||||
});
|
});
|
||||||
getBar(total == succeeded)
|
function renderTests() {
|
||||||
.html(
|
var total = tests.length,
|
||||||
'<b>' + total + ' tests, ' +
|
|
||||||
succeeded + ' succeeded, ' + failed + ' failed</b>'
|
|
||||||
)
|
|
||||||
.appendTo($foo);
|
|
||||||
names.forEach(function(name) {
|
|
||||||
var tests = testsByName[name],
|
|
||||||
total = tests.length,
|
|
||||||
succeeded = tests.filter(function(test) {
|
succeeded = tests.filter(function(test) {
|
||||||
return test.success;
|
return test.success;
|
||||||
}).length,
|
}).length,
|
||||||
failed = total - succeeded,
|
failed = total - succeeded,
|
||||||
classname = name.replace('.', '');
|
names = Ox.unique(tests.map(function(test) {
|
||||||
|
return test.name;
|
||||||
|
})).sort();
|
||||||
|
testsByName = {};
|
||||||
|
tests.forEach(function(test) {
|
||||||
|
if (!(test.name in testsByName)) {
|
||||||
|
testsByName[test.name] = [];
|
||||||
|
}
|
||||||
|
testsByName[test.name].push(test);
|
||||||
|
});
|
||||||
getBar(total == succeeded)
|
getBar(total == succeeded)
|
||||||
.html(
|
.html(
|
||||||
'<b>' + name + '</b> — ' + total +
|
'<b>' + total + ' tests, ' +
|
||||||
' test' + (total == 1 ? '' : 's') + ', ' +
|
|
||||||
succeeded + ' succeeded, ' + failed + ' failed</b>'
|
succeeded + ' succeeded, ' + failed + ' failed</b>'
|
||||||
)
|
)
|
||||||
.click(function() {
|
.appendTo($div);
|
||||||
$('.' + classname).toggle();
|
names.forEach(function(name) {
|
||||||
})
|
var tests = testsByName[name],
|
||||||
.appendTo($foo);
|
total = tests.length,
|
||||||
tests.forEach(function(test) {
|
succeeded = tests.filter(function(test) {
|
||||||
getBar(test.success, true)
|
return test.success;
|
||||||
.addClass(classname)
|
}).length,
|
||||||
|
failed = total - succeeded,
|
||||||
|
classname = name.replace('.', '');
|
||||||
|
getBar(total == succeeded)
|
||||||
.html(
|
.html(
|
||||||
Ox.repeat(' ', 4) +
|
'<b>' + name + '</b> — ' + total +
|
||||||
'<b>> ' + Ox.encodeHTML(test.statement) + ' </b> ==> ' +
|
' test' + (total == 1 ? '' : 's') + ', ' +
|
||||||
(test.success ? '' : Ox.encodeHTML(test.actual) + ' !=> ') +
|
succeeded + ' succeeded, ' + failed + ' failed</b>'
|
||||||
Ox.encodeHTML(test.expected)
|
|
||||||
)
|
)
|
||||||
.hide()
|
.click(function() {
|
||||||
.appendTo($foo);
|
$('.' + classname).toggle();
|
||||||
|
})
|
||||||
|
.appendTo($div);
|
||||||
|
tests.forEach(function(test) {
|
||||||
|
getBar(test.success, true)
|
||||||
|
.addClass(classname)
|
||||||
|
.html(
|
||||||
|
Ox.repeat(' ', 4) +
|
||||||
|
'<b>> ' + Ox.encodeHTML(test.statement) + ' </b> ==> ' +
|
||||||
|
(test.success ? '' : Ox.encodeHTML(test.actual) + ' !=> ') +
|
||||||
|
Ox.encodeHTML(test.expected)
|
||||||
|
)
|
||||||
|
.hide()
|
||||||
|
.appendTo($div);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
});
|
|
||||||
function getBar(success, darker) {
|
|
||||||
var $div = $('<div>')
|
|
||||||
.css({
|
|
||||||
width: window.innerWidth - Ox.UI.SCROLLBAR_SIZE,
|
|
||||||
height: '15px',
|
|
||||||
padding: '4px 8px 4px 8px',
|
|
||||||
fontFamily: 'Menlo, Monaco, Courier',
|
|
||||||
fontSize: '12px',
|
|
||||||
whiteSpace: 'nowrap',
|
|
||||||
MozUserSelect: 'text',
|
|
||||||
WebkitUserSelect: 'text'
|
|
||||||
});
|
|
||||||
gradients.forEach(function(gradient) {
|
|
||||||
$div.css({
|
|
||||||
background: gradient + 'left top, left bottom, from(rgb(' +
|
|
||||||
getColor(success, 0) + ')), to(rgb(' +
|
|
||||||
getColor(success, 1) + ')))'
|
|
||||||
});
|
|
||||||
});
|
|
||||||
function getColor(success, i) {
|
|
||||||
return colors[+success][i].map(function(color) {
|
|
||||||
return color - (darker || 0) * 32;
|
|
||||||
}).join(', ')
|
|
||||||
}
|
}
|
||||||
return $div;
|
function getBar(success, darker) {
|
||||||
}
|
var $div = $('<div>')
|
||||||
|
.css({
|
||||||
|
width: window.innerWidth - Ox.UI.SCROLLBAR_SIZE,
|
||||||
|
height: '15px',
|
||||||
|
padding: '4px 8px 4px 8px',
|
||||||
|
fontFamily: 'Menlo, Monaco, Courier',
|
||||||
|
fontSize: '12px',
|
||||||
|
whiteSpace: 'nowrap',
|
||||||
|
MozUserSelect: 'text',
|
||||||
|
WebkitUserSelect: 'text'
|
||||||
|
});
|
||||||
|
['moz', 'webkit'].forEach(function(browser) {
|
||||||
|
Ox.print('-' + browser + '-linear-gradient(left top, left bottom, rgb(' +
|
||||||
|
getColor(success, 0) + '), rgb(' +
|
||||||
|
getColor(success, 1) + '))')
|
||||||
|
$div.css({
|
||||||
|
background: '-' + browser + '-linear-gradient(top, rgb(' +
|
||||||
|
getColor(success, 0) + '), rgb(' +
|
||||||
|
getColor(success, 1) + '))'
|
||||||
|
});
|
||||||
|
});
|
||||||
|
function getColor(success, i) {
|
||||||
|
return colors[+success][i].map(function(color) {
|
||||||
|
return color - (darker || 0) * 32;
|
||||||
|
}).join(', ')
|
||||||
|
}
|
||||||
|
return $div;
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
@ -2,8 +2,79 @@ Ox.load.Geo = function(options, callback) {
|
||||||
|
|
||||||
Ox.getJSON(Ox.PATH + 'Ox.Geo/json/Ox.Geo.json', function(data) {
|
Ox.getJSON(Ox.PATH + 'Ox.Geo/json/Ox.Geo.json', function(data) {
|
||||||
|
|
||||||
|
//@ Constants ----------------------------------------------------------
|
||||||
|
|
||||||
|
/*@
|
||||||
|
Ox.COUNTRIES <[o]> Array of countries
|
||||||
|
area <n> Area of the country in square meters
|
||||||
|
code <s> ISO 3166 country code
|
||||||
|
dependencies <[s]> Array of dependencies of the country (country codes)
|
||||||
|
dependency <[s]> Array of countries the country is a dependency of (country codes)
|
||||||
|
east <n> Longitude of eastern boundary in deg
|
||||||
|
former <b> True if the country is a former country
|
||||||
|
imageURLs <o> Collection of dataURLs
|
||||||
|
marker <s> Map marker
|
||||||
|
imdbCode <s> IMDb country code
|
||||||
|
imdbName <s> IMDb country name
|
||||||
|
lat <n> Latitude of the center in deg
|
||||||
|
lng <n> Longitude of the center in deg
|
||||||
|
name <s> Name
|
||||||
|
north <n> Latitude of northern boundary in deg
|
||||||
|
other <b> True if the country is an "other entity" (EU, FX, UK)
|
||||||
|
south <n> Latitude of southern boundary in deg
|
||||||
|
wikipediaURL <s> URL of the wikipedia article for the country
|
||||||
|
west <n> Longitude of western boundary in deg
|
||||||
|
<script>
|
||||||
|
Ox.test.array = [
|
||||||
|
// Current independent countries with dependencies
|
||||||
|
Ox.COUNTRIES.filter(function(c) {
|
||||||
|
return c.dependencies.length && !c.former && !c.other;
|
||||||
|
}).length,
|
||||||
|
// Current independent countries without dependencies
|
||||||
|
Ox.COUNTRIES.filter(function(c) {
|
||||||
|
return !c.dependencies.length && !c.dependency.length &&
|
||||||
|
!c.former && !c.other;
|
||||||
|
}).length,
|
||||||
|
// Current dependecies
|
||||||
|
Ox.COUNTRIES.filter(function(c) {
|
||||||
|
return c.dependency.length && !c.former && !c.other;
|
||||||
|
}).length,
|
||||||
|
// Former independent countries with dependencies
|
||||||
|
Ox.COUNTRIES.filter(function(c) {
|
||||||
|
return c.dependencies.length && c.former && !c.other;
|
||||||
|
}).length,
|
||||||
|
// Former independent countries without dependencies
|
||||||
|
Ox.COUNTRIES.filter(function(c) {
|
||||||
|
return !c.dependencies.length && !c.dependency.length &&
|
||||||
|
c.former && !c.other;
|
||||||
|
}).length,
|
||||||
|
// Former dependecies
|
||||||
|
Ox.COUNTRIES.filter(function(c) {
|
||||||
|
return c.dependency.length && c.former && !c.other;
|
||||||
|
}).length,
|
||||||
|
// Other entities
|
||||||
|
Ox.COUNTRIES.filter(function(c) { return c.other; }).length
|
||||||
|
];
|
||||||
|
</script>
|
||||||
|
> Ox.COUNTRIES.length
|
||||||
|
311
|
||||||
|
> Ox.sum(Ox.test.array)
|
||||||
|
311
|
||||||
|
> Ox.test.array
|
||||||
|
[15, 189, 74, 1, 16, 13, 3]
|
||||||
|
@*/
|
||||||
Ox.COUNTRIES = data;
|
Ox.COUNTRIES = data;
|
||||||
|
|
||||||
|
//@ Functions ----------------------------------------------------------
|
||||||
|
|
||||||
|
/*@
|
||||||
|
Ox.getCountryByCode <f> Returns a country object for a given country code
|
||||||
|
(code) -> <o> Country object
|
||||||
|
code <s> ISO 3166 country code
|
||||||
|
> Ox.getCountryByCode('US').name
|
||||||
|
'United States'
|
||||||
|
@*/
|
||||||
|
|
||||||
Ox.getCountryByCode = function(code) {
|
Ox.getCountryByCode = function(code) {
|
||||||
var country;
|
var country;
|
||||||
Ox.forEach(Ox.COUNTRIES, function(c) {
|
Ox.forEach(Ox.COUNTRIES, function(c) {
|
||||||
|
|
@ -15,6 +86,14 @@ Ox.load.Geo = function(options, callback) {
|
||||||
return country;
|
return country;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*@
|
||||||
|
Ox.getCountryByName <f> Returns a country object for a given country name
|
||||||
|
(name) -> <o> Country object
|
||||||
|
name <s> Country name
|
||||||
|
> Ox.getCountryByName('United States').code
|
||||||
|
'US'
|
||||||
|
@*/
|
||||||
|
|
||||||
Ox.getCountryByName = function(name) {
|
Ox.getCountryByName = function(name) {
|
||||||
var country;
|
var country;
|
||||||
Ox.forEach(Ox.COUNTRIES, function(c) {
|
Ox.forEach(Ox.COUNTRIES, function(c) {
|
||||||
|
|
|
||||||
|
|
@ -274,7 +274,8 @@ Ox.BlockTimeline = function(options, self) {
|
||||||
self.$tooltip.options({
|
self.$tooltip.options({
|
||||||
title: subtitle ?
|
title: subtitle ?
|
||||||
'<span class=\'OxBright\'>' +
|
'<span class=\'OxBright\'>' +
|
||||||
Ox.highlight(subtitle.value, self.options.find).replace(/\n/g, '<br/>') + '</span><br/>' +
|
Ox.highlight(subtitle.value, self.options.find, 'OxHighlight').replace(/\n/g, '<br/>') +
|
||||||
|
'</span><br/>' +
|
||||||
Ox.formatDuration(subtitle['in'], 3) + ' - ' + Ox.formatDuration(subtitle['out'], 3) :
|
Ox.formatDuration(subtitle['in'], 3) + ' - ' + Ox.formatDuration(subtitle['out'], 3) :
|
||||||
Ox.formatDuration(position, 3)
|
Ox.formatDuration(position, 3)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ Ox.LargeTimeline = function(options, self) {
|
||||||
left: (v['in'] * self.fps) + 'px',
|
left: (v['in'] * self.fps) + 'px',
|
||||||
width: (((v['out'] - v['in']) * self.fps) - 2) + 'px'
|
width: (((v['out'] - v['in']) * self.fps) - 2) + 'px'
|
||||||
})
|
})
|
||||||
.html(Ox.highlight(v.value, self.options.find))
|
.html(Ox.highlight(v.value, self.options.find, 'OxHighlight'))
|
||||||
.appendTo(self.$timeline)
|
.appendTo(self.$timeline)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -130,7 +130,8 @@ Ox.SmallTimeline = function(options, self) {
|
||||||
self.$tooltip.options({
|
self.$tooltip.options({
|
||||||
title: subtitle ?
|
title: subtitle ?
|
||||||
'<span class=\'OxBright\'>' +
|
'<span class=\'OxBright\'>' +
|
||||||
Ox.highlight(subtitle.value, self.options.find).replace(/\n/g, '<br/>') + '</span><br/>' +
|
Ox.highlight(subtitle.value, self.options.find, 'OxHighlight').replace(/\n/g, '<br/>') +
|
||||||
|
'</span><br/>' +
|
||||||
Ox.formatDuration(subtitle['in'], 3) + ' - ' + Ox.formatDuration(subtitle['out'], 3) :
|
Ox.formatDuration(subtitle['in'], 3) + ' - ' + Ox.formatDuration(subtitle['out'], 3) :
|
||||||
Ox.formatDuration(position, 3)
|
Ox.formatDuration(position, 3)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -320,7 +320,10 @@ Ox.VideoEditorPlayer = function(options, self) {
|
||||||
var subtitle = getSubtitle();
|
var subtitle = getSubtitle();
|
||||||
if (subtitle != self.subtitle) {
|
if (subtitle != self.subtitle) {
|
||||||
self.subtitle = subtitle;
|
self.subtitle = subtitle;
|
||||||
self.$subtitle.html(Ox.highlight(self.subtitle, self.options.find).replace(/\n/g, '<br/>'));
|
self.$subtitle.html(
|
||||||
|
Ox.highlight(self.subtitle, self.options.find, 'Ox.Highlight')
|
||||||
|
.replace(/\n/g, '<br/>')
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
20
source/Ox.js
20
source/Ox.js
|
|
@ -2903,7 +2903,6 @@ Ox.doc = (function() {
|
||||||
}
|
}
|
||||||
function parseNode(node) {
|
function parseNode(node) {
|
||||||
var item = parseItem(node.line), subitem;
|
var item = parseItem(node.line), subitem;
|
||||||
Ox.print(node, node.line, 'item', item);
|
|
||||||
node.nodes && node.nodes.forEach(function(node) {
|
node.nodes && node.nodes.forEach(function(node) {
|
||||||
var key, line = node.line, subitem;
|
var key, line = node.line, subitem;
|
||||||
if (!/^#/.test(node.line)) {
|
if (!/^#/.test(node.line)) {
|
||||||
|
|
@ -2946,10 +2945,8 @@ Ox.doc = (function() {
|
||||||
}
|
}
|
||||||
function parseTest(str) {
|
function parseTest(str) {
|
||||||
var lines = decodeLinebreaks(str).split('\n');
|
var lines = decodeLinebreaks(str).split('\n');
|
||||||
Ox.print('$$$', str)
|
|
||||||
return {
|
return {
|
||||||
statement: lines[0].substr(2),
|
statement: lines[0].substr(2),
|
||||||
// result: JSON.parse(lines[1].trim())
|
|
||||||
result: lines[1].trim()
|
result: lines[1].trim()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -3144,7 +3141,6 @@ Ox.test = function(file, callback) {
|
||||||
var tests = [];
|
var tests = [];
|
||||||
items.forEach(function(item) {
|
items.forEach(function(item) {
|
||||||
item.examples && item.examples.forEach(function(example) {
|
item.examples && item.examples.forEach(function(example) {
|
||||||
Ox.print(example)
|
|
||||||
var actual = eval(example.statement);
|
var actual = eval(example.statement);
|
||||||
if (example.result) {
|
if (example.result) {
|
||||||
tests.push({
|
tests.push({
|
||||||
|
|
@ -3859,12 +3855,16 @@ Ox.endsWith = function(str, sub) {
|
||||||
return str.substr(str.length - sub.length) == sub;
|
return str.substr(str.length - sub.length) == sub;
|
||||||
};
|
};
|
||||||
|
|
||||||
Ox.highlight = function(txt, str) {
|
/*@
|
||||||
// fixme: move to ox.ui
|
Ox.highlight <f> Highlight matches in a string
|
||||||
return str ? txt.replace(
|
> Ox.highlight('foobar', 'foo', 'match')
|
||||||
|
'<span class="match">foo</span>bar'
|
||||||
|
@*/
|
||||||
|
Ox.highlight = function(txt, str, classname) {
|
||||||
|
return txt.replace(
|
||||||
new RegExp('(' + str + ')', 'ig'),
|
new RegExp('(' + str + ')', 'ig'),
|
||||||
'<span class="OxHighlight">$1</span>'
|
'<span class="' + classname + '">$1</span>'
|
||||||
) : txt;
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
/*@
|
/*@
|
||||||
|
|
@ -4028,7 +4028,7 @@ Ox.toCamelCase <f> Takes a string with '-', '/' or '_', returns a camelCase stri
|
||||||
@*/
|
@*/
|
||||||
|
|
||||||
Ox.toCamelCase = function(str) {
|
Ox.toCamelCase = function(str) {
|
||||||
return str.replace(/[\-_\/][a-z]/g, function(str) {
|
return str.replace(/[\-\/_][a-z]/g, function(str) {
|
||||||
return str[1].toUpperCase();
|
return str[1].toUpperCase();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue