'Auto',
'DeferedCSS' => 'loadCSS',
'DeferedJS' => 'loadJS',
];
}
public static function Auto($class = false)
{
// Initialization
Requirements::block(THIRDPARTY_DIR.'/jquery/jquery.js');
if (defined('FONT_AWESOME_DIR')) {
Requirements::block(FONT_AWESOME_DIR.'/css/lib/font-awesome.min.css');
}
Requirements::set_force_js_to_bottom(true);
// Main libs
DeferedRequirements::loadJS('//ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js');
// App libs
DeferedRequirements::loadJS(project().'/dist/js/app.js');
DeferedRequirements::loadCSS(project().'/dist/css/app.css');
// Class libs
if($class) {
DeferedRequirements::loadJS(project() . '/dist/js/' . $class . '.js');
DeferedRequirements::loadCSS(project() . '/dist/css/' . $class . '.css');
}
return self::forTemplate();
}
public static function loadCSS($css)
{
if (self::$defered && !self::_webpackActive()) {
self::$css[] = $css;
} else {
WebpackTemplateProvider::loadCSS($css);
}
}
public static function loadJS($js)
{
if (self::$defered && !self::_webpackActive()) {
self::$js[] = $js;
} else {
WebpackTemplateProvider::loadJS($js);
}
}
protected static function _webpackActive()
{
return class_exists('WebpackTemplateProvider') && WebpackTemplateProvider::isActive();
}
public static function setDefered($bool)
{
self::$defered = $bool;
}
public static function forTemplate()
{
if (!self::$defered || self::_webpackActive()) {
return false;
}
$result = '';
foreach (self::$css as $css) {
$result .= '';
}
foreach (self::$js as $js) {
$result .= '';
}
$result .=
'';
return $result;
}
private static function get_url($url)
{
// external URL
if (strpos($url, '//') !== false) {
return $url;
}
$version = Config::inst()->get('DeferedRequirements', 'version');
$version = $version
? strpos($url, '?') // inner URL
? '&'.$version // add param
: '?'.$version // new param
: ''; // no version defined
$static_domain = Config::inst()->get('DeferedRequirements', 'static_domain');
$static_domain = $static_domain ? $static_domain : '';
return $url.$version;
}
}