You are here

function modernizr_page_build in Modernizr 8

Same name and namespace in other branches
  1. 7.3 modernizr.module \modernizr_page_build()

Implements hook_page_build().

We used to use hook_init(), but that loads the JA files needlessly on AJAX requests, private file requests, etc.

File

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

Code

function modernizr_page_build(&$page) {
  global $_modernizr_js_settings;

  // Load Modernizr on the page by invoking our implementation of hook_libraries_info().
  //
  // We can only use this method when Libraries API 2.0 is installed. Since Libraries 1.0
  // did not contain a function called libraries_load(), we must explicitly check for a
  // valid function to avoid fatal errors.
  //
  // @see http://drupal.org/node/1919796
  if (module_exists('libraries') && function_exists('libraries_load')) {
    libraries_load('modernizr');
  }
  else {

    // No Libraries API? Load the regular way.
    drupal_add_js(modernizr_get_path(), $_modernizr_js_settings);
  }

  // We want Modernizr.load() commands to be issued immediately after the call
  // to Modernizr so that they download while the page renders. The overrides
  // to $inline_js_settings will format the output as inline JS.
  if ($output = _modernizr_load_generate()) {
    $inline_js_settings = $_modernizr_js_settings;
    $inline_js_settings['type'] = 'inline';
    $inline_js_settings['weight'] = MODERNIZR_SCRIPT_WEIGHT + 1;

    // Load JS
    drupal_add_js($output, $inline_js_settings);
  }
}