Ewan Mellor  >  JavaScript  >  pngfix.js

 

· pngfix.js ·

   1/*                                                                              
                                                                                    
    pngfix.js.  Version 1.3.                                                        
                                                                                    
   5Copyright (c) 2002-2004 Ewan Mellor.  All rights reserved.                      
                                                                                    
    This software is covered by the MIT Licence                                     
    <http://www.opensource.org/licenses/mit-license.html>:                          
                                                                                    
  10  Permission is hereby granted, free of charge, to any person obtaining a copy  
      of this software and associated documentation files (the "Software"), to      
      deal in the Software without restriction, including without limitation the    
      rights to use, copy, modify, merge, publish, distribute, sublicense, and/or   
      sell copies of the Software, and to permit persons to whom the Software is    
  15  furnished to do so, subject to the following conditions:                      
                                                                                    
        The above copyright notice and this permission notice shall be included in  
        all copies or substantial portions of the Software.                         
                                                                                    
  20    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,    
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL     
        THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER  
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING     
  25    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER         
        DEALINGS IN THE SOFTWARE.                                                   
                                                                                    
                                                                                    
    This file may be obtained from <http://www.ewanmellor.org.uk/javascript/>.      
  30                                                                                
    This file depends upon sniffer.js by Eric Krok, Andy King, and Michel           
    Plungjan.                                                                       
                                                                                    
    To use this file, simply call fixPNGs from your page's onload event handler:    
  35                                                                                
      <html>                                                                        
       <head>                                                                       
        <script type="text/javascript" src="sniffer.js"></script>                   
        <script type="text/javascript" src="pngfix.js"></script>                    
  40   </head>                                                                      
       <body onload="javascript:fixPNGs()">                                         
        ...                                                                         
                                                                                    
                                                                                    
  45All images must have their size specified in the <img> tag.  There must also    
    be a single pixel transparent GIF available as given below.                     
                                                                                    
    */                                                                              
                                                                                    
  50var SPACER = "/spacer1x1.gif";                                                  
                                                                                    
                                                                                    
    function fixPNGs()                                                              
    {                                                                               
  55  var images = document.images;                                                 
      var i;                                                                        
                                                                                    
      if (is_ie5_5up && is_win32)                                                   
      {                                                                             
  60    for (i = 0; i < images.length; i++)                                         
        {                                                                           
          fixPNG(images[i]);                                                        
        }                                                                           
        setTimeout("showPNGs()", 200);                                              
  65  }                                                                             
      else                                                                          
      {                                                                             
        for (i = 0; i < images.length; i++)                                         
        {                                                                           
  70      images[i].style.visibility = "visible";                                   
        }                                                                           
      }                                                                             
    }                                                                               
                                                                                    
  75                                                                                
    function fixPNG(element)                                                        
    {                                                                               
      if (element.style.visibility == "hidden")                                     
      {                                                                             
  80    element.style.filter =                                                      
          "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" +              
          element.src + "',sizingMethod='image') " +                                
          "revealTrans(transition=12,duration=0.5)";                                
      }                                                                             
  85  else                                                                          
      {                                                                             
        element.style.filter =                                                      
          "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" +              
          element.src + "',sizingMethod='image')";                                  
  90  }                                                                             
                                                                                    
      element.src = SPACER;                                                         
    }                                                                               
                                                                                    
  95                                                                                
    function showPNGs()                                                             
    {                                                                               
      var images = document.images;                                                 
      var i;                                                                        
 100                                                                                
      for (i = 0; i < images.length; i++)                                           
      {                                                                             
        showPNG(images[i]);                                                         
      }                                                                             
 105}                                                                               
                                                                                    
                                                                                    
    function showPNG(element)                                                       
    {                                                                               
 110  if (element.style.visibility == "hidden")                                     
      {                                                                             
        element.filters[1].Apply();                                                 
        element.style.visibility = "visible";                                       
        element.filters[1].Play();                                                  
 115  }                                                                             
    }                                                                               
    

· pngfix.js ends ·

Generated by CHIP: Code Highlighting in PHP, version 2.7.0.