Script
Script Du er her: /  Forsiden  /  Kildekoden  /  Base  /  Script   Login nu   Login
Script
 ««« Se kilde koden
Script
Script Basic Base  Component Db Db-basket Dto Form Form-elements Jquery Layout Menu Menu-fisheye Mvc Tab Table Template Util
Script
Script
Script Index
 
Tilbage

Navn : Script.php


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

Parent html

Sådan vises komponenten Script klassen


PHP source code

Den fulde PHP kildekode for Script klassen

<?
/**
* @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.10
* @since 22-feb-2007
*/

/**
* 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();   
*   $script->add($element);
*   print $script->getHtml();
* Or
*   $script = new Script();   
*   print $script->getStart();
*   print "some javascript";
*   print $script->getEnd();
* Or
*   print $script->getStart();
*   print $script->getOnload($function);
*   print $script->getEnd();
* Or
*   Script::display();
* Or
*   Script::start();
*   DoSomeJavascript();
*   Script::end();
* Or
*   Script::start();
*   Script::onload($function);
*   Script::end();
* </code>
* @package base
*/

class Script extends Html {
    
/**
     * @var String $src The url to the javascript source file
     */
    
var $src = '';
    
/**
     * @var String $js The javascript if any
     */
    
var $js = '';
    
    
    
/**
     * Constructor
     * @param String $src The url to the javascript source file
     * @param String $js  The javascript if any
     */
    
function Script($src='', $js='') {
        
$this->Html();
        
$domainname = '';
        if (
defined('HTML_UTIL_COMPONENT_PATH') && $src != '') {
            
$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, $runFirst, false);
    }
    
    
/**
     * 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') && 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') && 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 type="text/javascript"';
        
$html .= $this->getAttribute('src');
        
$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() > 0 || $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
     */
    
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
     */
    
function onunload($function='', $runFirst=false) {
        
$html = new Script();
        
$html->addHtml($html->getOnunload($function, $runFirst));
    }
    
    
/**
     * Start of tag
     * <code>
     * Usage:
     *    Script::start($src);
     * </code>
     * @param String $src The url to the javascript source file
     * @static
     */
    
function start($src='') {
        
$html = new Script($src);
        
$html->addHtml($html->getStart());
    }

    
/**
     * End of tag
     * <code>
     * Usage:
     *    Script::end();
    * </code>
    * @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
     */
    
function display($src='', $js='') {
        
$html = new Script($src, $js);
        
$html->addHtml();
    }
}
?>

HTML source code

Den fulde HTML kildekode for Script klassen

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

?>

Class methods

Her er 'klasse metoderne' for Script klassen:

  • object
  • getclassname
  • getmsg
  • addhtml
  • gethtml
  • tostring
  • getcachefilename
  • save
  • content
  • stop
  • 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

Object vars

Her er 'objekt variable' for Script klassen:

  • html =>
  • sql =>
  • elements => Array
  • sizeof => 0
  • src => /include/my.js
  • js =>

Script

Vis denne side på danmark

Vis denne side på Germany

Vis denne side på England

Vis denne side på France

Vis denne side på Italy

Vis denne side på Norge

Vis denne side på Sverige

Vis denne side på USA


 
Script
Script Copyright @ 1999-2009 www.Finn-Rasmussen.com Powered by myPHP Version 1.10
Script