Advertisement
Guest User

Untitled

a guest
Jul 17th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. add: function(src, rel) {
  2.     if (this.cache[src]) {
  3.         return this.cache[src];
  4.     }
  5.     if (this.cache[rel]) {
  6.     return this.cache[rel];
  7.     }
  8.  
  9.     // The only "rel" value in this function is what you're passing to the "rel" parameter.
  10.     alert( rel ); // take a look at the value
  11.  
  12.     // create a new image
  13.     var image = new Image();
  14.  
  15.     // assign the src
  16.     image.src = src;
  17.  
  18.     // assign the rel. Apparently we need to assign both the property and attribute separately
  19.     image.rel = rel;
  20.     image.setAttribute('rel',rel);
  21.  
  22.        // set the style of the image
  23.     this.setStyle(image, {display: 'block'});
  24.  
  25.        // go ahead and return the image if it is already loaded
  26.     if (image.complete && image.width) {
  27.         return image;
  28.     }
  29.        // If we get this far, the image wasn't loaded yet, so we assign an "onload" handler
  30.     image.onload = (function(scope) {
  31.         return function() {
  32.             scope.cache[src] = image;
  33.         };
  34.     })(this);
  35.    
  36.        // return the image
  37.     return image;
  38. },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement