function _modernizr_load_generate in Modernizr 7.3
Same name and namespace in other branches
- 8 modernizr.module \_modernizr_load_generate()
Helper function to render the yepnope() calls.
1 call to _modernizr_load_generate()
- modernizr_page_build in ./
modernizr.module - Implements hook_page_build().
File
- ./
modernizr.module, line 437 - Main module file for Modernizr
Code
function _modernizr_load_generate() {
$output = FALSE;
// Get yepnope() calls from the active theme.
$theme = modernizr_load_data();
// Collect data from modules that implement hook_modernizr_load().
$modules = modernizr_load_list();
// Combine the data from the .info file and the Drupal modules.
// Themes go first because they are more visual and in most cases
// it's probably best to load them first. Modules whose assets
// truly need to be loaded first have hook_modernizr_load_alter()
// at their disposal.
$test_objects = array_merge($theme, $modules);
// Build the yepnope() commands.
if (count($test_objects)) {
$num_tests = 0;
$items = array();
foreach ($test_objects as $load) {
// If test is defined, this entry will be an object.
if (isset($load['test'])) {
$item = '{' . "\n";
$item .= ' test: ' . $load['test'] . ',' . "\n";
// Print each action and its resources
$actions = array(
'yep',
'nope',
'both',
'load',
);
foreach ($actions as $action) {
if (isset($load[$action])) {
// Begin output for this action
$item .= ' ' . sprintf('%-4s', $action) . ': ';
// How many resources for this action?
if (count($load[$action]) == 1) {
// Single resource
$item .= "'" . $load[$action][0] . "',\n";
}
else {
// Multiple resources
$item .= '[';
foreach ($load[$action] as $resource) {
$item .= "'" . $resource . "',";
}
// Truncate last comma
$item = substr($item, 0, -1);
$item .= "],\n";
}
}
}
// Output these two properties without quotes around the output
$callbacks = array(
'callback',
'complete',
);
foreach ($callbacks as $action) {
if (isset($load[$action])) {
// Begin output for this action
$item .= ' ' . sprintf('%-4s', $action) . ': ';
// How many callbacks for this action?
if (count($load[$action]) == 1) {
// Single resource
$item .= $load[$action][0] . ",\n";
}
else {
// Multiple resources
$item .= '[';
foreach ($load[$action] as $callback) {
$item .= $callback . ",";
}
// Truncate last comma
$item = substr($item, 0, -1);
$item .= "],\n";
}
}
}
// Truncate last comma and newline
$item = substr($item, 0, -2);
$item .= "\n}";
$num_tests++;
}
else {
$resources = array();
foreach ($load as $resource) {
$resources[] = "'" . $resource . "'";
}
$item = implode(",\n", $resources);
$num_tests++;
}
$items[] = $item;
}
$output .= 'yepnope(';
// Issue commands as array if there is more than resource to load.
$output .= $num_tests > 1 ? '[' : '';
// Add commands.
$output .= implode(",\n", $items);
// Finally, close the yepnope() function parenthesis.
$output .= $num_tests > 1 ? ']' : '';
$output .= ');';
}
return $output;
}