blank.gif
triangle.gif Du er her: /  Forsiden  /  Kildekoden  /  Form  /  Focus   Login nu   Login
blank.gif
 ««« Se kilde koden
blank.gif
triangle.gif Basic Base Component Db Dto Form  Form-elements Jquery Layout Menu Menu-fisheye Mvc Tab Table Template Util
blank.gif
blank.gif
 
arrow-headline.gif Index
 
  Tilbage

Navn : Focus.php


Sample code, tutorial

Sådan benyttes komponenten Focus klassen

Først skal du inkludere den fil der beskriver komponenten, som en klasse fil

  • <?
    require_once(HTML_PACKAGE_PATH.'/Focus.php');
    ?>

Dernæst kan du enten benytte komponenten som et taglib (statiske metoder):

  • <?
    Focus
    ::display($param1, $param2, $param3, ...);
    ?>

eller du kan lave en instance af komponenten og benytte metoderne direkte:

  • <?
    $object
    = new Focus($param1, $param2, $param3, ...);
    print
    $object->getHtml();
    ?>

Parent html

Sådan vises komponenten Focus klassen


PHP source code

Den fulde PHP kildekode for Focus klassen

<?
/**
* @package form
* @filesource
* @see HTML_FORM_COMPONENT_PATH.'/Focus.php'
* @copyright (c) http://Finn-Rasmussen.com
* @license http://Finn-Rasmussen.com/license/ myPHP License conditions
* @author http://Finn-Rasmussen.com
* @version 1.10
* @since 22-feb-2007
*/

/**
* The required files
*/
require_once(HTML_BASE_UTIL_PATH.'/Script.php');

/**
* Generates the html, so focus and selected is set the element name for a named form
* No javascript is inserted, if the form or element is undefined (not an javascript object)
* If more than one Focus object is call, only the last one will be used in window.onload
* <code>
* The following javascript code is inserted
*   document.ViewForm.email.focus();
*   document.ViewForm.email.select();
* Usage:
*   Assume that the html form/element tags looks like the following
*   <form name="ViewForm" ...><input type="text" name="email" .../> ...</form>
*   $form    = 'ViewForm';
*   $element = 'email';
*   $focus = new Focus($form, $element);
*   print $focus->getHtml();
* Or
*   Focus::display($form, $element);
* </code>
* @package form
*/

class Focus extends Script {
   
/**
     * Constructor
     * @param String $form    The name of the form
     * @param String $element The element name to set focus to
     */
    
function Focus($form, $element) {
        
$this->Script();
        
$this->setJavascript($form, $element);
    }

    
/**
     * Set the complete html for a javascript element to set focus and select
     * @param String $form    The name of the form
     * @param String $element The element name to set focus to
     */
    
function setJavascript($form, $element) {
        
$html = '';
        
$nl  = '';
        
$tab = '';
        if (
defined('DEBUG_LEVEL') && DEBUG_LEVEL & DEBUG_LEVEL_SHOW_INFO) {
            
$nl  = "\r\n";
            
$tab = "\t";
        }
        
$name = 'set'.$this->getClassName().'_';
        
$focusIsDefined = "focusIsDefined";
        
$html .= "function ".$name.$form.$element."() {".$nl;
        
$html .= $tab."if (typeof document.".$form." == 'object') {".$nl;
        
$html .= $tab.$tab."if (typeof document.".$form.".".$element." == 'object') {".$nl;
        
$html .= $tab.$tab.$tab."document.".$form.".".$element.".focus();".$nl;
        
$html .= $tab.$tab.$tab."document.".$form.".".$element.".select();".$nl;
        
$html .= $tab.$tab."}".$nl;
        
$html .= $tab."}".$nl;
        
$html .= "}".$nl;
        
$html .= "if (typeof $focusIsDefined == 'undefined') {".$nl;
        
$html .= $this->getOnload($name.$form.$element);
        
//$html .= $tab."window.onload = setFocus;".$nl;
        
$html .= $tab."$focusIsDefined = true;".$nl; // Global flag, no var
        
$html .= "}".$nl;
        
$this->js = $html;
    }

    
/**
     * Display html for a javascript selected and set focus for a form element
     * <code>
     * Usage:
     *    Focus::display($form, $element);
     * </code>
     * @static
     * @param String $form    The name of the form
     * @param String $element The element name to set focus to
     */
    
function display($form, $element) {
        
$html = new Focus($form, $element);
        
$html->addHtml();
    }
}
?>

HTML source code

Den fulde HTML kildekode for Focus klassen

<?
<script type="text/javascript">
//<![CDATA[
function setFocus_TestTest() {if (typeof document.Test == 'object') {if (typeof document.Test.Test == 'object') {document.Test.Test.focus();document.Test.Test.select();}}}if (typeof focusIsDefined == 'undefined') {function onload1Body() {var onloadCurrent = window.onload;if (typeof onloadCurrent !== 'function') {window.onload = setFocus_TestTest;} else {window.onload = function() {onloadCurrent();setFocus_TestTest();}}}onload1Body();focusIsDefined = true;}
//]]>
</script>

?>

Class methods

Her er 'klasse metoderne' for Focus klassen:

  • object
  • getclassname
  • getmsg
  • addhtml
  • gethtml
  • tostring
  • getcachefilename
  • save
  • content
  • html
  • setobject
  • set
  • get
  • getattribute
  • gettag
  • add
  • getsizeof
  • getelement
  • getelements
  • gettoogle
  • getmaximize
  • getminimize
  • newtriangle
  • display
  • showsource
  • script
  • getonunload
  • getonload
  • getstart
  • getjs
  • getend
  • onload
  • onunload
  • start
  • end
  • focus
  • setjavascript

Object vars

Her er 'objekt variable' for Focus klassen:

  • html =>
  • sql =>
  • elements => Array
  • sizeof => 0
  • src =>
  • js => function setFocus_TestTest() {if (typeof document.Test == 'object') {if (typeof document.Test.Test == 'object') {document.Test.Test.focus();document.Test.Test.select();}}}if (typeof focusIsDefined == 'undefined') {function onload1Body() {var onloadCurrent = window.onload;if (typeof onloadCurrent !== 'function') {window.onload = setFocus_TestTest;} else {window.onload = function() {onloadCurrent();setFocus_TestTest();}}}onload1Body();focusIsDefined = true;}

 
triangle.gif

danmark

Germany

England

France

Italy

Norge

Sverige

USA


 
blank.gif