Skip to content

Commit

Permalink
Fix tests so they work with jQuery>2.0 as well as the older versions
Browse files Browse the repository at this point in the history
Changed .live handlers to .click etc that works in all jQuery versions
  • Loading branch information
hankhero authored and rstacruz committed Apr 24, 2014
1 parent 20d19af commit f059785
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
1 change: 1 addition & 0 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<body>
<div class='use'>
Use:
<a href='index.html?jquery=2.0.3'>jQ 2.0.3</a>
<a href='index.html?jquery=1.9.0b1'>jQ 1.9.0b1</a>
<a href='index.html?jquery=1.8.1'>jQ 1.8</a>
<a href='index.html?jquery=1.7.0'>jQ 1.7</a>
Expand Down
43 changes: 25 additions & 18 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
(function($) {
/* Simple test framework of sorts */
$('.test').live('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').live('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');
}
});

$('.play-all').live('click', function() {
$('.test').trigger('play');
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) {
Expand All @@ -36,6 +42,7 @@
$test.find('h3').html(name);
$test.find('pre').text(code);
$test.data('code', {fn: fn});
addTestEvents($test);

$('.tests').append($test);
}
Expand Down

0 comments on commit f059785

Please sign in to comment.