function minifyjs_js_alter in Minify JS 7
Same name and namespace in other branches
- 8.2 minifyjs.module \minifyjs_js_alter()
- 8 minifyjs.module \minifyjs_js_alter()
Implements hook_js_alter().
File
- ./
minifyjs.module, line 107
Code
function minifyjs_js_alter(&$scripts) {
// Determine if the replacement needs to be performed.
$do_replace = FALSE;
if (variable_get('minifyjs_use_minified_javascript', 0)) {
if (variable_get('minifyjs_disable_admin', 0)) {
if (!path_is_admin(current_path())) {
$do_replace = TRUE;
}
}
else {
$do_replace = TRUE;
}
}
if ($do_replace) {
// Files array is keyed by file id. To make this operation as fast as
// possible, the array should be keyed by file uri. Also, shorten the
// array by removing files that are not minified.
$files = minifyjs_load_all_files();
$minified_files = array();
foreach ($files as $file) {
if (!empty($file->minified_uri)) {
$minified_files[$file->uri] = $file;
}
}
// Update the scripts array with new file info.
foreach ($scripts as $path => $file) {
if (isset($minified_files[$path])) {
$scripts[$path]['data'] = $minified_files[$path]->minified_uri;
minifyjs_update_scripts($scripts, $path, $minified_files[$path]->minified_uri);
}
}
}
}