Top  Branding  Banner 
blank.gif
blank.gif
triangle.gif Du er her: /  Forsiden  /  Kildekoden  /  Base  /  Script   Login nu   Login
blank.gif
««« Se kilde koden
blank.gif
tls.gif     Base  trs.gif tl.gif Basic tr.gif tl.gif Dto tr.gif tl.gif Form tr.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

Script.php


Vis: Sample code, tutorial

Script, Sample code, tutorial

Sådan benyttes komponenten Script klassen

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

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

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

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

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

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

Skjul: Sådan vises komponenten

Script, Sådan vises komponenten

Sådan vises komponenten Script klassen


Vis: PHP source code

Script, PHP source code

Den fulde PHP kildekode for Script klassen

<?php
/**
 * @package base
 * @see HTML_BASE_UTIL_PATH.'/Script.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_COMMON_PATH.'/Html.php');
if (
defined('HTML_UTIL_COMPONENT_PATH')) {
    require_once(
HTML_UTIL_COMPONENT_PATH.'/Url.php');
}

/**
 * Generates an SCRIPT element
 * <code>
 * Usage:
 *   $script = new Script($src, $js);   
 *   $script->add($element);
 *   print $script->getHtml();
 * Or
 *   $script = new Script($src, $js);   
 *   print $script->getStart();
 *   print "some javascript";
 *   print $script->getEnd();
 * Or
 *   print $script->getStart();
 *   print $script->getOnload($function);
 *   print $script->getEnd();
 * Or
 *   Script::display($src, $js);
 * Or
 *   Script::start($src, $js);
 *   DoSomeJavascript();
 *   Script::end();
 * Or
 *   Script::start($src, $js);
 *   Script::onload($function);
 *   Script::end();
 * </code>
 * @package base
 */

