You are here

function modernizr_load_data in Modernizr 7.3

Same name and namespace in other branches
  1. 8 modernizr.module \modernizr_load_data()

A function to generate the load data from the current themes.

Reads async-loaded CSS/JS from theme .info files. Stores info in variable. Prints yepnope() calls into drupal_add_js() as inline settings.

Return value

array

2 calls to modernizr_load_data()
modernizr_preprocess_html in ./modernizr.module
Implements MODULE_preprocess_html().
_modernizr_load_generate in ./modernizr.module
Helper function to render the yepnope() calls.

File

./modernizr.module, line 378
Main module file for Modernizr

Code

function modernizr_load_data() {
  $load =& drupal_static(__FUNCTION__);
  if (!isset($load)) {

    // This is the first time this is called.
    global $base_url, $base_theme_info, $theme_info;
    $load = array();
    $num_tests = 0;

    // Make a list of base themes and the current theme.
    $themes = $base_theme_info;
    $themes[] = $theme_info;
    foreach (array_keys($themes) as $key) {
      $theme_path = dirname($themes[$key]->filename) . '/';
      if (isset($themes[$key]->info['modernizr'])) {

        // Loop through Modernizr calls and assemble Load variable.
        foreach (array_keys($themes[$key]->info['modernizr']) as $test_key => $test) {

          // If no tests are defined, simply add them as resources for loading them unconditionally.
          if (is_numeric($test)) {
            $load[] = array(
              _modernizr_sanitize_resource($themes[$key]->info['modernizr'][$test_key], $theme_path),
            );
          }
          elseif ($test != 'tests') {

            // All other entries inside a theme's modernizr[] settings should be scanned
            $load[$num_tests]['test'] = $test;
            foreach (array_keys($themes[$key]->info['modernizr'][$test]) as $action) {
              foreach ($themes[$key]->info['modernizr'][$test][$action] as $asset) {

                // First figure out which property we're reading.
                // callback/complete need different processing than yep/nope/both/load
                $functions = array(
                  'callback',
                  'complete',
                );

                // Is this a function or a resource?
                if (in_array($action, $functions)) {

                  // It's a function
                  $load[$num_tests][$action][] = _modernizr_sanitize_callback($asset);
                }
                else {

                  // It's a resource
                  $load[$num_tests][$action][] = _modernizr_sanitize_resource($asset, $theme_path);
                }
              }
            }
            $num_tests++;
          }
        }
      }
    }
  }
  return $load;
}