API16:JHtml/script
From Joomla! Documentation
Description
Write a <script></script> element
<! removed transcluded page call, red link never existed >
Syntax
static script($file, $framework=false, $relative=false, $path_only=false)
| Parameter Name | Default Value | Description |
|---|---|---|
| $file | path to file | |
| $framework | false | load the JS framework |
| $relative | false | path to file is relative to /media folder |
| $path_only | false | return the path to the file only |
Defined in
libraries/joomla/html/html.php
Importing
jimport( 'joomla.html.html' );
Source Body
public static function script($file, $framework = false, $relative = false, $path_only = false)
{
JHtml::core();
// Include mootools framework
if ($framework) {
JHtml::_('behavior.framework');
}
if($relative)
{
$app = JFactory::getApplication();
$cur_template = $app->getTemplate();
if (file_exists(JPATH_THEMES .'/'. $cur_template .'/js/'. $file)) {
$file = JURI::base(true).'/templates/'. $cur_template .'/js/'. $file;
} else {
list($extension, $file) = explode('/', $file, 2);
if (strpos($file, '/')) {
// Try to deal with plugins group
list($element, $file) = explode('/', $file, 2);
if (file_exists(JPATH_ROOT .'/media/'. $extension.'/'.$element.'/js/'.$file)) {
$file = JURI::root(true).'/media/'.$extension.'/'.$element.'/js/'.$file;
} else {
$file = JURI::root(true).'/media/'.$extension.'/js/'.$element.'/'.$file;
}
}
else {
$file = JURI::root(true).'/media/'.$extension.'/js/'.$file;
}
}
if($path_only)
{
return $file;
}
} elseif (strpos($file, 'http') !== 0) {
$file = JURI::root(true).'/'.$file;
}
$document = &JFactory::getDocument();
$document->addScript($file);
return;
}
<! removed transcluded page call, red link never existed >
Examples
Code Examples