Created
November 21, 2014 10:48
-
-
Save andymantell/0246d61efb0d4bb5a1f0 to your computer and use it in GitHub Desktop.
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
'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