Skip to content
This repository

Merge branch #13

Merged
merged 2 commits into from about 2 years ago

2 participants

Thad Cox Adam Bradley
Thad Cox

fixed issues for #10 and #11

Adam Bradley adamdbradley merged commit cc56438 into from
Adam Bradley
Owner

I put a try/catch within the triggerImageEvent just to prevent the errors which IE8 was having. Would you be able to take a look at your triggerImageEvent function and make sure its works with IE?

Thad Cox
Thad Cox

It appears that IE8 will not allow custom events. The only way to support it is through a hack of using a standard event and passing custom properties on the event object http://stackoverflow.com/questions/2028456/how-to-fire-personal-event-in-javascript. The other option is to add a framework and start using their event model but that would increase the required weight. I suggest for the time being that the events are IE9+ support only. I'll commit code to make sure browsers that don't support custom events don't try to execute them shortly.

Thad Cox jmuthad referenced this pull request from a commit
Thad Cox Implemented fix to prevent IE8 from executing events it can't support…
… as discussed in Pull Request #13
7d580d4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 2 unique commits by 1 author.

Apr 17, 2012
Thad Cox Fixed duplicated css rules (issue #10) 0381aa0
Thad Cox Image Events Added (issue #11) 6c1a126
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 19 additions and 2 deletions. Show diff stats Hide diff stats

  1. +19 2 foresight.js
21 foresight.js
@@ -67,6 +67,12 @@
67 67
68 68 initImageRebuild();
69 69 },
  70 +
  71 + triggerImageEvent = function(eventName, img){
  72 + var event = document.createEvent("Event");
  73 + event.initEvent("foresight-" + eventName, true, true);
  74 + img.dispatchEvent(event);
  75 + },
70 76
71 77 initImages = function () {
72 78 // loop through each of the document.images and find valid foresight images
@@ -83,6 +89,8 @@
83 89 // only gather the images that haven't already been initialized
84 90 if ( img.initalized ) continue;
85 91
  92 + triggerImageEvent("imageInitStart", img);
  93 +
86 94 img.initalized = TRUE;
87 95
88 96 img.orgSrc = getDataAttribute( img, 'src' ); // important, do not set the src attribute yet!
@@ -115,6 +123,8 @@
115 123 // handle any response errors which may happen with this image
116 124 img.onerror = imgResponseError;
117 125
  126 + triggerImageEvent("imageInitEnd", img);
  127 +
118 128 // add this image to the collection
119 129 foresight.images.push( img );
120 130 }
@@ -240,6 +250,8 @@
240 250 // parent element is not visible (yet anyways) so don't continue with this img
241 251 continue;
242 252 }
  253 +
  254 + triggerImageEvent("imageRebuildStart", img);
243 255
244 256 // build a list of CSS Classnames for the <img> which may be useful
245 257 classNames = img.orgClassName.split( ' ' );
@@ -252,10 +264,13 @@
252 264 // we can then add those CSS dimension classnames to the document and do less repaints
253 265 dimensionClassName = 'fs-' + img[ BROWSER_WIDTH ] + 'x' + img[ BROWSER_HEIGHT ];
254 266 classNames.push( dimensionClassName );
255   -
  267 +
  268 + if(dimensionCssRules[dimensionClassName] == undefined){
256 269 // build a list of CSS rules for all the different dimensions
257 270 // ie: .fs-640x480{width:640px;height:480px}
258   - dimensionCssRules.push( '.' + dimensionClassName + '{width:' + img[ BROWSER_WIDTH ] + 'px;height:' + img[ BROWSER_HEIGHT ] + 'px}' );
  271 + dimensionCssRules[dimensionClassName] = true;
  272 + dimensionCssRules.push('.' + dimensionClassName + '{width:' + img[ BROWSER_WIDTH ] + 'px;height:' + img[ BROWSER_HEIGHT ] + 'px}' );
  273 + }
259 274 }
260 275
261 276 // show the display to inline so it flows in the webpage like a normal img
@@ -327,6 +342,8 @@
327 342
328 343 // assign the new CSS classnames to the img
329 344 img.className = classNames.join( ' ' );
  345 +
  346 + triggerImageEvent("imageRebuildEnd", img);
330 347 }
331 348
332 349 // if there were are imgs that need width/height assigned to them then

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.