FOF30\Template\Template::addJS PHP Méthode

addJS() public méthode

There are three combinations of defer and async (see http://www.w3schools.com/tags/att_script_defer.asp): * $defer false, $async true: The script is executed asynchronously with the rest of the page (the script will be executed while the page continues the parsing) * $defer true, $async false: The script is executed when the page has finished parsing. * $defer false, $async false. (default) The script is loaded and executed immediately. When it finishes loading the browser continues parsing the rest of the page. When you are using $defer = true there is no guarantee about the load order of the scripts. Whichever script loads first will be executed first. The order they appear on the page is completely irrelevant.
See also: self::parsePath
public addJS ( string $uri, boolean $defer = false, boolean $async = false, string $version = null, string $type = 'text/javascript' ) : void
$uri string A path definition understood by parsePath, e.g. media://com_example/js/foo.js
$defer boolean Adds the defer attribute, see above
$async boolean Adds the async attribute, see above
$version string (optional) Version string to be added to the URL
$type string MIME type of the script
Résultat void
    public function addJS($uri, $defer = false, $async = false, $version = null, $type = 'text/javascript')
    {
        if ($this->container->platform->isCli()) {
            return;
        }
        $method = 'addScript' . (!empty($version) ? 'Version' : '');
        $document = $this->container->platform->getDocument();
        if (!method_exists($document, $method)) {
            return;
        }
        $url = $this->container->template->parsePath($uri);
        if (empty($version)) {
            $document->addScript($url, $type, $defer, $async);
            return;
        }
        $document->addScriptVersion($url, $version, $type, $defer, $async);
    }