add Ox.Editable

This commit is contained in:
rolux 2011-08-12 23:00:42 +02:00
commit db4b33cf24
6 changed files with 121 additions and 48 deletions

View file

@ -4,7 +4,7 @@
<title>Ox.js Tests</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link rel="stylesheet" type="text/css" href="tests.css"/>
<script type="text/javascript" src="../build/js/Ox.js"></script>
<script type="text/javascript" src="../build/Ox.js"></script>
<!--<script type="text/javascript" src="../build/js/ox.data.js"></script>-->
<script type="text/javascript" src="tests.js"></script>
</head>

View file

@ -14,27 +14,75 @@ Ox.load('UI', function() {
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']
],
gradients = [
'-moz-linear-gradient(',
'-webkit-gradient(linear, '
];
setBackground($tests, true);
tests(['../build/js/Ox.js'/*, '../build/js/ox.data.js'*/]);
tests(['../build/Ox.js'/*, '../build/js/ox.data.js'*/]);
function tests() {
var succeeded = 0, failed = 0,
lines, spaces, command, expected, result, success,
replace = ['', ''], fns = [], $test
Ox.forEach(Ox.isArray(arguments[0]) ? arguments[0] : arguments, function(script, i) {
Ox.print(script, Ox)
Ox.test(script, function(results) {
var tests = {};
results.forEach(function(result) {
tests[result.section] = tests[result.section] || {};
tests[result.section][result.name] = tests[result.section][result.name] || [];
tests[result.section][result.name].push(result);
});
Ox.print('tests', tests)
Ox.forEach(tests, function(functions, section) {
Ox.Bar({size: 14})
.css({padding: '1px 0 1px 4px'})
.html(Ox.basename(script) + ' ' + section)
.appendTo($body);
Ox.forEach(functions, function(arr, fn) {
var $test = Ox.CollapsePanel({
collapsed: true,
title: fn + '()'
})
.appendTo($body);
setBackground($test.find('.OxBar'), true);
arr.forEach(function(test) {
succeeded += test.success;
failed += !test.success;
$tests.html(
(succeeded + failed) + ' tests, '
+ succeeded + ' succeeded, ' + failed + ' failed'
);
if (!test.success) {
setBackground($tests, false);
setBackground($test.find('.OxBar'), false);
}
Ox.Element()
.css({
padding: '2px 0 2px 4px',
background: 'rgb(' + colors[+test.success][2] + ')'
})
.html(
'<span style="font-family: Monaco">'
+ Ox.encodeHTML(test.statement) + ' '
+ (test.success ? '=' : '!') + '=&gt; '
+ Ox.encodeHTML(test.expected)
+ (test.success ? '' : ' ==&gt; ' + Ox.encodeHTML(test.actual))
+ '</tt>'
)
.appendTo($test.$content);
});
$test.$content.css({
marginTop: -$test.$content.height() + 'px'
});
});
});
})
/*
$.get(script, function(data) {
Ox.print(script, Ox)
new Ox.Bar({size: 17})
@ -62,10 +110,8 @@ Ox.load('UI', function() {
result = eval(command);
if (fn) {
fn = fn[fn.length - 1];
/*
success = typeof expected == 'object' ?
expected.toString() == result.toString() : expected === result;
*/
Ox.print('command:', command, 'expected:', expected, 'result:', result)
success = Ox.isEqual(expected, result);
succeeded += success;
@ -84,7 +130,6 @@ Ox.load('UI', function() {
.appendTo($body);
setBackground($test.find('.OxBar'), true);
}
///*
new Ox.Bar({size:17}) // fixme: Ox.Object() used to work
.css({
//padding: '2px 0 2px 8px',
@ -97,36 +142,28 @@ Ox.load('UI', function() {
(success ? '' : ' ==&gt; ' + Ox.encodeHTML(JSON.stringify(result))) + '</span>'
)
.appendTo($test.$content);
//*/
// to be fixed in ui:
// /*
$test.$content
.css({
marginTop: -$test.$content.height() + 'px'
});
//*/
// /*
if (!success) {
setBackground($test.find('.OxBar'), success);
}
//*/
} else {
replace = command.split(' = ')
}
}
});
}, 'html');
*/
});
}
//});
function setBackground($element, success) {
$.each(gradients, function(i, v) {
['-moz-linear-gradient', '-webkit-linear-gradient'].forEach(function(v) {
$element.css({
background: v + 'left top, left bottom, from(rgb(' +
colors[+success][0] + ')), to(rgb(' +
colors[+success][1] + ')))'
background: v + '(top, rgb(' +
colors[+success][0] + '), rgb(' +
colors[+success][1] + '))'
});
});
}