Skip to content

Instantly share code, notes, and snippets.

@andymantell
Created November 21, 2014 10:48
Show Gist options
  • Save andymantell/0246d61efb0d4bb5a1f0 to your computer and use it in GitHub Desktop.
Save andymantell/0246d61efb0d4bb5a1f0 to your computer and use it in GitHub Desktop.
'use strict';
var lazy_load_image = require('../plugins/lazy-load-image.js');
var domready = require('detect-dom-ready');
var pubsub = require('pubsub-js');
// @TODO: This should only load images which are visible by default, not things that are inside hidden tabs etc
// @TODO: This loop probably belongs inside the plugin, not here
// @TODO: Select via data attributes instead of classes assuming IE8 supports this?
function process(element) {
var images = element.getElementsByClassName('image');
var count = images.length;
for (var i=0; i < count; i++) {
var instance = lazy_load_image(images[i]);
instance.init();
}
}
domready(function() {
process(document);
});
pubsub.subscribe('domupdated', function(msg, element) {
process(element);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment