Location: PHPKode > scripts > rollover2 > rollover2/rollover2.php
<?PHP
/*
 * Filename.....: rollover2.php
 * Aufgabe......: Rollover Effekt mit buttons
 * Parameter....: none
 * Erstellt am..: 9. Mai 2002
 *       _  __      _ _
 *  ||| | |/ /     (_) |        Wirtschaftsinformatiker IHK
 * \. ./| ' / _ __  _| |_ ___   www.ingoknito.de
 * - ^ -|  < | '_ \| | __/ _ \  
 * / - \| . \| | | | | || (_) | Peter Klauer
 *  ||| |_|\_\_| |_|_|\__\___/  06131-651236
 * mailto.......: hide@address.com
 *
 * Changes:
 * 2003-01-24: function i_am_this_url() changed $PHP_SELF to $REQUEST_URI
 * 2002-10-11: Added support for 'rollovered' image maps
 * 2002-05-22: Three bugs corrected: 3 forgotten $this->es.
 *             The bugs were in preload() and image().
 *             Thanks to Cecilio Albero
 * 2002-05-20: Define global var $rollover2_class_loaded to stop
 *             errors when reloaded multiple times.
 *             This is PHP3 compatible behaviour. 
 * 2002-05-11: added downimg. This image is shown, when the linked page is the
 *             active page. No rollover effekt with this page, simple <img> only.
 *             Parameter shifting: downimg is insertet as the 4th parameter in
 *             addimage(). Parameters $alt, $link, $target and $layer are shifted
 *             to the right.
 */
if( !isset( $rollover2_class_loaded))
{
    $rollover2_class_loaded = 1; 
 
    class rollover2 
    {
      var $images = array(); // Array for all images
      var $imagedir = './images/'; // path to image files
      var $jsincludepath = './'; // path to javascript image.js  './' means actual directory
      var $window_defaultstatus = ''; // default status for status bar message
      
      function addimage( $imgname, $baseimg, $selimg, $downimg='', $alt='', $link='#', $target='', $layer='', $map='' )
      {
        $this->images[$imgname] = 
          array( 'layer' => $layer,     // the layer name if it is on a named layer
                 'baseimg' => $baseimg, // unselected image file
                 'selimg' => $selimg,   // selected image file
                 'downimg' => $downimg, // if $PHP_SELF is the link, show this image
                 'alt' => $alt,         // mouseover hint text
                 'link' => $link,       // url to document
                 'target' => $target,   // target window for new document
                 'map' => $map );       // client image map name <map name="my_name"><area ... /area></map>
      }
      
      function preload()
      {
        # MUST BE CALLED WITHIN <HEAD></HEAD> SECTION
        # includes images.js and defines preload script section
          
        echo '<script type="text/javascript" language="javascript" src="'. 
          $this->jsincludepath.'images.js"></script>'.
          '<script type="text/javascript" language="javascript">'."\n".
          # set window.defaultstatus for onmouseout=..
          "//<!--\nwindow.defaultStatus='".$this->window_defaultstatus."';\n";
        
        while( list( $key, $val ) = each( $this->images ) )
        {
          if( $val['downimg'] > '' && $this->i_am_this_url( $val['link'] ))
          {
            echo '// no preloads for '.$key.': url is '.$val['link']."\n";
          }
          else
          {
            echo "preload('$key"."bas','".$this->imagedir.$val['baseimg']."');\n" ;
            echo "preload('$key"."sel','".$this->imagedir.$val['selimg'] ."');\n" ;
          }
        }
        
        echo '//-->'."\n".'</script>'."\n";
      }
      
      function i_am_this_url( $url )
      {
        # global $PHP_SELF; changed 2003-01-24
				global $REQUEST_URI;
				$urll = strtolower( $url );
				$phps = strtolower( $REQUEST_URI );
				
        $shortest = strlen( $urll );
        $shortest = strlen( $phps ) < $shortest ? strlen( $phps ) : $shortest;
        return( substr($urll, -$shortest) == substr( $phps, -$shortest ) );
      }
      
      function image( $imgname )
      {
        $size = GetImageSize($this->imagedir . $this->images[$imgname]['baseimg'] ); 
        $l = $this->images[$imgname]['layer'] == '' ? 'null' : "'".$this->images[$imgname]['layer']."'";
        $t = $this->images[$imgname]['target'] == '' ? ' ' : ' target="'.$this->images[$imgname]['target'].'" ';
        $map = $this->images[$imgname]['map'] == '' ? '' : ' ISMAP USEMAP="#'.$this->images[$imgname]['map'].'" ';
    
        if( ($this->images[$imgname]['downimg'] > '') && 
            ($this->i_am_this_url( $this->images[$imgname]['link'] ) ) )
        {
            # show state 3: downimage ($this->link == reached)
            echo "<img name='". 
            $imgname . "' border=0 width=" . $size[0] . 
            " height=" . $size[1] .$map. " src='" . $this->imagedir .  
            $this->images[$imgname]['downimg'] . 
            "' alt='" . $this->images[$imgname]['alt'] . 
            "'>" ;
        }
        else
        {
            # show normal rollover image 
            echo '<a href="' . $this->images[$imgname]['link'].'"'.$t. 
            "onMouseOver=\"javascript:changeImage( $l ,'" . 
            $imgname ."','".$imgname . 
            "sel');".
            "window.status='".$this->images[$imgname]['alt']."';return true;\" ".
            "onMouseOut=\"javascript:changeImage( $l,'".
            $imgname ."','".$imgname . "bas');window.status='".
            $this->window_defaultstatus."';return true;\"><img name='" . 
            $imgname . "' border=0 width=" . $size[0] . 
            " height=" . $size[1] . $map. " src='" . $this->imagedir .  
            $this->images[$imgname]['baseimg'] . 
            "' alt='" . $this->images[$imgname]['alt'] . 
            "'></a>" ;
        } // normal rollover image
      } // end function image()
    } // end class rollover2
} // if( !isset( $rollover2_class_loaded))
?>
Return current item: rollover2