forked from rstacruz/jquery.transit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
65 lines (52 loc) · 1.74 KB
/
test.js
File metadata and controls
65 lines (52 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
(function($) {
/* Simple test framework of sorts */
function addTestEvents ($test) {
$test.bind('mouseenter play', function() {
var $test = $(this).closest('.test');
$test.trigger('reset');
var $box = $test.find('.box:not(.ghost)');
var $ghost = $box.clone().addClass('ghost').appendTo($test.find('.area'));
$test.data('code').fn($box, $test);
});
$test.bind('mouseleave reset', function() {
var $test = $(this).closest('.test');
var $ghost = $test.find('.ghost');
if ($ghost.length) {
$test.find('.box:not(.ghost)').remove();
$test.find('.ghost').removeClass('ghost');
}
});
}
$(document).ready(function () {
$('.play-all').bind('click', function() {
$('.test').trigger('play');
});
});
function test(name, fn) {
var i = $('.tests .test').length;
var $test = $('<div class="test"><h3></h3><div class="area"><div class="box"></div></div><pre class="code"></pre></div>');
var m = fn.toString().match(/\{([\s\S]*)\}$/);
var code = m[1];
code = code.replace(/^\s*|\s*$/g, '');
code = code.replace(/\n {4}/g, "\n");
name = name.replace(/\(.*\)/, function(n) { return "<em>"+n.substr(1,n.length-2)+"</em>"; });
$test.attr('id', 'test-'+i);
$test.find('h3').html(name);
$test.find('pre').text(code);
$test.data('code', {fn: fn});
addTestEvents($test);
$('.tests').append($test);
}
function group(name) {
$('.tests').append($('<h4 class="group-heading">').text(name));
}
// Show versions
$(function() {
$('#jquery-version').html(
'jQuery: v' + $.fn.jquery + '<br>' +
'Transit: v' + $.transit.version
);
});
window.group = group;
window.test = test;
})(jQuery);