minor cleanup

This commit is contained in:
rolux 2012-05-25 13:42:33 +02:00
parent b1ff236b3f
commit e47f826329
4 changed files with 15 additions and 18 deletions

View file

@ -1,4 +1,5 @@
'use strict'; 'use strict';
/*@ /*@
Ox.cache <f> Memoize a function Ox.cache <f> Memoize a function
<script> <script>

View file

@ -145,12 +145,12 @@
{lat: 0, lng: 0} {lat: 0, lng: 0}
@*/ @*/
Ox.getLatLngByXY = function(xy) { Ox.getLatLngByXY = function(xy) {
function getVal(val) { function getValue(value) {
return (val - 0.5) * 2 * Math.PI; return (value - 0.5) * 2 * Math.PI;
} }
return { return {
lat: -Ox.deg(Math.atan(Ox.sinh(getVal(xy.y)))), lat: -Ox.deg(Math.atan(Ox.sinh(getValue(xy.y)))),
lng: Ox.deg(getVal(xy.x)) lng: Ox.deg(getValue(xy.x))
}; };
}; };
@ -213,12 +213,12 @@
{x: 0.5, y: 0.5} {x: 0.5, y: 0.5}
@*/ @*/
Ox.getXYByLatLng = function(latlng) { Ox.getXYByLatLng = function(latlng) {
function getVal(val) { function getValue(value) {
return (val / (2 * Math.PI) + 0.5) return (value / (2 * Math.PI) + 0.5);
} }
return { return {
x: getVal(Ox.rad(latlng.lng)), x: getValue(Ox.rad(latlng.lng)),
y: getVal(Ox.asinh(Math.tan(Ox.rad(-latlng.lat)))) y: getValue(Ox.asinh(Math.tan(Ox.rad(-latlng.lat))))
}; };
}; };

View file

@ -45,7 +45,6 @@ Ox.parseHTML <f> Takes HTML from an untrusted source and returns something sane
> Ox.parseHTML('<b>foo</b></b>') > Ox.parseHTML('<b>foo</b></b>')
'<b>foo</b>' '<b>foo</b>'
@*/ @*/
Ox.parseHTML = (function() { Ox.parseHTML = (function() {
var defaultTags = [ var defaultTags = [
// inline formatting // inline formatting
@ -141,9 +140,9 @@ Ox.parseURL = (function() {
var a = document.createElement('a'), var a = document.createElement('a'),
keys = ['hash', 'host', 'hostname', 'origin', keys = ['hash', 'host', 'hostname', 'origin',
'pathname', 'port', 'protocol', 'search']; 'pathname', 'port', 'protocol', 'search'];
return function(str) { return function(string) {
var ret = {}; var ret = {};
a.href = str; a.href = string;
keys.forEach(function(key) { keys.forEach(function(key) {
ret[key] = a[key]; ret[key] = a[key];
}); });
@ -167,14 +166,10 @@ Ox.parseURLs <f> Takes HTML and turns URLs into links
Ox.parseURLs = function(html) { Ox.parseURLs = function(html) {
return html.replace( return html.replace(
/\b((https?:\/\/|www\.).+?)([\.,:;!\?\)\]]*?(\s|$))/gi, /\b((https?:\/\/|www\.).+?)([\.,:;!\?\)\]]*?(\s|$))/gi,
function(str, url, pre, end) { function(string, url, prefix, end) {
url = (pre == 'www.' ? 'http://' : '' ) + url; url = (prefix == 'www.' ? 'http://' : '') + url;
return Ox.formatString( return Ox.formatString(
'<a href="{url}">{url}</a>{end}', '<a href="{url}">{url}</a>{end}', {end: end, url: url}
{
end: end,
url: url
}
); );
} }
); );

View file

@ -94,4 +94,5 @@ Ox.oshash = function(file, callback) {
} }
reader.readAsBinaryString(blob); reader.readAsBinaryString(blob);
} }
}; };