src/Helper/Extension/AbstractExtensionHelper.php
protected function renderLibrary($source, $callback = null)
    {
        if ($callback === null) {
            return sprintf('<script type="text/javascript" src="%s"></script>'.PHP_EOL, $source);
        }

        $output = array();

        $output[] = 'var s = document.createElement("script");'.PHP_EOL;
        $output[] = 's.type = "text/javascript";'.PHP_EOL;
        $output[] = 's.async = true;'.PHP_EOL;
        $output[] = sprintf('s.src = "%s";'.PHP_EOL, $source);
        $output[] = sprintf('s.addEventListener("load", function () { %s(); }, false);'.PHP_EOL, $callback);
        $output[] = 'document.getElementsByTagName("head")[0].appendChild(s);'.PHP_EOL;

        return implode('', $output);
    }
protected function renderLibrary($source, $callback = null)
    {
        if ($callback === null) {
            return sprintf('<script type="text/javascript" src="%s"></script>'.PHP_EOL, $source);
        }

        $output = array();

        $output[] = 'var s = document.createElement("script");'.PHP_EOL;
        $output[] = 's.type = "text/javascript";'.PHP_EOL;
        $output[] = 's.async = true;'.PHP_EOL;
        $output[] = sprintf('s.src = "%s";'.PHP_EOL, $source);
        $output[] = sprintf('s.addEventListener("load", function () { %s(); }, false);'.PHP_EOL, $callback);
        $output[] = 'document.getElementsByTagName("head")[0].appendChild(s);'.PHP_EOL;

        return implode('', $output);
    }
Renders a library.

@param string      $source   The library source.
@param string|null $callback The javascript callback.

@return string The HTML output.