html
[ class tree: html ] [ index: html ] [ all elements ]

Source for file OverInfo.class.php

Documentation is available at OverInfo.class.php

  1. <?php
  2. /**
  3.  * For including this file you have to define the constant "CLASSPATH".
  4.  * Because every include in the framework depends on the CLASSPATH definition.
  5.  * The CLASSPATH means the relative path to the folder that contains the
  6.  * framework GilliGan.
  7.  *
  8.  * @package    html
  9.  * @subpackage components
  10.  */
  11. if!defined"CLASSPATH" ) )
  12. {
  13.   echo "<h3>You have to define the constant CLASSPATH!</h3>\n";
  14.   echo "Example: define( 'CLASSPATH', '../path/to/classes/' );\n";
  15.   exit();
  16. }
  17.  
  18. /**
  19.  *
  20.  */
  21. require_onceCLASSPATH."html/HTMLSpan.class.php" );
  22.  
  23. /**
  24.  *
  25.  */
  26. require_onceCLASSPATH."html/HTMLLayer.class.php" );
  27.  
  28. /**
  29.  * A class to generate a "<div>"-layer which makes a second layer visible
  30.  * when the user goes over it with the mousecursor.
  31.  *
  32.  * @package    html
  33.  * @subpackage components
  34.  * @version    0.1.61
  35.  * @author     Daniel Plücken <daniel@debakel.net>
  36.  * @license    http://www.gnu.org/copyleft/lesser.html
  37.  *              GNU Lesser General Public License
  38.  * @copyright  Copyright (c) 2005 Daniel Plücken <daniel@debakel.net>
  39.  *
  40.  *  This library is free software; you can redistribute it and/or
  41.  *  modify it under the terms of the GNU Lesser General Public
  42.  *  License as published by the Free Software Foundation; either
  43.  *  version 2.1 of the License.
  44.  *
  45.  *  This library is distributed in the hope that it will be useful,
  46.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  47.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  48.  *  GNU Lesser General Public License for more details.
  49.  *
  50.  *  You should have received a copy of the GNU Lesser General
  51.  *  Public License along with this library; if not, write to the
  52.  *  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  53.  *  Boston, MA 02111-1307 USA
  54.  */
  55. class OverInfo extends HTMLSpan
  56. {
  57.   /**
  58.    * @var    object 
  59.    * @access public
  60.    */
  61.   var $write_to_doc_directly = false;
  62.   /**
  63.    * @var    object 
  64.    * @access public
  65.    */
  66.   var $pop_layer;
  67.   /**
  68.    * @var    integer 
  69.    * @access public
  70.    */
  71.   var $x_margin_to_cursor = 20;
  72.   /**
  73.    * @var    integer 
  74.    * @access public
  75.    */
  76.   var $y_margin_to_cursor = 0;
  77.   /**
  78.    * @var    boolean 
  79.    * @access public
  80.    */
  81.   var $hide_selects_on_over = true;
  82.   /**
  83.    * @var    boolean 
  84.    * @access public
  85.    */
  86.   var $move_popup_with_mouse = true;
  87.  
  88.  
  89.  
  90.   /**
  91.    * Constructor.
  92.    *
  93.    * @version 1.37
  94.    * @since   0.1.0
  95.    * @author  Daniel Plücken <daniel@debakel.net>
  96.    * @access  public
  97.    * @param   $label 
  98.    * @param   $content 
  99.    * @param   $style_pop_layer 
  100.    * @param   $style_base_layer 
  101.    * @param   $x_margin_to_cursor 
  102.    * @param   $y_margin_to_cursor 
  103.    * @param   $hide_selects 
  104.    */
  105.   function OverInfo(
  106.                      $label,
  107.                      $content,
  108.                      $style_pop_layer       "",
  109.                      $style_base_layer      "",
  110.                      $x_margin_to_cursor    20,
  111.                      $y_margin_to_cursor    0,
  112.                      $hide_selects_on_over  true,
  113.                      $move_popup_with_mouse true
  114.                    )
  115.   {
  116.     $tmp uniqid"dp" );
  117.  
  118.     $this->pop_layer =new HTMLLayer$tmp );
  119.     $this->pop_layer->setBody$content );
  120.     $this->pop_layer->setStyle$style_pop_layer );
  121.     $this->pop_layer->setPosition"absolute" );
  122.     $this->pop_layer->setFreeStyle"display:none" );
  123.  
  124.  
  125.  
  126.     $this->setBody$label );
  127.     $this->setVisible();
  128.     $this->setStyle$style_base_layer );
  129.     $this->setNoFormat();
  130.  
  131.     $this->x_margin_to_cursor = $x_margin_to_cursor;
  132.     $this->y_margin_to_cursor = $y_margin_to_cursor;
  133.     $this->hide_selects_on_over = $hide_selects_on_over;
  134.  
  135.  
  136.     // $this->setOnMouseMove( "this.onmousemove=setCoords" );
  137.     $this->setAutoZIndex$this->pop_layer );
  138.  
  139.                                     $x_margin_to_cursor,
  140.                                     $y_margin_to_cursor
  141.                                  );
  142.   }
  143.  
  144.  
  145.  
  146.   /**
  147.    * Order that the div-tag (popup layer) should be written directly to the
  148.    * body; otherwise the div-tag will be written onload-event of the body-tag.
  149.    * It is useful to keep the javascript function trough an ajax request, when
  150.    * the body is already loaded.
  151.    *
  152.    * @version 1.0
  153.    * @since   0.1.6
  154.    * @author  Daniel Plücken <daniel@debakel.net>
  155.    * @return  void 
  156.    */
  157.   function writeToDocumentDirectly()
  158.   $this->write_to_doc_directly = true}
  159.  
  160.  
  161.  
  162.   /**
  163.    * Stores the popup layer of this OverInfo to the next z-index.
  164.    *
  165.    * @version 1.0
  166.    * @since   0.1.2
  167.    * @author  Daniel Plücken <daniel@debakel.net>
  168.    * @return  void 
  169.    */
  170.   function setAutoZIndex&$obj_ref )
  171.   {
  172.     static $int 5000;
  173.  
  174.     $this->setZIndex$int );
  175.     $obj_ref->setZIndex$int++ );
  176.   }
  177.  
  178.  
  179.  
  180.   /**
  181.    * Stores the needed javascript to output in the head of html-document.
  182.    *
  183.    * @version 1.07
  184.    * @since   0.1.3
  185.    * @author  Daniel Plücken <daniel@debakel.net>
  186.    * @param   $x_margin_to_cursor 
  187.    * @param   $y_margin_to_cursor 
  188.    * @return  void 
  189.    */
  190.   function setGlobalJavaScript(
  191.                                 $x_margin_to_cursor 0,
  192.                                 $y_margin_to_cursor 0
  193.                               )
  194.   {
  195.     static $js_already_set false;
  196.  
  197.     if !$js_already_set )
  198.        $GLOBALS["javascript_content"][=
  199. <<<JSCRIPT
  200.     // over info adjustment
  201.     window.oia_x = {$x_margin_to_cursor};
  202.     window.oia_y = {$y_margin_to_cursor};
  203.  
  204.     window.setCoords = function( which2move_obj, referrer_obj, move_with_mouse, evt )
  205.     {
  206.         var pos_x = 0;
  207.         var pos_y = 0;
  208.  
  209.         if ( move_with_mouse )
  210.         {
  211.             which2move_obj = document.getElementById( which2move_obj );
  212.  
  213.             if ( !evt || evt == null )
  214.                 evt = window.event;
  215.  
  216.             if ( evt && ( evt.pageX || evt.pageY ) )
  217.             {
  218.                 pos_x = evt.pageX;
  219.                 pos_y = evt.pageY;
  220.             }
  221.             else
  222.             if ( evt && ( evt.clientX || evt.clientY ) )
  223.                 if ( document.documentElement.scrollTop )
  224.                 {
  225.                     pos_x = evt.clientX
  226.                           + document.documentElement.scrollLeft;
  227.                     pos_y = evt.clientY
  228.                           + document.documentElement.scrollTop;
  229.                 }
  230.                 else
  231.                 {
  232.                     pos_x = evt.clientX + document.body.scrollLeft;
  233.                     pos_y = evt.clientY + document.body.scrollTop;
  234.                 }
  235.         }
  236.         else
  237.         {
  238.             // Get the left position of the Element
  239.             var obj = referrer_obj;
  240.             if ( obj.offsetParent )
  241.             {
  242.                 while ( obj.offsetParent )
  243.                 {
  244.                     pos_x += obj.offsetLeft;
  245.                     obj = obj.offsetParent;
  246.                 }
  247.             }
  248.             else
  249.             if ( obj.x )
  250.                 pos_x += obj.x;
  251.  
  252.  
  253.             // Get the top position of the Element
  254.             obj = referrer_obj;
  255.             if ( obj.offsetParent )
  256.             {
  257.                 while ( obj.offsetParent )
  258.                 {
  259.                     pos_y += obj.offsetTop;
  260.                     obj = obj.offsetParent;
  261.                 }
  262.             }
  263.             else
  264.             if ( obj.y )
  265.                 pos_y += obj.y;
  266.  
  267.         }
  268.  
  269.         if ( which2move_obj )
  270.         {
  271.             which2move_obj.style.display = 'block';
  272.             which2move_obj.style.top = (pos_y+window.oia_y) + 'px';
  273.             which2move_obj.style.left = (pos_x+window.oia_x) + 'px';
  274.         }
  275.     }
  276.  
  277.  
  278.     window.startOverInfo = function( which, ref_obj, no_select_hiding, move_with_mouse )
  279.     {
  280.         if (
  281.              !no_select_hiding
  282.           && navigator.appName == "Microsoft Internet Explorer"
  283.            )
  284.         {
  285.             var aV = navigator.appVersion.replace( /^.+?MSIE ([0-9.]+).+$/, "$1" )
  286.  
  287.             if ( parseFloat( aV ) < 7.0 )
  288.             {
  289.                 var sel = document.getElementsByTagName( 'select' );
  290.                 for ( var i = 0; i < sel.length; i++ )
  291.                     sel[i].style.visibility = 'hidden';
  292.             }
  293.         }
  294.  
  295.         var tmp_obj = document.getElementById( which );
  296.  
  297.         if ( tmp_obj )
  298.             window.setCoords( tmp_obj, ref_obj, move_with_mouse, null );
  299.     }
  300.  
  301.  
  302.     window.stopOverInfo = function( which, no_select_hiding )
  303.     {
  304.         if (
  305.              !no_select_hiding
  306.           && navigator.appName == "Microsoft Internet Explorer"
  307.            )
  308.         {
  309.             var aV = navigator.appVersion.replace( /^.+?MSIE ([0-9.]+).+$/, "$1" )
  310.  
  311.             if ( parseFloat( aV ) < 7.0 )
  312.             {
  313.                 var sel = document.getElementsByTagName('select');
  314.                 for ( var i = 0; i < sel.length; i++ )
  315.                     sel[i].style.visibility = 'visible';
  316.             }
  317.         }
  318.  
  319.         var tmp_obj = document.getElementById( which );
  320.  
  321.         if ( tmp_obj )
  322.         {
  323.             tmp_obj.style.left = -17378;
  324.             tmp_obj.style.top = -17378;
  325.             tmp_obj.style.display = 'none';
  326.         }
  327.     }
  328.  
  329.  
  330.  
  331. JSCRIPT;
  332.  
  333.     $js_already_set true;
  334.   }
  335.  
  336.  
  337.  
  338.   /**
  339. /**
  340.    * Returns a generated string based on the attributes of this HTML-Object.
  341.    *
  342.    * @version 1.22
  343.    * @since   0.1.0
  344.    * @author  Daniel Plücken <daniel@debakel.net>
  345.    * @access  public
  346.    * @return  string 
  347.    */
  348.   function get()
  349.   {
  350.     static $firsttime true;
  351.  
  352.     // Two time escaping
  353.     $prepared_content_str str_replace(
  354.                                 "\r""\\r",
  355.                                 str_replace(
  356.                                     "\n""\\n",
  357.                                     addslashes$this->pop_layer->get() )
  358.                                            )
  359.                                        );
  360.  
  361.     $tmp_str $this->pop_layer->getId();
  362.  
  363.     if $this->hide_selects_on_over )
  364.     {
  365.         $this->setOnMouseOut"window.stopOverInfo( '{$tmp_str}', false ));
  366.         $this->setOnMouseOver(
  367.              "window.oia_x=".$this->x_margin_to_cursor.";"
  368.             ."window.oia_y=".$this->y_margin_to_cursor.";"
  369.             ."window.startOverInfo( '{$tmp_str}', this, false, "
  370.                       .( ( $this->move_popup_with_mouse "true" "false" )
  371.                                ." )"
  372.                              );
  373.  
  374.         if $this->move_popup_with_mouse )
  375.            $this->setOnMouseMove(
  376.                        "this.onmousemove=function(evt){window.setCoords( '{$tmp_str}', this, true, evt );}"
  377.                                 );
  378.     }
  379.     else
  380.     {
  381.         $this->setOnMouseOut"window.stopOverInfo( '{$tmp_str}', true ));
  382.         $this->setOnMouseOver(
  383.              "window.oia_x=".$this->x_margin_to_cursor.";"
  384.             ."window.oia_y=".$this->y_margin_to_cursor.";"
  385.             ."window.startOverInfo( '{$tmp_str}', this, true, "
  386.                       .( ( $this->move_popup_with_mouse "true" "false" )
  387.                                ." )"
  388.                              );
  389.  
  390.         if $this->move_popup_with_mouse )
  391.            $this->setOnMouseMove(
  392.                        "this.onmousemove=function(evt){window.setCoords( '{$tmp_str}', this, true, evt );}"
  393.                                 );
  394.  
  395.     }
  396.  
  397.     $tmp_str $firsttime "" "";
  398.  
  399.     if $this->write_to_doc_directly )
  400.     {
  401.         $tmp_js = <<<JSCRIPT
  402.  
  403.         document.getElementsByTagName('body')[0].innerHTML += tmp_str;
  404. JSCRIPT;
  405.     }
  406.     else
  407.     {
  408.         $prepared_content_str addslashes$prepared_content_str );
  409.         $tmp_js = <<<JSCRIPT
  410.  
  411.         if ( window.addEventListener )
  412.             window.addEventListener( "load", new Function( "document.getElementsByTagName('body')[0].innerHTML += '" + tmp_str + "';"), false );
  413.         else
  414.         if ( window.attachEvent )
  415.             window.attachEvent( 'onload', new Function( "document.getElementsByTagName('body')[0].innerHTML += '" + tmp_str + "';") );
  416. JSCRIPT;
  417.     }
  418.  
  419.     // write the popuplayer, with the help of javascript, at the end of the document.
  420.     $poplayer_write_str = <<<JSCRIPT
  421. <div style="position:absolute;top:-17318;left:-17318;z-index:-17378;display:hidden">
  422.     <script language="javascript" type="text/javascript">
  423.     <!--
  424.         var tmp_str = '{$prepared_content_str}';
  425.  
  426.         {$tmp_js}
  427.     // -->
  428.     </script>
  429. </div>
  430. JSCRIPT;
  431.  
  432.     $firsttime false;
  433.  
  434.     return $poplayer_write_str.parent::get();
  435.   }
  436. // END of class OverInfo
  437. ?>

Documentation generated on Thu, 05 Jun 2008 19:14:41 +0200 by phpDocumentor 1.4.1