class Script extends Html {
    
/**
     * @var String $src The url to the javascript source file
     */
    
protected $src '';
    
/**
     * @var String $js The javascript if any
     */
    
protected $js '';
    
/**
     * @var String $type The type
     */
    
protected $type 'text/javascript';
    
    
    
/**
     * Constructor
     * @param String $src The url to the javascript source file
     * @param String $js  The javascript if any
     */
    
function __construct($src=''$js='') {
        
parent::__construct();
        
$domainname '';
        if (
defined('HTML_UTIL_COMPONENT_PATH') && $src !== '') {
            
$strHttp 'http:/'.'/';
            if (
strpos($src$strHttp) !== false) {
                
// Skip
            
} else {
//                $domainname = Url::subdomain(DOMAIN_NAME); // Strip off subdomain names
            
}
        }
        
$this->src $domainname.$src;
        
$this->js  $js;
    }

    
/**
     * Returns the html for the Javascript window onunload event
     * <code>
     * Usage:
     *   $script = new Script();
     *   print $script->getOnunload($function);
     * </code>
     * @param  String $function The name of the function to add to the window.onunload
     * @param  String $runFirst The function is run before other, if true
     * @return String the complete html
     */
    
function getOnunload($function=''$runFirst=false) {
        return 
$this->getOnload($function$runFirstfalse);
    }
    
    
/**
     * Returns the html for the Javascript window onload event
     * <code>
     * Usage:
     *   $script = new Script();
     *   print $script->getOnload($function, $runFirst, $unload);
     * </code>
     * @param  String $function The name of the function to add to the window.onload
     * @param  String $runFirst The function is run before other, if true
     * @param  String $unload   The onload code is used if true, onunloaf is used if false
     * @return String the complete html
     */
    
function getOnload($function=''$runFirst=false$unload=true) {
        
$html  '';
        if (
$function != '') {
            static 
$id 0;
            
$id++;
            
$loadName $unload 'onload' 'onunload';
            
$oldName  $loadName.'Current';
            
$nl  '';
            
$tab '';
            if (
defined('DEBUG_LEVEL_SHOW_INFO') && DEBUG_LEVEL DEBUG_LEVEL_SHOW_INFO) {
                
$nl  "\r\n";
                
$tab "\t";
            }
            
$functions '';
            if (
$runFirst) {
                
$functions .= $tab.$tab.$tab.$function."();$nl";
                
$functions .= $tab.$tab.$tab.$oldName."();$nl";
            } else {
                
$functions .= $tab.$tab.$tab.$oldName."();$nl";
                
$functions .= $tab.$tab.$tab.$function."();$nl";
            }
            
$html .= "function ".$loadName.$id."Body() {".$nl;
            
$html .= $tab."var ".$oldName." = window.$loadName;".$nl;
            
$html .= $tab."if (typeof ".$oldName." !== 'function') {".$nl;
            
$html .= $tab.$tab."window.".$loadName." = $function;".$nl;
            
$html .= $tab."} else {".$nl;
            
$html .= $tab.$tab."window.".$loadName." = function() {".$nl;
            
$html .= $functions// to call
            
$html .= $tab.$tab."}".$nl;
            
$html .= $tab."}".$nl;
            
$html .= "}".$nl;
            
$html .= $loadName.$id."Body();".$nl;
        } else {
            if (
defined('DEBUG_LEVEL_SHOW_INFO') && DEBUG_LEVEL DEBUG_LEVEL_SHOW_INFO) {
                
$html .= "<!-- bodyOnload is empty -->\r\n";
            }
        }
        return 
$html;
    }

    
/**
     * Returns the start html for the script control
     * @return String the complete html
     */
    
function getStart() {
        
$html  '';
        
$html .= '<script';
        
$html .= $this->getAttribute('src');
        
$html .= $this->getAttribute('type');
        
$html .= ">\r\n";
        
$html .= $this->getJs();
        return 
$html;
    }

    
/**
     * Returns the start html for the script control
     * @return String the complete html
     */
    
function getJs() {
        
$html  '';
        if (
$this->getSizeof() > || $this->js != '') {
            
$html .= "/"."/<![CDATA[\r\n";
            
$html .= $this->js;
            
$html .= $this->getElements(); // as html
            
$html .= "\r\n/"."/]]>\r\n";
        }
        return 
$html;
    }

    
/**
     * Returns the end html for the script control
     * @return String the complete html
     */
    
function getEnd() {
        return 
"</script>\r\n";
    }

    
/**
     * Returns the html for the script control
     * @return String the complete html
     */
    
function getHtml() {
        
$html  $this->html;
        
$html .= $this->getStart();
        
$html .= $this->getEnd();
        return 
$html;
    }

    
/**
     * Display the html for the window onload event
     * <code>
     * Usage:
     *    Script::onload($function);
     * </code> 
     * @static
     * @param String $function The name of the function to add to the window.onload
     * @param String $runFirst The function is run before other, if true
     */
    
public static function onload($function=''$runFirst=false) {
        
$html = new Script();
        
$html->addHtml($html->getOnload($function$runFirst));
    }
    
    
/**
     * Display the html for the window onunload event
     * <code>
     * Usage:
     *    Script::onunload($function);
     * </code> 
     * @static
     * @param String $function The name of the unload function to add to the window.onunload
     * @param String $runFirst The function is run before other, if true
     */
    
public static function onunload($function=''$runFirst=false) {
        
$html = new Script();
        
$html->addHtml($html->getOnunload($function$runFirst));
    }
    
    
/**
     * Start of tag
     * <code>
     * Usage:
     *    Script::start($src, $js);
     * </code> 
     * @static
     * @param String $src The url to the javascript source file
     * @param String $js  The javascript if any
     */
    
public static function start($src=''$js='') {
        
$html = new Script($src$js);
        
$html->addHtml($html->getStart());
    }

    
/**
     * End of tag
     * <code>
     * Usage:
     *    Script::end(); 
    * </code> 
    * @static
     */
    
public static function end() {
        
$html = new Script();
        
$html->addHtml($html->getEnd());
    }

    
/**
     * Display html
     * <code>
     * Usage:
     *    Script::display($src, $js); 
     * </code> 
     * @static
     * @param String $src The url to the javascript source file
     * @param String $js  The javascript if any
     */
    
public static function display($src=''$js='') {
        
$html = new Script($src$js);
        
$html->addHtml();
    }
}
?>

Vis: HTML source code

Script, HTML source code

Den fulde HTML kildekode for Script klassen

<?
<!-- DEBUGScript -->
<
script src="/include/my.js" type="text/javascript">
</script>

?>

Vis: Class methods

Script, Class methods

Her er 'klasse metoderne' for Script klassen:

  • __construct
  • getOnunload
  • getOnload
  • getStart
  • getJs
  • getEnd
  • getHtml
  • onload
  • onunload
  • start
  • end
  • display
  • 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

Script, Object vars

Her er 'objekt variable' for Script 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+squeeze9) 1.11
blank.gif