Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
101 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,28 @@ | ||
test( 'basics', function() { | ||
QUnit.test( 'basics', function( assert ) { | ||
|
||
'use strict'; | ||
|
||
var elem = document.querySelector('#basics'); | ||
var images = elem.querySelectorAll('img'); | ||
var isCallbacked, isDone, isAlways, isAllProgressed; | ||
// stop(); | ||
var done = assert.async( 3 + images.length ); | ||
|
||
var imgLoader = new imagesLoaded( elem, function( obj ) { | ||
ok( true, 'callback function triggered' ); | ||
equal( imgLoader, obj, 'callback argument and instance match' ); | ||
isCallbacked = true; | ||
checkReady(); | ||
assert.ok( true, 'callback function triggered' ); | ||
assert.equal( imgLoader, obj, 'callback argument and instance match' ); | ||
done(); | ||
}); | ||
imgLoader.on( 'done', function() { | ||
ok( true, 'done event triggered' ); | ||
isDone = true; | ||
checkReady(); | ||
assert.ok( true, 'done event triggered' ); | ||
done(); | ||
}); | ||
imgLoader.on( 'always', function() { | ||
ok( true, 'always event triggered' ); | ||
isAlways = true; | ||
checkReady(); | ||
assert.ok( true, 'always event triggered' ); | ||
done(); | ||
}); | ||
|
||
var progressCount = 0; | ||
imgLoader.on( 'progress', function( loader, image ) { | ||
ok( image.isLoaded, 'image is loaded'); | ||
progressCount++; | ||
if ( progressCount >= images.length ) { | ||
equal( progressCount, images.length, 'progressed right amount of times' ); | ||
isAllProgressed = true; | ||
checkReady(); | ||
} | ||
assert.ok( image.isLoaded, 'image is loaded'); | ||
done(); | ||
}); | ||
|
||
stop(); | ||
|
||
function checkReady() { | ||
if ( isCallbacked && isDone && isAlways && isAllProgressed ) { | ||
start(); | ||
} | ||
} | ||
|
||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
test( 'data-uri', function() { | ||
QUnit.test( 'data-uri', function( assert ) { | ||
'use strict'; | ||
|
||
stop(); | ||
var done = assert.async(); | ||
imagesLoaded('#data-uri', { debug: true }).on( 'done', function( obj ) { | ||
ok( true, 'data-uri images loaded' ); | ||
equal( obj.images.length, 2, 'instance has 2 images' ); | ||
start(); | ||
assert.ok( true, 'data-uri images loaded' ); | ||
assert.equal( obj.images.length, 2, 'instance has 2 images' ); | ||
done(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,29 @@ | ||
test( 'jquery fail', function() { | ||
QUnit.test( 'jquery fail', function( assert ) { | ||
|
||
'use strict'; | ||
|
||
var $ = window.jQuery; | ||
var isCallbacked, isFailed, isAlways, isAllProgressed; | ||
var progressCount = 0; | ||
var $images = $('#jquery-fail img'); | ||
stop(); | ||
var done = assert.async( 3 + $images.length ); | ||
|
||
$('#jquery-fail').imagesLoaded( function( instance ) { | ||
ok( true, 'callback triggered' ); | ||
ok( instance instanceof imagesLoaded, 'instance instanceof imagesLoaded' ); | ||
isCallbacked = true; | ||
checkReady(); | ||
assert.ok( true, 'callback triggered' ); | ||
assert.ok( instance instanceof imagesLoaded, 'instance instanceof imagesLoaded' ); | ||
done(); | ||
}) | ||
.fail( function( instance ) { | ||
ok( true, 'done triggered' ); | ||
ok( instance instanceof imagesLoaded, 'instance instanceof imagesLoaded' ); | ||
isFailed = true; | ||
checkReady(); | ||
assert.ok( true, 'fail triggered' ); | ||
assert.ok( instance instanceof imagesLoaded, 'instance instanceof imagesLoaded' ); | ||
done(); | ||
}) | ||
.always( function( instance ) { | ||
ok( true, 'always triggered' ); | ||
ok( instance instanceof imagesLoaded, 'instance instanceof imagesLoaded' ); | ||
isAlways = true; | ||
checkReady(); | ||
assert.ok( true, 'always triggered' ); | ||
assert.ok( instance instanceof imagesLoaded, 'instance instanceof imagesLoaded' ); | ||
done(); | ||
}) | ||
.progress( function() { | ||
progressCount++; | ||
if ( progressCount >= $images.length ) { | ||
equal( progressCount, $images.length, 'progressed iterations matches images length' ); | ||
isAllProgressed = true; | ||
checkReady(); | ||
} | ||
.progress( function(/* instance, image */) { | ||
assert.ok( true, 'progress trigged'); | ||
done(); | ||
}); | ||
|
||
function checkReady() { | ||
if ( isCallbacked && isFailed && isAlways && isAllProgressed ) { | ||
start(); | ||
} | ||
} | ||
|
||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,28 @@ | ||
test( 'jquery success', function() { | ||
QUnit.test( 'jquery success', function( assert ) { | ||
|
||
'use strict'; | ||
|
||
var $ = window.jQuery; | ||
var isCallbacked, isDone, isAlways, isAllProgressed; | ||
var progressCount = 0; | ||
stop(); | ||
var done = assert.async( 6 ); | ||
|
||
$('#jquery-success').imagesLoaded( function( instance ) { | ||
ok( true, 'callback triggered' ); | ||
ok( instance instanceof imagesLoaded, 'instance instanceof imagesLoaded' ); | ||
isCallbacked = true; | ||
checkReady(); | ||
assert.ok( true, 'callback triggered' ); | ||
assert.ok( instance instanceof imagesLoaded, 'instance instanceof imagesLoaded' ); | ||
done(); | ||
}) | ||
.done( function( instance ) { | ||
ok( true, 'done triggered' ); | ||
ok( instance instanceof imagesLoaded, 'instance instanceof imagesLoaded' ); | ||
isDone = true; | ||
checkReady(); | ||
assert.ok( true, 'done triggered' ); | ||
assert.ok( instance instanceof imagesLoaded, 'instance instanceof imagesLoaded' ); | ||
done(); | ||
}) | ||
.always( function( instance ) { | ||
ok( true, 'always triggered' ); | ||
ok( instance instanceof imagesLoaded, 'instance instanceof imagesLoaded' ); | ||
isAlways = true; | ||
checkReady(); | ||
assert.ok( true, 'always triggered' ); | ||
assert.ok( instance instanceof imagesLoaded, 'instance instanceof imagesLoaded' ); | ||
done(); | ||
}) | ||
.progress( function( instance, image ) { | ||
ok( image.isLoaded, 'image is loaded'); | ||
progressCount++; | ||
if ( progressCount >= 3 ) { | ||
equal( progressCount, 3, 'progressed 3 times' ); | ||
isAllProgressed = true; | ||
checkReady(); | ||
} | ||
assert.ok( image.isLoaded, 'progress trigged, image is loaded'); | ||
done(); | ||
}); | ||
|
||
function checkReady() { | ||
if ( isCallbacked && isDone && isAlways && isAllProgressed ) { | ||
start(); | ||
} | ||
} | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,31 @@ | ||
test( 'local files', function() { | ||
|
||
QUnit.test( 'local files', function( assert ) { | ||
'use strict'; | ||
|
||
var elem = document.querySelector('#locals'); | ||
var isCallbacked, isFailed, isAlways, isAllProgressed; | ||
// stop(); | ||
var done = assert.async( 6 ); | ||
|
||
var imgLoader = new imagesLoaded( elem, function( obj ) { | ||
ok( true, 'callback function triggered' ); | ||
equal( imgLoader, obj, 'callback argument and instance match' ); | ||
isCallbacked = true; | ||
checkReady(); | ||
assert.ok( true, 'callback function triggered' ); | ||
assert.equal( imgLoader, obj, 'callback argument and instance match' ); | ||
done(); | ||
}); | ||
imgLoader.on( 'fail', function() { | ||
ok( true, 'fail event triggered' ); | ||
isFailed = true; | ||
checkReady(); | ||
assert.ok( true, 'fail event triggered' ); | ||
done(); | ||
}); | ||
imgLoader.on( 'always', function() { | ||
ok( true, 'always event triggered' ); | ||
isAlways = true; | ||
checkReady(); | ||
assert.ok( true, 'always event triggered' ); | ||
done(); | ||
}); | ||
|
||
var progressCount = 0; | ||
imgLoader.on( 'progress', function( loader, image ) { | ||
ok( true, 'image progressed'); | ||
assert.ok( true, 'image progressed'); | ||
if ( image.img.src.indexOf('img/not-there.jpg') !== -1 ) { | ||
ok( !image.isLoaded, 'thunder cloud is not loaded' ); | ||
assert.ok( !image.isLoaded, 'thunder cloud is not loaded' ); | ||
} else { | ||
ok( image.isLoaded, 'image is loaded' ); | ||
} | ||
progressCount++; | ||
if ( progressCount >= 3 ) { | ||
equal( progressCount, 3, 'progressed 3 times' ); | ||
isAllProgressed = true; | ||
checkReady(); | ||
assert.ok( image.isLoaded, 'image is loaded' ); | ||
} | ||
done(); | ||
}); | ||
|
||
stop(); | ||
|
||
function checkReady() { | ||
if ( isCallbacked && isFailed && isAlways && isAllProgressed ) { | ||
start(); | ||
} | ||
} | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
test( 'no images', function() { | ||
|
||
QUnit.test( 'no images', function( assert ) { | ||
'use strict'; | ||
|
||
var elem = document.querySelector('#no-images'); | ||
stop(); | ||
var done = assert.async(); | ||
imagesLoaded( elem, function() { | ||
ok( true, 'triggered with no images' ); | ||
start(); | ||
assert.ok( true, 'triggered with no images' ); | ||
done(); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,24 @@ | ||
test( 'dismiss non-element nodes', function() { | ||
|
||
QUnit.test( 'dismiss non-element nodes', function( assert ) { | ||
'use strict'; | ||
|
||
var $ = window.jQuery; | ||
stop(); | ||
var done = assert.async( 2 ); | ||
|
||
$(' <img src="http://lorempixel.com/401/301/" /> <img src="http://lorempixel.com/402/302/" /> ') | ||
.imagesLoaded(function() { | ||
ok( true, 'elements from jQuery string ok' ); | ||
start(); | ||
testFrag(); | ||
assert.ok( true, 'elements from jQuery string ok' ); | ||
done(); | ||
}); | ||
|
||
function testFrag() { | ||
stop(); | ||
var frag = document.createDocumentFragment(); | ||
var img = new Image(); | ||
img.src = 'http://lorempixel.com/403/303/'; | ||
frag.appendChild( img ); | ||
var imgLoad = imagesLoaded( frag, function() { | ||
ok( true, 'document fragment ok' ); | ||
equal( imgLoad.images.length, 1, '1 image found' ); | ||
start(); | ||
}); | ||
} | ||
// test fragment | ||
var frag = document.createDocumentFragment(); | ||
var img = new Image(); | ||
img.src = 'http://lorempixel.com/403/303/'; | ||
frag.appendChild( img ); | ||
var imgLoad = imagesLoaded( frag, function() { | ||
assert.ok( true, 'document fragment ok' ); | ||
assert.equal( imgLoad.images.length, 1, '1 image found' ); | ||
done(); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
test( 'selector string', function() { | ||
stop(); | ||
QUnit.test( 'selector string', function( assert ) { | ||
'use strict'; | ||
var images = document.querySelectorAll('#basics img'); | ||
var done = assert.async(); | ||
var imgLoad = imagesLoaded('#basics', { debug: true }).on( 'done', function( obj ) { | ||
ok( true, 'selector string worked' ); | ||
ok( obj.images, 'argument has images' ); | ||
equal( obj.images.length, images.length, 'images.length matches' ); | ||
start(); | ||
assert.ok( true, 'selector string worked' ); | ||
assert.ok( obj.images, 'argument has images' ); | ||
assert.equal( obj.images.length, images.length, 'images.length matches' ); | ||
done(); | ||
}); | ||
ok( imgLoad.options.debug, 'debug option set' ); | ||
assert.ok( imgLoad.options.debug, 'debug option set' ); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
test( 'single element', function() { | ||
QUnit.test( 'single element', function( assert ) { | ||
'use strict'; | ||
var elem = document.querySelector('#mario-with-shell'); | ||
stop(); | ||
var done = assert.async(); | ||
imagesLoaded( elem ).on( 'done', function( obj ) { | ||
ok( true, 'single element worked' ); | ||
ok( obj.images, 'argument has images' ); | ||
equal( obj.images.length, 1, 'images.length = 1' ); | ||
start(); | ||
assert.ok( true, 'single element worked' ); | ||
assert.ok( obj.images, 'argument has images' ); | ||
assert.equal( obj.images.length, 1, 'images.length = 1' ); | ||
done(); | ||
}); | ||
}); |