function minify_js_alter in Minify 7
Implements hook_js_alter().
File
- ./
minify.module, line 246
Code
function minify_js_alter(&$scripts) {
$cache = variable_get('minify_captured_js', array());
$updated = false;
foreach ($scripts as $file_path => $file_details) {
if ('file' == $file_details['type'] && is_file(drupal_realpath($file_path))) {
/* Set JavaScript entry into cache array if it not exist in cache */
if (!_minify_javascript_exist($file_path, $cache)) {
$updated = true;
$cache[$file_path]['file_path'] = $file_path;
$cache[$file_path]['file_name'] = drupal_basename($file_path);
$cache[$file_path]['version'] = isset($file_details['version']) ? $file_details['version'] : '';
$cache[$file_path]['minified_file_path'] = null;
$cache[$file_path]['minified_size'] = 0;
$cache[$file_path]['status'] = false;
$cache[$file_path]['last_minify_at'] = 0;
$cache[$file_path]['error'] = false;
$cache[$file_path]['error_msg'] = null;
$cache[$file_path]['skip'] = false;
$cache[$file_path]['md5'] = md5_file(drupal_realpath($file_path));
}
}
}
/* If any change in existing array update cache */
if ($updated) {
variable_set('minify_captured_js', $cache);
}
if (intval(variable_get('minify_js', 0))) {
/* Replace the JavaScript path by minified path into $scripts without changing the order */
foreach ($cache as $key => $value) {
if (isset($scripts[$key]) && $value['status']) {
$scripts[$key]['data'] = $value['minified_file_path'];
$scripts = _minify_replace_array_key($scripts, $key, $value['minified_file_path']);
}
}
}
}