includes/clientside/ie-png.js
author Dan
Mon, 28 Dec 2009 16:52:41 -0500
changeset 335 59fee40b4644
parent 294 444c34a3886b
permissions -rw-r--r--
Fixed a couple non-security sanitizer and editor bugs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
294
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
     1
// ScriptingMagic PNG hack for IE
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
     2
// Source: http://www.scriptingmagic.com/Topics/IE%20Specific/PNG%20Transparency/
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
     3
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
     4
if ( typeof ScriptingMagic == "undefined" )
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
     5
{
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
     6
  var ScriptingMagic = {}
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
     7
}
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
     8
ScriptingMagic.fixPNG = function() {};
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
     9
var smFixPNGOnload = (
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    10
  function()
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    11
  {
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    12
    if ( !document.all || window.opera )
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    13
    {
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    14
      return;
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    15
    }
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    16
    var a = parseFloat(navigator.appVersion.match(/MSIE (\d.*)/)[1]);
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    17
    if ( ( a < 5.5 ) || ( a >= 7 ) )
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    18
    {
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    19
      return;
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    20
    }
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    21
    if ( document.styleSheets.length == 0 )
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    22
    {
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    23
      document.body.appendChild(document.createElement("style"));
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    24
    }
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    25
    var src_clause = 'src=\'"+this.nextSibling.src.replace(/\'/g,"%27")+"\')"';
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    26
    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 + ');');
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    27
    window.ScriptingMagic.fixPNG = function(b)
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    28
    {
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    29
      b.style.filter="alpha(opacity=0)";
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    30
      var c = document.createElement("div");
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    31
      c.className = "sm-iepng-backdrop";
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    32
      if ( b.currentStyle.position.match(/^static$/i) )
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    33
      {
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    34
        b.style.position = "relative";
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    35
      }
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    36
      b.parentNode.insertBefore(c,b);
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    37
      c = null
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    38
    };
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    39
    var b = [], c, d, e, f;
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    40
    var g = document.getElementsByTagName("img");
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    41
    for ( c = 0, d = g.length; c < d; c++ )
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    42
    {
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    43
      b[b.length] = g[c];
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    44
    }
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    45
    var h = document.getElementsByTagName("input");
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    46
    for ( c = 0, d = h.length; c < d; c++ )
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    47
    {
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    48
      e = h[c];
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    49
      if ( e.type && e.type.match(/^image$/i) )
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    50
      {
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    51
        b[b.length] = e;
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    52
      }
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    53
    }
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    54
    for ( c = 0, d = b.length; c < d; c++ )
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    55
    {
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    56
      e = b[c];
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    57
      window.ScriptingMagic.fixPNG(e);
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    58
    }
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    59
    a = b = c = d = e = f = g = h = null;
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    60
  }
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    61
);
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    62
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    63
addOnloadHook(smFixPNGOnload);
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    64
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    65
ScriptingMagic.fixPNG.version = 1.4;
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    66
ScriptingMagic.fixPNG.release = new Date("Jan 1, 2007");
444c34a3886b Rebrand as 1.0.5 (Ferrishyn)
Dan
parents:
diff changeset
    67