Top  Branding  Banner 
blank.gif
blank.gif
triangle.gif Du er her: /  Forsiden  /  Kildekoden  /  Form  /  Focus   Login nu   Login
blank.gif
««« Se kilde koden
blank.gif
tl.gif Base tr.gif tl.gif Basic tr.gif tl.gif Dto tr.gif tls.gif     Form  trs.gif tl.gif Language tr.gif tl.gif Layout tr.gif tl.gif Menu tr.gif tl.gif Mvc tr.gif tl.gif Netbank.eksperter.dk tr.gif tl.gif Tab tr.gif tl.gif Table tr.gif tl.gif Util tr.gif
blank.gif
blank.gif
arrow-headline.gif Index
MenuLink  MenuLeft  
Tilbage

Skjul: Navn

Focus.php


Vis: Sample code, tutorial

Focus, 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();
    ?>

Skjul: Sådan vises komponenten

Focus, Sådan vises komponenten

Sådan vises komponenten Focus klassen


Vis: PHP source code

Focus, PHP source code

Den fulde PHP kildekode for Focus klassen

<?php
/**
 * @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.11
 * @since 27-nov-2009
 */

/**
 * The required files
 */
require_once(HTML_BASE_UTIL_PATH.'/Script.php');
require_once(
HTML_BASIC_UTIL_PATH.'/Message.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="firma 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 __construct($form=''$element='') {
        
parent::__construct();
        
// Sanity check, no space should be allowed here
        
if (strpos($element' ') !== false) {
            if (
defined('DEBUG_LEVEL_SHOW_INFO') && DEBUG_LEVEL DEBUG_LEVEL_SHOW_INFO) {
                
Message::add("Space detected in element=".$element__FILE____LINE__);
            }
            
$element str_replace(' ''_'$element);
        }
        
$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_SHOW_INFO') && 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;
        if (
$element != "") {
            
$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;
        } else {
            
$html .= $tab.$tab."/* form.element is empty */".$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
     */
    
public static function display($form=''$element='') {
        
$html = new Focus($form$element);
        
$html->addHtml();
    }
}
?>

Vis: HTML source code

Focus, HTML source code

Den fulde HTML kildekode for Focus klassen

<?
<!-- DEBUGFocus -->
<
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>

?>

Vis: Class methods

Focus, Class methods

Her er 'klasse metoderne' for Focus klassen:

  • __construct
  • setJavascript
  • display
  • getOnunload
  • getOnload
  • getStart
  • getJs
  • getEnd
  • getHtml
  • onload
  • onunload
  • start
  • end
  • setObject
  • set
  • get
  • getAttribute
  • getTag
  • add
  • getSizeof
  • getElement
  • getElements
  • getToogle
  • getMaximize
  • getMinimize
  • newTriangle
  • getStartHtml
  • getEndHtml
  • showsource
  • getClassName
  • getMsg
  • addHtml
  • __toString
  • getCacheFileName
  • save
  • content

Vis: Object vars

Focus, Object vars

Her er 'objekt variable' for Focus klassen:

  • html =>
  • sql =>

MenuRight 
triangle.gif

Dansk

Deutch

English (UK)

France

Italy

Norsk

Svensk

English (USA)


 
blank.gif
MenuBottom 
triangle.gif Copyright @ 1999-2010 www.Finn-Rasmussen.com Powered by myPHP Version (5.3.3-7+squeeze3) 1.11
blank.gif