includes/clientside/ie-png.js
author Dan
Sat, 21 Mar 2009 18:58:41 -0400
changeset 329 e48b1937dfc3
parent 294 444c34a3886b
permissions -rw-r--r--
Merging nighthawk and scribus branches

// ScriptingMagic PNG hack for IE
// Source: http://www.scriptingmagic.com/Topics/IE%20Specific/PNG%20Transparency/

if ( typeof ScriptingMagic == "undefined" )
{
  var ScriptingMagic = {}
}
ScriptingMagic.fixPNG = function() {};
var smFixPNGOnload = (
  function()
  {
    if ( !document.all || window.opera )
    {
      return;
    }
    var a = parseFloat(navigator.appVersion.match(/MSIE (\d.*)/)[1]);
    if ( ( a < 5.5 ) || ( a >= 7 ) )
    {
      return;
    }
    if ( document.styleSheets.length == 0 )
    {
      document.body.appendChild(document.createElement("style"));
    }
    var src_clause = 'src=\'"+this.nextSibling.src.replace(/\'/g,"%27")+"\')"';
    document.styleSheets[document.styleSheets.length-1].addRule(".sm-iepng-backdrop", 'position: absolute; z-index: expression(this.nextSibling.currentStyle.zIndex); top: expression(this.nextSibling.offsetTop); left: expression(this.nextSibling.offsetLeft); height: expression(this.nextSibling.offsetHeight); width: expression(this.nextSibling.offsetWidth); filter: expression("progid:DXImageTransform.Microsoft.AlphaImageLoader(' + src_clause + ');');
    window.ScriptingMagic.fixPNG = function(b)
    {
      b.style.filter="alpha(opacity=0)";
      var c = document.createElement("div");
      c.className = "sm-iepng-backdrop";
      if ( b.currentStyle.position.match(/^static$/i) )
      {
        b.style.position = "relative";
      }
      b.parentNode.insertBefore(c,b);
      c = null
    };
    var b = [], c, d, e, f;
    var g = document.getElementsByTagName("img");
    for ( c = 0, d = g.length; c < d; c++ )
    {
      b[b.length] = g[c];
    }
    var h = document.getElementsByTagName("input");
    for ( c = 0, d = h.length; c < d; c++ )
    {
      e = h[c];
      if ( e.type && e.type.match(/^image$/i) )
      {
        b[b.length] = e;
      }
    }
    for ( c = 0, d = b.length; c < d; c++ )
    {
      e = b[c];
      window.ScriptingMagic.fixPNG(e);
    }
    a = b = c = d = e = f = g = h = null;
  }
);

addOnloadHook(smFixPNGOnload);

ScriptingMagic.fixPNG.version = 1.4;
ScriptingMagic.fixPNG.release = new Date("Jan 1, 2007");