You are here

function live_css_init in Live CSS 7.2

Same name and namespace in other branches
  1. 6.2 live_css.module \live_css_init()
  2. 6 live_css.module \live_css_init()
  3. 7 live_css.module \live_css_init()

Implements hook_init().

File

./live_css.module, line 223
Allows editing and a live view of all changes in real-time in the browser.

Code

function live_css_init() {

  // 4, 6, 7 = admin access
  // 2, 3, 6, 7 = full access
  // 1 = limited
  // **NOTE**
  // This check is necessary to combat potential double permissions
  // Example:  'edit css admin' paired with 'edit css limited' would otherwise still result
  // in a dominant limitation in the files shown.
  $access = 4 * (int) user_access('edit css admin') + 2 * (int) user_access('edit css') + (int) user_access('edit css limited');
  if ($access > 0 && (bool) variable_get('preprocess_css', FALSE) === FALSE) {
    $path = drupal_get_path('module', 'live_css');
    $theme = variable_get('live_css_theme', 'tomorrow');
    $less = variable_get('live_css_less', 0);
    $allowed_path = $access === 1 ? variable_get('live_css_path_to_files', '') : '';

    // Collect PHP settings to be sent to Javascript for easy access.
    $settings = array(
      'theme' => $theme,
      'autoLoad' => FALSE,
      'hideAdmin' => variable_get('live_css_hideadmin', 1),
      'hideModules' => variable_get('live_css_hidemodules', 1),
      'fontSize' => variable_get('live_css_fontsize', '12px'),
      'tabSize' => (int) variable_get('live_css_tabsize', 2),
      'softTabs' => (bool) variable_get('live_css_softtabs', 1),
      'storage' => variable_get('live_css_storage', 1),
      'less' => $less,
      'savePath' => url('css/save'),
      'menuMargin' => variable_get('admin_menu_top_margin', 0),
      'switchSave' => (bool) variable_get('live_css_switchsave', 0),
      'pathGoggles' => $allowed_path,
    );

    // Transfer variables to JS and load the module and its files.
    if ($less) {
      drupal_add_js($path . '/js/less-1.3.0.min.js');
      drupal_add_js($path . '/js/less-display.js');
    }
    drupal_add_js(array(
      'liveCSS' => $settings,
    ), 'setting');
    libraries_load('ace');
    drupal_add_css($path . '/css/live_css.css', array(
      'group' => 'CSS_THEME',
      'every_page' => TRUE,
      'weight' => 100,
      'preprocess' => FALSE,
    ));
    drupal_add_js($path . '/js/live_css.js', array(
      'group' => 'CSS_THEME',
      'every_page' => TRUE,
      'weight' => 100,
    ));
  }
}