You are here

function modernizr_admin in Modernizr 7.3

Implements hook_admin().

Modernizr administration settings

1 string reference to 'modernizr_admin'
modernizr_menu in ./modernizr.module
Implements hook_menu().

File

./modernizr.admin.inc, line 13
Admin include for Modernizr module.

Code

function modernizr_admin() {
  $form = array();

  // Fieldset for drupal_add_js() options.
  $form['js'] = array(
    '#type' => 'fieldset',
    '#title' => t('Placement and Performance'),
  );

  // Option to set the scope of Modernizr.
  $form['js']['modernizr_scope'] = array(
    '#type' => 'select',
    '#title' => t('Where should Modernizr be loaded?'),
    '#options' => array(
      'header' => t('header'),
      'footer' => t('footer'),
    ),
    '#default_value' => variable_get('modernizr_scope', MODERNIZR_SCOPE_DEFAULT),
    '#description' => t('When possible, it is recommended to print all JavaScript in the footer unless you are using a specific set of features which require blocking execution in the &lt;head&gt;. <a href="@url">Read more on GitHub</a>. <strong>Important:</strong> you should not move Modernizr to the bottom of the page unless ALL dependent scripts are also after Modernizr (higher weight in <code>drupal_add_js()</code> settings).', array(
      '@url' => 'https://github.com/Modernizr/Modernizr/issues/878#issuecomment-41448059',
    )),
  );

  // Options to determine how Modernizr is included. Although these options are
  // presented as one group, they control two settings within drupal_add_js()
  // because an inline file cannot be deferred. If inline is set, it precludes
  // us from setting `defer` to TRUE. Conversely if `defer` is chosen, we must
  // set the type to `file` when invoking drupal_add_js().
  $form['js']['modernizr_type'] = array(
    '#type' => 'select',
    '#title' => t('How should Modernizr be loaded?'),
    '#options' => array(
      'defer' => t('Defer'),
      'inline' => t('Inline'),
      'sync' => t('Synchronous'),
    ),
    '#default_value' => variable_get('modernizr_type', MODERNIZR_TYPE_DEFAULT),
    '#description' => t('When possible, it is recommended to <code>defer</code> this JavaScript unless you are using a specific set of features which require blocking execution in the &lt;head&gt;. <strong>Important:</strong> you should not defer Modernizr unless any dependent scripts are also deferred.<br><br>In some cases, it might be beneficial to inline this JavaScript file. Make sure that you can confirm that this works better for your site by measuring performance! <a href="@url">Read more on GitHub</a>.', array(
      '@url' => 'https://github.com/Modernizr/Modernizr/issues/878#issuecomment-41448059',
    )),
  );

  // Fieldset for custom build options.
  $form['build_options'] = array(
    '#type' => 'fieldset',
    '#title' => t('Custom Build Options'),
  );

  // Custom builds no longer require printshiv by default.
  $form['build_options']['modernizr_cb_printshiv'] = array(
    '#type' => 'checkbox',
    '#title' => t('Require <code>printshiv</code> when custom builds are created.'),
    '#default_value' => variable_get('modernizr_cb_printshiv', FALSE),
  );

  // Modernizr v3 deprecated direct inclusion of Modernizr.load(). In order to
  // continue using Modernizr.load(), we have to include yepnope.js ourselves.
  $form['build_options']['modernizr_cb_load'] = array(
    '#type' => 'checkbox',
    '#title' => t('Include <code>Modernizr.load()</code> functionality. Modernizr v3 no longer includes this script itself. <a href="@url">Read more on GitHub</a>.', array(
      '@url' => 'https://github.com/Modernizr/Modernizr/issues/1182',
    )),
    '#default_value' => variable_get('modernizr_cb_load', MODERNIZR_YEPNOPE_DEFAULT),
  );

  // Fieldset for reporting options.
  $form['reporting'] = array(
    '#type' => 'fieldset',
    '#title' => t('Error reporting'),
  );

  // Reduce severity of requirements errors. Admin can use this option to avoid
  // seeing the red boxes when Modernizr requirements are not met.
  $form['reporting']['modernizr_quiet'] = array(
    '#type' => 'checkbox',
    '#title' => t('Decrease severity of Modernizr Test API errors.'),
    '#description' => t('Check this box if you\'d rather not see the red warning about missing Modernizr tests (or lack of a custom build). Enabling this option will not make Modernizr function properly if things are missing, but it will suppress the error message.'),
    '#default_value' => variable_get('modernizr_quiet', MODERNIZR_QUIET_DEFAULT),
  );
  return system_settings_form($form);
}