function magic_sort_css_js in Magic 7.2
Same name and namespace in other branches
- 7 includes/scripts-experimental.inc \magic_sort_css_js()
Sorts CSS and JavaScript resources.
Callback for uasort() within:
This sort order helps optimize front-end performance while providing modules and themes with the necessary control for ordering the CSS and JavaScript appearing on a page.
Parameters
$a: First item for comparison. The compared items should be associative arrays of member items from drupal_add_css() or magic_add_js().
$b: Second item for comparison.
See also
1 string reference to 'magic_sort_css_js'
- magic_experimental_js in includes/
scripts-experimental.inc - Returns a themed presentation of all JavaScript code for the current page.
File
- includes/
scripts-experimental.inc, line 774 - A file to contain functions for the magic module to abuse.
Code
function magic_sort_css_js($a, $b) {
// First order by group, so that, for example, all items in the CSS_SYSTEM
// group appear before items in the CSS_DEFAULT group, which appear before
// all items in the CSS_THEME group. Modules may create additional groups by
// defining their own constants.
if (!empty($a['group']) && !empty($b['group'])) {
if ($a['group'] < $b['group']) {
return -1;
}
elseif ($a['group'] > $b['group']) {
return 1;
}
}
// Within a group, order all infrequently needed, page-specific files after
// common files needed throughout the website. Separating this way allows for
// the aggregate file generated for all of the common files to be reused
// across a site visit without being cut by a page using a less common file.
if (!empty($a['every_page']) && !empty($b['every_page'])) {
if ($a['every_page'] && !$b['every_page']) {
return -1;
}
elseif (!$a['every_page'] && $b['every_page']) {
return 1;
}
}
// Finally, order by weight.
if (!empty($a['weight']) && !empty($b['weight'])) {
if ($a['weight'] < $b['weight']) {
return -1;
}
elseif ($a['weight'] > $b['weight']) {
return 1;
}
}
else {
return 0;
}
}