API16

JHtml/script: Difference between revisions

From Joomla! Documentation

Doxiki (talk | contribs)
New page: ===Description=== Write a <script></script> element <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>Edit Descripton<nowik...
 
m preparing for archive only
 
(2 intermediate revisions by the same user not shown)
Line 2: Line 2:
Write a &lt;script&gt;&lt;/script&gt; element  
Write a &lt;script&gt;&lt;/script&gt; element  


<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[Description:JHtml/script|Edit Descripton]]<nowiki>]</nowiki>
</span>


{{Description:JHtml/script}}
 
<! removed transcluded page call, red link never existed >


===Syntax===
===Syntax===
Line 85: Line 83:
</source>
</source>


<span class="editsection" style="font-size:76%;">
 
<nowiki>[</nowiki>[[SeeAlso:JHtml/script|Edit See Also]]<nowiki>]</nowiki>
<! removed transcluded page call, red link never existed >
</span>
{{SeeAlso:JHtml/script}}


===Examples===
===Examples===
<CodeExamplesForm />
=== Code Examples ===
<dpl>
<dpl>
  noresultsheader=\n
  noresultsheader=\n
  category=script
  category=script
  category=JHtml
  category=JHtml
  category=CodeExample
  namespace=CodeExample
  category=MethodExample
  category=MethodExample
  include=*
  include=*
  format= ,,,
  format= ,,,
</dpl>
</dpl>
[[Category:Archived pages API16]]

Latest revision as of 01:44, 25 March 2017

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