Skip to content

Merge branch #13

Merged
merged 2 commits into from Apr 17, 2012
View
21 foresight.js
@@ -67,6 +67,12 @@
initImageRebuild();
},
+
+ triggerImageEvent = function(eventName, img){
+ var event = document.createEvent("Event");
+ event.initEvent("foresight-" + eventName, true, true);
+ img.dispatchEvent(event);
+ },
initImages = function () {
// loop through each of the document.images and find valid foresight images
@@ -83,6 +89,8 @@
// only gather the images that haven't already been initialized
if ( img.initalized ) continue;
+ triggerImageEvent("imageInitStart", img);
+
img.initalized = TRUE;
img.orgSrc = getDataAttribute( img, 'src' ); // important, do not set the src attribute yet!
@@ -115,6 +123,8 @@
// handle any response errors which may happen with this image
img.onerror = imgResponseError;
+ triggerImageEvent("imageInitEnd", img);
+
// add this image to the collection
foresight.images.push( img );
}
@@ -240,6 +250,8 @@
// parent element is not visible (yet anyways) so don't continue with this img
continue;
}
+
+ triggerImageEvent("imageRebuildStart", img);
// build a list of CSS Classnames for the <img> which may be useful
classNames = img.orgClassName.split( ' ' );
@@ -252,10 +264,13 @@
// we can then add those CSS dimension classnames to the document and do less repaints
dimensionClassName = 'fs-' + img[ BROWSER_WIDTH ] + 'x' + img[ BROWSER_HEIGHT ];
classNames.push( dimensionClassName );
-
+
+ if(dimensionCssRules[dimensionClassName] == undefined){
// build a list of CSS rules for all the different dimensions
// ie: .fs-640x480{width:640px;height:480px}
- dimensionCssRules.push( '.' + dimensionClassName + '{width:' + img[ BROWSER_WIDTH ] + 'px;height:' + img[ BROWSER_HEIGHT ] + 'px}' );
+ dimensionCssRules[dimensionClassName] = true;
+ dimensionCssRules.push('.' + dimensionClassName + '{width:' + img[ BROWSER_WIDTH ] + 'px;height:' + img[ BROWSER_HEIGHT ] + 'px}' );
+ }
}
// show the display to inline so it flows in the webpage like a normal img
@@ -327,6 +342,8 @@
// assign the new CSS classnames to the img
img.className = classNames.join( ' ' );
+
+ triggerImageEvent("imageRebuildEnd", img);
}
// if there were are imgs that need width/height assigned to them then
Something went wrong with that request. Please try again.