Project

General

Profile

Feature #16900 ยป includejslib.patch

Administrator Admin, 2007-01-28 17:54

View differences:

typo3/template.php (working copy)
// Vars you typically might want to/should set from outside after making instance of this class:
var $backPath = ''; // 'backPath' pointing back to the PATH_typo3
var $form=''; // This can be set to the HTML-code for a formtag. Useful when you need a form to span the whole page; Inserted exactly after the body-tag.
var $JSlibArray = array(); // Additional header code (eg. a JavaScript section) for external javascript files (used in includejslib()), it get's included before all the other JS-code
var $JScode=''; // Additional header code (eg. a JavaScript section) could be accommulated in this var. It will be directly outputted in the header.
var $JScodeArray = array(); // Similar to $JScode but for use as array with associative keys to prevent double inclusion of JS code. a <script> tag is automatically wrapped around.
var $postCode=''; // Additional 'page-end' code could be accommulated in this var. It will be outputted at the end of page before </body> and some other internal page-end code.
......
'.$generator.'
<title>'.htmlspecialchars($title).'</title>
'.$this->docStyle().'
'.$this->JSlibArray.'
'.$this->JScode.'
'.$tabJScode.'
'.$this->wrapScriptTags(implode("\n", $this->JScodeArray)).'
......
}
/**
* Include javascript library
* Includes a javascript file from the typo3/contrib directory
*
* @param string library name (e.g. "prototype" or "scriptaculous"), which is
* the same as the folder & file name in the typo3/contrib/ directory
* @return boolean whether the library name was a valid file and was included or not
*/
function includeJSLib($libname) {
$js = t3lib_div::includeJSlib($libname);
if ($js) {
$this->JSlibArray[$libname] = $js;
return true;
}
return false;
}
/**
* Wraps the input string in script tags.
* Automatic re-identing of the JS code is done by using the first line as ident reference.
* This is nice for identing JS code with PHP code on the same level.
t3lib/class.t3lib_div.php (working copy)
return '\''.$value.'\'';
}
/**
* Include javascript library
* Includes a javascript file from the typo3/contrib directory
* If this is included in a FE-script, then it will be automatically be loaded
* if loaded in BE-script, please use the includeJSLib function in template.
*
* @param string library name (e.g. "prototype" or "scriptaculous"), which is
* the same as the folder / file name in the typo3/contrib/ directory
* @return mixed js-script inclusion string on success, otherwise false
*/
function includeJSLib($libname) {
$libname = htmlspecialchars($libname);
$contribDir = $GLOBALS['BACK_PATH'].'contrib/';
$filename = $contribDir.$libname.'/'.$libname.'.js';
if (!is_file($filename)) $filename = $contribDir.$libname.'.js';
if (!is_file($filename)) return false;
$js = '<script language="javascript" type="text/javascript" src="'.$filename.'"></script>';
// automatically include the library for frontend use
if (is_array($GLOBALS['TSFE'])) {
$GLOBALS['TSFE']->additionalHeaderData[$libname] = $js;
}
return $js;
}
}
    (1-1/1)