You are here

function cpn_attach_syntax_highlighting in Code per Node 7

Attaches syntax highlighting to a form element.

4 calls to cpn_attach_syntax_highlighting()
cpn_form_alter in ./cpn.module
Implements of hook_form_alter().
cpn_form_node_form_alter in ./cpn.module
Implements hook_form_BASE_FORM_ID_alter().
cpn_form_node_type_form_alter in ./cpn.module
Implements hook_form_FORM_ID_alter().
cpn_settings in ./cpn.admin.inc
Settings form.

File

./cpn.module, line 903
Primary hook implementations.

Code

function cpn_attach_syntax_highlighting(&$form, $css = TRUE, $js = TRUE) {
  if (variable_get('cpn_syntax_highlighting', 0) == 'codemirror') {
    $path = cpn_codemirror();
    if (!empty($path)) {
      $form['#attached']['js'][] = $path . '/lib/codemirror.js';
      $form['#attached']['css'][] = $path . '/lib/codemirror.css';
      if ($css) {
        $form['#attached']['js'][] = $path . '/mode/css/css.js';
      }
      if ($js) {
        $form['#attached']['js'][] = $path . '/mode/javascript/javascript.js';
      }
      $form['#attached']['css'][] = $path . '/theme/default.css';
      $form['#attached']['css'][] = drupal_get_path('module', 'cpn') . '/cpn.css';

      // Admin pages.
      if (current_path() == 'admin/config/content/cpn') {
        $form['#attached']['js'][] = drupal_get_path('module', 'cpn') . '/cpn.admin.js';
      }
      else {
        $form['#attached']['js'][] = drupal_get_path('module', 'cpn') . '/cpn.js';
      }
    }
  }
}