Skip to content
This repository has been archived by the owner on Feb 13, 2019. It is now read-only.

Commit

Permalink
Just brute force this shit
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Sinchok committed Sep 10, 2014
1 parent a488df7 commit ba04229
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions comcastify.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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';
Expand Down

0 comments on commit ba04229

Please sign in to comment.