lazyload.js 952 B

1234567891011121314151617181920212223242526272829303132
  1. QUnit.test( 'lazyload', function( assert ) {
  2. 'use strict';
  3. var done = assert.async();
  4. var gallery = document.querySelector('#lazyload');
  5. var flkty = new Flickity( gallery, {
  6. lazyLoad: 1
  7. });
  8. var loadCount = 0;
  9. flkty.on( 'lazyLoad', function( event, cellElem ) {
  10. loadCount++;
  11. assert.equal( event.type, 'load', 'event.type == load' );
  12. assert.ok( event.target.complete, 'img ' + loadCount + ' is complete' );
  13. assert.ok( cellElem, 'cellElement argument there' );
  14. var lazyAttr = event.target.getAttribute('data-flickity-lazyload');
  15. assert.ok( !lazyAttr, 'data-flickity-lazyload attribute removed' );
  16. // after first 2 have loaded, select 7th cell
  17. if ( loadCount == 2 ) {
  18. flkty.select( 6 );
  19. }
  20. if ( loadCount == 5 ) {
  21. var loadedImgs = gallery.querySelectorAll('.flickity-lazyloaded');
  22. assert.equal( loadedImgs.length, '5', 'only 5 images loaded' );
  23. done();
  24. }
  25. });
  26. });