Sha256: e27ff0b785fc400b3a554b568ed6834f7503026c46c1e1e1576d4f5d9b933a7c

Contents?: true

Size: 1.77 KB

Versions: 24

Compression:

Stored size: 1.77 KB

Contents

var imgSizer = {
  Config : {
    imgCache : []
    ,spacer : "/path/to/your/spacer.gif"
  }

  ,collate : function(aScope) {
    var isOldIE = (document.all && !window.opera && !window.XDomainRequest) ? 1 : 0;
    if (isOldIE && document.getElementsByTagName) {
      var c = imgSizer;
      var imgCache = c.Config.imgCache;

      var images = (aScope && aScope.length) ? aScope : document.getElementsByTagName("img");
      for (var i = 0; i < images.length; i++) {
        images[i].origWidth = images[i].offsetWidth;
        images[i].origHeight = images[i].offsetHeight;

        imgCache.push(images[i]);
        c.ieAlpha(images[i]);
        images[i].style.width = "100%";
      }

      if (imgCache.length) {
        c.resize(function() {
          for (var i = 0; i < imgCache.length; i++) {
            var ratio = (imgCache[i].offsetWidth / imgCache[i].origWidth);
            imgCache[i].style.height = (imgCache[i].origHeight * ratio) + "px";
          }
        });
      }
    }
  }

  ,ieAlpha : function(img) {
    var c = imgSizer;
    if (img.oldSrc) {
      img.src = img.oldSrc;
    }
    var src = img.src;
    img.style.width = img.offsetWidth + "px";
    img.style.height = img.offsetHeight + "px";
    img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='scale')"
    img.oldSrc = src;
    img.src = c.Config.spacer;
  }

  // Ghettomodified version of Simon Willison's addLoadEvent() -- http://simonwillison.net/2004/May/26/addLoadEvent/
  ,resize : function(func) {
    var oldonresize = window.onresize;
    if (typeof window.onresize != 'function') {
      window.onresize = func;
    } else {
      window.onresize = function() {
        if (oldonresize) {
          oldonresize();
        }
        func();
      }
    }
  }
}

Version data entries

24 entries across 14 versions & 1 rubygems

Version Path
survivalkit-1.0.beta.8 templates/drupal/libs/320-up/imgSizer.js
survivalkit-1.0.beta.8 templates/project/libs/320-up/imgSizer.js
survivalkit-1.0.beta.7 templates/drupal/libs/320-up/imgSizer.js
survivalkit-1.0.beta.7 templates/project/libs/320-up/imgSizer.js
survivalkit-1.0.beta.6 templates/project/libs/320-up/imgSizer.js
survivalkit-1.0.beta.6 templates/drupal/libs/320-up/imgSizer.js
survivalkit-1.0.beta.5 templates/drupal/libs/320-up/imgSizer.js
survivalkit-1.0.beta.5 templates/project/libs/320-up/imgSizer.js
survivalkit-1.0.beta.4 templates/drupal/libs/320-up/imgSizer.js
survivalkit-1.0.beta.4 templates/project/libs/320-up/imgSizer.js
survivalkit-1.0.beta.3 templates/project/libs/320-up/imgSizer.js
survivalkit-1.0.beta.3 templates/drupal/libs/320-up/imgSizer.js
survivalkit-1.0.beta.2 templates/drupal/libs/320-up/imgSizer.js
survivalkit-1.0.beta.2 templates/project/libs/320-up/imgSizer.js
survivalkit-1.0.beta.1 templates/project/libs/320-up/imgSizer.js
survivalkit-1.0.beta.1 templates/drupal/libs/320-up/imgSizer.js
survivalkit-0.3.4 templates/project/libs/320-up/imgSizer.js
survivalkit-0.3.4 templates/drupal/libs/320-up/imgSizer.js
survivalkit-0.3.3 templates/drupal/libs/320-up/imgSizer.js
survivalkit-0.3.3 templates/project/libs/320-up/imgSizer.js