You are here

function syntaxhighlighter_init in Syntax Highlighter 7

Same name and namespace in other branches
  1. 6.2 syntaxhighlighter.module \syntaxhighlighter_init()
  2. 6 syntaxhighlighter.module \syntaxhighlighter_init()
  3. 7.2 syntaxhighlighter.module \syntaxhighlighter_init()

File

./syntaxhighlighter.module, line 70
Syntax highlight code using the Syntaxhighlighter javascript library. See http://alexgorbatchev.com/wiki/SyntaxHighlighter

Code

function syntaxhighlighter_init() {
  if (!_syntaxhighlighter_page_match()) {
    return;
  }
  $lib_location = _syntaxhighlighter_get_lib_location();
  $styles_path = $lib_location . '/styles/';
  $scripts_path = $lib_location . '/scripts/';
  $js_options = array(
    'type' => 'file',
    'group' => JS_DEFAULT,
    'every_page' => TRUE,
  );
  drupal_add_css($styles_path . 'shCore.css');
  $theme = variable_get('syntaxhighlighter_theme', 'shThemeDefault.css');
  drupal_add_css($styles_path . $theme);
  drupal_add_js($scripts_path . 'shCore.js', $js_options);
  if (variable_get('syntaxhighlighter_legacy_mode', 0)) {
    drupal_add_js($scripts_path . 'shLegacy.js', $js_options);
  }
  if (variable_get('syntaxhighlighter_use_autoloader', FALSE)) {
    drupal_add_js($scripts_path . 'shAutoloader.js', $js_options);
    drupal_add_js(_syntaxhighlighter_file_directory_path() . '/syntaxhighlighter.autoloader.js', $js_options);
    $settings['useAutoloader'] = TRUE;
  }
  else {
    $enabled_languages = variable_get('syntaxhighlighter_enabled_languages', array(
      'shBrushPhp.js',
    ));
    foreach ($enabled_languages as $lang) {
      if (!empty($lang)) {
        drupal_add_js($scripts_path . $lang, $js_options);
      }
    }
  }
  $tag_name = variable_get('syntaxhighlighter_tagname', 'pre');
  if ($tag_name !== 'pre') {
    $settings['tagName'] = $tag_name;
  }
  if (file_exists($scripts_path . 'clipboard.swf')) {
    $settings['clipboard'] = base_path() . $scripts_path . 'clipboard.swf';
  }
  if (variable_get('syntaxhighlighter_legacy_mode', 0)) {
    $settings['legacyMode'] = TRUE;
  }
  if (isset($settings)) {
    drupal_add_js(array(
      'syntaxhighlighter' => $settings,
    ), 'setting');
  }
  if ($defaultExpression = variable_get('syntaxhighlighter_default_expressions', '')) {
    drupal_add_js($defaultExpression, 'inline');
  }
  drupal_add_js(drupal_get_path('module', 'syntaxhighlighter') . '/syntaxhighlighter.min.js', array(
    'type' => 'file',
    'scope' => 'footer',
    'group' => JS_DEFAULT,
    'every_page' => TRUE,
  ));
}