JS

Either adds the javascript to the group, or returns the script tag.

@access	public
@param	mixed	The file name, or an array files.
@param	array	An array of extra attributes
@param	string	The asset group name
@return	string
513122
public static function js($scripts = array(), $attr = array(), $group = NULL, $raw = false)
	{
		return static::instance()->js($scripts, $attr, $group, $raw);
	}
842279
public function addJs($asset)
	{
		if(is_array($asset))
		{
			foreach($asset as $a)
				$this->addJs($a);

			return $this;
		}

		if( ! $this->isRemoteLink($asset))
			$asset = $this->buildLocalLink($asset, $this->js_dir);

		if( ! in_array($asset, $this->js))
			$this->js[] = $asset;

		return $this;
	}
993820
public function script($url, $attributes = [], $secure = null)
    {
        $attributes['src'] = $this->url->asset($url, $secure);
        return '<script' . $this->attributes($attributes) . '></script>' . PHP_EOL;
    }
631520
public function script($assets, array $attributes = [])
    {

        $manager = clone $this;

        $collection = (new JavascriptCollection)->setAttributes($attributes);

        $manager->clear()
                ->addCollection($collection)
                ->addArray((array) $assets);

        return $manager;
    }
59130
public function getScript()
    {
        $_script = $this->script;
        $script = [
            $_script['form-create']
        ];
        if ($this->loadCityAreaData == true)
            $script[] = $_script['city-area-data'];
        if ($this->loadCityData == true)
            $script[] = $_script['city-data'];
        if ($this->linkJq)
            $script[] = $_script['jq'];
        if ($this->linkIview) {
            $script[] = $_script['iview'];
            $script[] = $_script['iview-css'];
        }
        if ($this->linkVue)
            $script[] = $_script['vue'];
        return array_reverse($script);
    }
1099849
function addFromArray($assets) {
        if (!is_array($assets)) $assets = [$assets];
        foreach ($assets as $key => $asset) {
            if ($key === 'debug') {
                if (self::$debug) $this->addFromArray($asset);
            } else if ($key === 'prod') {
                if (!self::$debug) $this->addFromArray($asset);
            } else {
                if (isset(self::$libs[$asset])) {
                    $this->addLib($asset);
                } elseif (substr($asset, -4) == '.css' || strpos($asset,'.css?v=') !== false) {
                    $this->addCss($asset);
                } else {
                    $this->addJs($asset);
                }
            }
        }
    }
360145
public function prependJs($asset)
	{
		if(is_array($asset))
		{
			foreach(array_reverse($asset) as $a)
				$this->prependJs($a);

			return $this;
		}

		if( ! $this->isRemoteLink($asset))
			$asset = $this->buildLocalLink($asset, $this->js_dir);

		if( ! in_array($asset, $this->js))
			array_unshift($this->js, $asset);

		return $this;
	}
665470
public function script($javascript)
    {
        if (is_array($javascript)) {
            $javascript = implode("\n", $javascript);
        }
        $this->link('<script>'.(strpos($javascript, "\n") ? "\n".$this->indent($javascript)."\n\t" : trim($javascript)).'</script>');
    }
553072
public function script($script) {
        $md5 = md5($script);
        if (in_array($md5, self::$cssScriptHistory))
            return '';
        self::$cssScriptHistory[] = $md5;
        return "<script type=\"text/javascript\">\n/*<![CDATA[*/\n{$script}\n/*]]>*/\n</script>";
    }
