function build_js($js, $config) {
global $tpl;
$js_array = array();
$extra_js_array = array();
$return_js = '';
$i=0;
$defer = "";
$config['jquery_version'] = intval($config['jquery_version']);
$ver = $config['jquery_version'] ? $config['jquery_version'] : "";
if( is_array($tpl->js_array) AND count($tpl->js_array) ) {
foreach ( $tpl->js_array as $js_file) {
$js_file = str_ireplace( '{THEME}', 'templates/' . $config['skin'], $js_file );
if( $js_file[0] == '/' ) {
$js_file = substr($js_file, 1);
}
if( stripos($js_file, 'http://') === 0 OR stripos($js_file, 'https://') === 0 ) {
$extra_js_array[] = $js_file;
} else $js[] = $js_file;
}
}
if ($config['js_min']) {
$js_array[] = "<script src=\"{$config['http_home_url']}engine/classes/min/index.php?g=general{$ver}&v={$config['cache_id']}\"></script>";
$default_array = array (
"engine/classes/js/jqueryui{$ver}.js",
'engine/classes/js/dle_js.js',
);
if ( count($js) ) $js = array_merge($default_array, $js); else $js = $default_array;
$js_array[] = "<script src=\"{$config['http_home_url']}engine/classes/min/index.php?f=".implode(",", $js)."&v={$config['cache_id']}\" defer></script>";
$return_js = implode("\n", $js_array);
} else {
$default_array = array (
"engine/classes/js/jquery{$ver}.js",
"engine/classes/js/jqueryui{$ver}.js",
'engine/classes/js/dle_js.js',
);
if ( count($js) ) $js = array_merge($default_array, $js); else $js = $default_array;
foreach ($js as $value) {
if($i > 0) $defer =" defer";
$js_array[] = "<script src=\"{$config['http_home_url']}{$value}?v={$config['cache_id']}\"{$defer}></script>";
$i++;
}
$return_js = implode("\n", $js_array);
}
if( count($extra_js_array) ) {
foreach ($extra_js_array as $value) {
$return_js .= "\n<script src=\"{$value}\" defer></script>";
}
}
return $return_js;
}