From ba042295e446dea9930bbaf8b8a242a648a35197 Mon Sep 17 00:00:00 2001 From: Chris Sinchok Date: Wed, 10 Sep 2014 11:10:05 -0500 Subject: [PATCH] Just brute force this shit --- comcastify.js | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/comcastify.js b/comcastify.js index e3610fe..69d833f 100644 --- a/comcastify.js +++ b/comcastify.js @@ -6,12 +6,27 @@ var comcastifyjs = (function () { // calculate new height var newTopClip = slowloadDiv.slothifyData.imageTopClip + args.loadIncrement; + var img = slowloadDiv.previousSibling; + slowloadDiv.style.width = img.offsetWidth + 'px'; + slowloadDiv.style.height = img.offsetHeight + 'px'; + slowloadDiv.style.top = img.offsetTop + 'px'; + slowloadDiv.style.left = img.offsetLeft + 'px'; // update slowload div slowloadDiv.style.clip = 'rect(' + newTopClip + 'px auto auto auto)'; + + if (!img.complete) { + setTimeout(slowloadModiferCallback(slowloadDiv, args), args.loadSpeed); + } + if (typeof img.naturalHeight !== "undefined" && img.naturalWidth === 0) { + setTimeout(slowloadModiferCallback(slowloadDiv, args), args.loadSpeed); + } + // check stopping conditions - if (newTopClip < slowloadDiv.slothifyData.maxImageHeight) { + var maxImageHeight = img.height * args.loadMaxPercent; + + if (!maxImageHeight || maxImageHeight === 0 || newTopClip < maxImageHeight) { // create new update timeout slowloadDiv.slothifyData.imageTopClip = newTopClip; setTimeout(slowloadModiferCallback(slowloadDiv, args), args.loadSpeed); @@ -32,24 +47,21 @@ var comcastifyjs = (function () { var slowImages = function (args) { return function () { var params = { + elements: args.elements || document.getElementsByTagName('img'), boxColor: args.boxColor || '#000000', // color of box overlay loadMaxPercent: args.loadMaxPercent || 0.0, // max percentage to load images loadSpeed: args.loadSpeed || 500, // how often in ms to pass loadIncrement: args.loadIncrement || 1 // pixels to load per pass }; - // grab all the images - var imgs = document.getElementsByTagName('img'); - // make 'em load slow - for(var i = 0; i < imgs.length; i++) { + for(var i = 0; i < params.elements.length; i++) { // get some things we need - var img = imgs[i], + var img = params.elements[i], parent = img.parentNode, slowload = document.createElement('DIV'); // set up initial state of box - slowload.className = 'sloth-box'; slowload.style.backgroundColor = params.boxColor; slowload.style.width = img.offsetWidth + 'px'; slowload.style.height = img.offsetHeight + 'px';