938164
public function renderScripts($withInternal = false, array $internalAttrs = [])
    {
        $html = [];

        $this->triggerEvent('onAssetRenderScripts', [
            'asset' => $this,
            'withInternal' => &$withInternal,
            'html' => &$html,
        ]);

        foreach ($this->scripts as $url => $script) {
            $defaultAttribs = [
                'src' => $script['url'],
            ];

            $attribs = array_merge($defaultAttribs, $script['attribs']);

            if ($script['options']['version'] !== false) {
                $attribs['src'] = $this->appendVersion($attribs['src']);
            }

            if (isset($script['options']['sri'])) {
                $attribs['integrity']   = $script['options']['sri'];
                $attribs['crossorigin'] = 'anonymous';
            }

            if (isset($script['options']['conditional'])) {
                $html[] = '<!--[if ' . $script['options']['conditional'] . ']>';
            }

            if (isset($script['options']['import'])) {
                $attribs['href'] = $attribs['src'];
                $attribs['rel']  = 'import';
                unset($attribs['src']);
                $html[] = (string) h('link', $attribs, null);
            } else {
                $html[] = (string) h('script', $attribs, null);
            }

            if (isset($script['options']['conditional'])) {
                $html[] = '<![endif]-->';
            }
        }

        if ($withInternal && $this->internalScripts) {
            $html[] = (string) h(
                'script',
                $internalAttrs,
                "\n" . $this->renderInternalScripts() . "\n" . $this->indents
            );
        }

        return implode("\n" . $this->indents, $html);
    }
1091289
public function asset($group, $asset)
    {
        if (!isset($asset)) {
            return '';
        }

        $asset['source'] = $this->getAssetSourceUrl($asset['source'], $group);

        return call_user_func_array([$this->html, $group], [$asset['source'], $asset['attributes']]);
    }
1372831
public static function script($text, array $attributes = [], $type = 'text/javascript')
    {
        return static::openTag('script',
            array_merge($attributes, ['type' => $type])).
            ' /*<![CDATA[*/ '.$text.' /*]]>*/ '.
            static::closeTag('script');
    }
723019
public function script($url, $attributes = array())
	{
		$attributes['src'] = $this->url->asset($url);

		return '<script'.$this->attributes($attributes).'></script>'.PHP_EOL;
	}
50097
public function js($file = false, $theme=null) {
        
        $this->secondaryTheme($theme);
        
        $js = $this->enqueueFiles($file, $this->container->getJS(), 'js');
        
        if(is_string($js))
            return $js;
        
        foreach($js as $value) {            
            $value = $this->buildPublicTmp($value);
            print '<script type="text/javascript" src="' . Filter::httpPublicTmp($value) . '"></script>'.PHP_EOL;
        }
        
    }
423195
public function asset_js($params) {
        if (!isset($params['refs'])) {
            throw new \UnexpectedValueException("The refs parameter is required.");
        }
        $group = isset($params['group']) ? $params['group'] : null;
        $attrs = isset($params['attrs']) ? $params['attrs'] : array();
        $raw = isset($params['raw']) ? $params['raw'] : false;
        return Asset::js($params['refs'], $attrs, $group, $raw);
    }
1314697
protected function _renderScript($script, $link, $attribs = array())
    {
        if ($link) {
            $script = pick($this->getService('com:base.template.asset')->getURL($script), $script);
        }

        //if ajax try to get the content of the file
        if (AnRequest::type() == 'AJAX') {
            if ($link) {
                $file = $this->getService('com:base.template.asset')->getFilePath($script);
                if ($file) {
                    $script = file_get_contents($file);
                    $link = false;
                }
            }

            return parent::_renderScript($script, $link, $attribs);
        }

        $document = AnService::get('anahita:document');

        if($link) {
            return $document->addScript($script, 'text/javascript');
        } else {
            return $document->addScriptDeclaration($script);
        }
    }
1199048
public function scriptFile($path) {
        if ($this->skipOtherScriptFiles)
            return "";
        
        if ('http' != substr($path, 0, 4)) {
            $path = \mpf\WebApp::get()->request()->getWebRoot() . $path;
        }

        $md5 = md5($path);
        if (in_array($md5, self::$cssScriptHistory))
            return '';
        self::$cssScriptHistory[] = $md5;
        return '<script type="text/javascript" src="' . self::encode($path) . '"></script>';
    }