You are here

magic_dev.module in Magic 7

Same filename and directory in other branches
  1. 7.2 magic_dev/magic_dev.module

Development settings for the magic module.

File

magic_dev/magic_dev.module
View source
<?php

/**
 * @file
 * Development settings for the magic module.
 */

/**
 * Implements hook_magic().
 */
function magic_dev_magic($magic_settings, $theme) {
  $settings = array();

  // Development Magic Grouping
  $settings['dev'] = array(
    '#type' => 'fieldset',
    '#title' => t('Development Enhancements'),
  );

  // Footer JavaScript Option
  $settings['dev']['magic_rebuild_registry'] = array(
    '#type' => 'checkbox',
    '#title' => t('Rebuild Theme Registry on Reload'),
    '#description' => t('<a href="!link" target="_blank">Rebuild the theme registry</a> during project development.', array(
      '!link' => 'http://drupal.org/node/173880#theme-registry',
    )),
    '#default_value' => theme_get_setting('magic_rebuild_registry', $theme),
  );

  // Viewport Indicator Option
  $settings['dev']['magic_viewport_indicator'] = array(
    '#type' => 'checkbox',
    '#title' => t('Viewport Width Indicator'),
    '#description' => t('Displays an indicator of the viewport. Tap/click to toggle between <em>em</em> and <em>px</em>. The CSS and JavaScript for this will bypass your CSS and JavaScript exclude options.'),
    '#default_value' => theme_get_setting('magic_viewport_indicator', $theme),
  );
  if (module_exists('modernizr')) {

    // Modernizr Debug Option
    $options = array(
      'attributes' => array(
        'target' => '_blank',
      ),
    );
    $settings['dev']['magic_modernizr_debug'] = array(
      '#type' => 'checkbox',
      '#title' => t('Modernizr Indicator'),
      '#description' => t('Displays an indicator of !modernizr detected features. Tap/click to toggle display of all of the available features. Install the !module for full Modernizr support. The CSS and JavaScript for this will bypass your CSS and JavaScript exclude options.', array(
        '!modernizr' => l('Modernizr', 'http://modernizr.com/', $options),
        '!module' => l('Modernizr Drupal module', 'http://drupal.org/project/modernizr', $options),
      )),
      '#default_value' => theme_get_setting('magic_modernizr_debug', $theme),
    );
  }
  else {

    // We don't have modernizr :-(
    $settings['dev']['magic_modernizr_debug'] = array(
      '#type' => 'hidden',
      '#value' => FALSE,
    );
  }
  return $settings;
}

/**
 * Implements hook_preprocess_html().
 */
function magic_dev_preprocess_html(&$vars) {
  global $theme_key;

  // Theme Registry Rebuild
  if (theme_get_setting('magic_rebuild_registry', $theme_key) && !defined('MAINTENANCE_MODE')) {

    // Rebuild .info data.
    system_rebuild_theme_data();

    // Rebuild theme registry.
    drupal_theme_rebuild();
  }

  // RWD Debug Integration
  if (theme_get_setting('magic_viewport_indicator', $theme_key) || theme_get_setting('magic_modernizr_debug', $theme_key)) {
    drupal_add_css(drupal_get_path('module', 'magic_dev') . '/css/magic.debug.css');
    drupal_add_js(drupal_get_path('module', 'magic_dev') . '/js/magic.debug.js');
  }
}

/**
 * Implements hook_process_html().
 */
function magic_dev_process_html(&$vars) {
  global $theme_key;

  // RWD Debug Integration
  if (theme_get_setting('magic_viewport_indicator', $theme_key) || theme_get_setting('magic_modernizr_debug', $theme_key)) {
    $debug_output = '<div id="magic-development">';
    if (theme_get_setting('magic_viewport_indicator', $theme_key)) {
      $debug_output .= '<div id="magic-viewport-indicator"></div>';
    }
    if (theme_get_setting('magic_modernizr_debug', $theme_key)) {
      $debug_output .= '<div id="magic-modernizr-debug" class="open"></div>';
    }
    $debug_output .= '</div>';
    if (!empty($vars['page_bottom'])) {
      $vars['page_bottom'] .= $debug_output;
    }
    else {
      $vars['page_bottom'] = $debug_output;
    }
  }
}

Functions

Namesort descending Description
magic_dev_magic Implements hook_magic().
magic_dev_preprocess_html Implements hook_preprocess_html().
magic_dev_process_html Implements hook_process_html().