forked from 0x2620/oxjs
updating ox.js
This commit is contained in:
parent
28535be814
commit
d7fb9e3dad
6 changed files with 715 additions and 335 deletions
|
|
@ -12,51 +12,49 @@
|
|||
<script type="text/javascript" src="../build/js/jquery-1.3.2.js"></script>
|
||||
<script type="text/javascript" src="../build/js/ox.js"></script>
|
||||
<script>
|
||||
$(function() {
|
||||
var $body = $("body"),
|
||||
src = "http://khm0.google.com/kh/v=46&x=0&y=0&z=0",
|
||||
//src = "http://www.google.com/intl/en_ALL/images/logo.gif",
|
||||
//src = "http://www.google.com/favicon.ico",
|
||||
//src = "http://images.apple.com/global/nav/images/globalnavbg.png",
|
||||
//src = "http://a1.twimg.com/a/1257210731/images/logo.png",
|
||||
//src = "http://l.yimg.com/g/images/logo_home.png",
|
||||
//src = "http://www.libpng.org/pub/png/img_png/png-9passes.png"
|
||||
//src = "http://www.libpng.org/pub/png/img_png/libpng-88x31.png"
|
||||
//str = "¥€$",
|
||||
str = "H€₤₤O ₩OR₤D"
|
||||
;
|
||||
$.get("http://google.com", function(data) {
|
||||
var str = data; //data.substr(0, 2048);
|
||||
$("<img/>")
|
||||
$(function() {
|
||||
var $body = $('body'),
|
||||
src = 'v78.png'
|
||||
//src = 'http://khm0.google.com/kh/v=46&x=0&y=0&z=0',
|
||||
//src = 'http://www.google.com/intl/en_ALL/images/logo.gif',
|
||||
//src = 'http://www.google.com/favicon.ico',
|
||||
//src = 'http://images.apple.com/global/nav/images/globalnavbg.png',
|
||||
//src = 'http://a1.twimg.com/a/1257210731/images/logo.png',
|
||||
//src = 'http://l.yimg.com/g/images/logo_home.png',
|
||||
//src = 'http://www.libpng.org/pub/png/img_png/png-9passes.png'
|
||||
//src = 'http://www.libpng.org/pub/png/img_png/libpng-88x31.png'
|
||||
//str = '¥€$',
|
||||
str = 'H€₤₤O ₩OR₤D';
|
||||
|
||||
$('<img/>')
|
||||
.attr({
|
||||
src: src
|
||||
})
|
||||
.load(function() {
|
||||
var that = this;
|
||||
Ox.print('encoding');
|
||||
$('<img/>')
|
||||
.attr({
|
||||
src: src
|
||||
src: Ox.encodePNG(that, str)
|
||||
})
|
||||
.load(function() {
|
||||
var that = this;
|
||||
Ox.print("encoding");
|
||||
$("<img/>")
|
||||
.attr({
|
||||
src: Ox.encodePNG(that, str)
|
||||
})
|
||||
.load(function() {
|
||||
Ox.print("decoding");
|
||||
$("<div/>")
|
||||
.html("[decoding original, should throw an error] " + (function() {
|
||||
var ret;
|
||||
try {
|
||||
ret = Ox.decodePNG(that);
|
||||
ret = "[" + ret.length + " bytes] " + Ox.encodeHTML(ret);
|
||||
} catch (e) {
|
||||
ret = e.toString()
|
||||
}
|
||||
return ret;
|
||||
})() + "<br/>[decoding encoded, should return a string] " + Ox.encodeHTML(Ox.decodePNG(this)))
|
||||
.prependTo($body);
|
||||
})
|
||||
.appendTo($body);
|
||||
});
|
||||
Ox.print('decoding');
|
||||
$('<div/>')
|
||||
.html('[decoding original, should throw an error] ' + (function() {
|
||||
var ret;
|
||||
try {
|
||||
ret = Ox.decodePNG(that);
|
||||
ret = '[' + ret.length + ' bytes] ' + Ox.encodeHTML(ret);
|
||||
} catch (e) {
|
||||
ret = e.toString()
|
||||
}
|
||||
return ret;
|
||||
}()) + '<br/>[decoding encoded, should return a string] ' + Ox.encodeHTML(Ox.decodePNG(this)))
|
||||
.prependTo($body);
|
||||
})
|
||||
.appendTo($body);
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
<body></body>
|
||||
|
|
|
|||
|
|
@ -1,65 +1,67 @@
|
|||
$(function() {
|
||||
|
||||
var $body = $("body")
|
||||
var $body = $('body')
|
||||
.css({
|
||||
overflowY: "auto"
|
||||
overflowY: 'auto'
|
||||
}),
|
||||
$tests = new Ox.Bar({
|
||||
size: 20
|
||||
})
|
||||
.css({
|
||||
padding: "6px 0 6px 8px",
|
||||
fontSize: "16px",
|
||||
fontWeight: "bold"
|
||||
padding: '6px 0 6px 8px',
|
||||
fontSize: '16px',
|
||||
fontWeight: 'bold'
|
||||
})
|
||||
.appendTo($("body"));
|
||||
.appendTo($('body'));
|
||||
colors = [
|
||||
["255, 64, 64", "224, 32, 32", "240, 16, 16"],
|
||||
["64, 192, 64", "32, 160, 32", "40, 176, 48"],
|
||||
["96, 96, 255", "64, 64, 224", "80, 80, 240"]
|
||||
['255, 64, 64', '224, 32, 32', '240, 16, 16'],
|
||||
['64, 192, 64', '32, 160, 32', '40, 176, 48'],
|
||||
['96, 96, 255', '64, 64, 224', '80, 80, 240']
|
||||
],
|
||||
gradients = [
|
||||
"-moz-linear-gradient(",
|
||||
"-webkit-gradient(linear, "
|
||||
'-moz-linear-gradient(',
|
||||
'-webkit-gradient(linear, '
|
||||
];
|
||||
|
||||
setBackground($tests, true);
|
||||
|
||||
tests("../build/js/ox.js", "../build/js/ox.data.js");
|
||||
tests('../build/js/ox.js', '../build/js/ox.data.js');
|
||||
|
||||
function tests() {
|
||||
var succeeded = 0, failed = 0,
|
||||
lines, spaces, command, expected, result, success,
|
||||
replace = ["", ""], fns = [], $test
|
||||
replace = ['', ''], fns = [], $test
|
||||
$.each($.isArray(arguments[0]) ? arguments[0] : arguments, function(i, script) {
|
||||
$.get(script, function(data) {
|
||||
Ox.Bar({size: 17})
|
||||
.css({padding: "3px 0 0 8px"})
|
||||
new Ox.Bar({size: 17})
|
||||
.css({padding: '3px 0 0 8px'})
|
||||
.html(Ox.basename(script))
|
||||
.appendTo($body);
|
||||
lines = data.split("\n");
|
||||
lines = data.split('\n');
|
||||
$.each(lines, function(l, line) {
|
||||
if (line.indexOf("/*") > -1 && lines[l + 1].indexOf("====") > -1) {
|
||||
Ox.Bar({size: 17})
|
||||
.css({padding: "3px 0 0 24px"})
|
||||
if (line.indexOf('/*') > -1 && lines[l + 1].indexOf('====') > -1) {
|
||||
new Ox.Bar({size: 17})
|
||||
.css({padding: '3px 0 0 24px'})
|
||||
.html($.trim(lines[l + 2]))
|
||||
.appendTo($body);
|
||||
//setBackground(x, 2)
|
||||
}
|
||||
spaces = line.indexOf(">>> ");
|
||||
spaces = line.indexOf('>>> ');
|
||||
if (spaces > -1) {
|
||||
command = $.trim(line).substr(4).split(" // ")[0];
|
||||
command = $.trim(line).substr(4).split(' // ')[0];
|
||||
Ox.print('command:', command)
|
||||
fn = command.match(/Ox\.\w+/);
|
||||
expected = eval(lines[l + 1].substr(spaces, lines[l + 1].length));
|
||||
// fixme: if object, recursively check identity
|
||||
result = eval(command);
|
||||
if (fn) {
|
||||
fn = fn[0];
|
||||
success = typeof expected == "object" ?
|
||||
success = typeof expected == 'object' ?
|
||||
expected.toString() == result.toString() : expected === result;
|
||||
succeeded += success;
|
||||
failed += !success;
|
||||
$tests.html((succeeded + failed) + " tests, " +
|
||||
succeeded + " succeeded, " + failed + " failed");
|
||||
$tests.html((succeeded + failed) + ' tests, ' +
|
||||
succeeded + ' succeeded, ' + failed + ' failed');
|
||||
if (!success) {
|
||||
setBackground($tests, success);
|
||||
}
|
||||
|
|
@ -67,22 +69,22 @@ $(function() {
|
|||
fns.push(fn);
|
||||
$test = Ox.CollapsePanel({
|
||||
collapsed: true,
|
||||
title: fn + "()"
|
||||
title: fn + '()'
|
||||
})
|
||||
.appendTo($body);
|
||||
setBackground($test.find(".OxBar"), true);
|
||||
setBackground($test.find('.OxBar'), true);
|
||||
}
|
||||
///*
|
||||
Ox.Bar({size:17}) // fixme: Ox.Object() used to work
|
||||
new Ox.Bar({size:17}) // fixme: Ox.Object() used to work
|
||||
.css({
|
||||
//padding: "2px 0 2px 8px",
|
||||
background: "rgb(" + colors[+success][2] + ")"
|
||||
//padding: '2px 0 2px 8px',
|
||||
background: 'rgb(' + colors[+success][2] + ')'
|
||||
})
|
||||
.html(
|
||||
Ox.basename(script) + ", line " + l + ": <span style=\"font-weight: bold\">" +
|
||||
Ox.encodeHTML(command).replace(replace[0], replace[1]) + " " +
|
||||
(success ? "=" : "!") + "=> " + Ox.encodeHTML(expected.toString()) +
|
||||
(success ? "" : " ==> " + Ox.encodeHTML(result.toString())) + "</span>"
|
||||
Ox.basename(script) + ', line ' + l + ': <span style="font-weight: bold">' +
|
||||
Ox.encodeHTML(command).replace(replace[0], replace[1]) + ' ' +
|
||||
(success ? '=' : '!') + '=> ' + Ox.encodeHTML(expected.toString()) +
|
||||
(success ? '' : ' ==> ' + Ox.encodeHTML(result.toString())) + '</span>'
|
||||
)
|
||||
.appendTo($test.$content);
|
||||
//*/
|
||||
|
|
@ -90,16 +92,16 @@ $(function() {
|
|||
// /*
|
||||
$test.$content
|
||||
.css({
|
||||
marginTop: -$test.$content.height() + "px"
|
||||
marginTop: -$test.$content.height() + 'px'
|
||||
});
|
||||
//*/
|
||||
// /*
|
||||
if (!success) {
|
||||
setBackground($test.find(".OxBar"), success);
|
||||
setBackground($test.find('.OxBar'), success);
|
||||
}
|
||||
//*/
|
||||
} else {
|
||||
replace = command.split(" = ")
|
||||
replace = command.split(' = ')
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -110,9 +112,9 @@ $(function() {
|
|||
function setBackground($element, success) {
|
||||
$.each(gradients, function(i, v) {
|
||||
$element.css({
|
||||
background: v + "left top, left bottom, from(rgb(" +
|
||||
colors[+success][0] + ")), to(rgb(" +
|
||||
colors[+success][1] + ")))"
|
||||
background: v + 'left top, left bottom, from(rgb(' +
|
||||
colors[+success][0] + ')), to(rgb(' +
|
||||
colors[+success][1] + ')))'
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue