Top  Branding  Banner 
blank.gif
blank.gif
triangle.gif Du är här: /  Försida  /  Kildekoden  /  Base  /  Script   Starta upp nu   Starta upp
blank.gif
««« Se source code
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  
Tilbaka

Gör mindra: Namn

Script.php


Visa: Sample code, tutorial

Script, Sample code, tutorial

Sådan användas Script klass

Först skall du inkludera den fil där beskrivar komponenten, som en klass fil

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

härefter kan du antingen bruka komponenten som ett taglib (statiske metoder):

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

eller du kan göra en instance av komponenten och bruka metoden direkte:

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

Gör mindra: Sådan visas komponenten

Script, Sådan visas komponenten

Sådan visas komponenten Script klass


Visa: PHP source code

Script, PHP source code

Den hela PHP kildekode för Script klass

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

Visa: HTML source code

Script, HTML source code

Den hela HTML kildekode för Script klass

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

?>

Visa: Class methods

Script, Class methods

Här är 'klasse metoden' för Script klass:

  • __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

Visa: Object vars

Script, Object vars

Här är 'objekt variable' för Script klass:

  • html =>
  • sql =>

MenuRight 
triangle.gif

Dansk

Deutch

English (UK)

France

Italy

Norsk

Svensk

English (USA)


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