You are here

function ace_editor_add in Ace Code Editor 7

An API function to embed read-only editors into template files.

File

./ace_editor.module, line 42
Ace Editor module.

Code

function ace_editor_add($content, $user_settings) {

  // Get the default settings and override them with settings defined by user.
  $settings = ace_editor_field_formatter_default_settings();
  foreach ($user_settings as $key => $value) {
    $settings[$key] = $value;
  }
  $settings = ace_editor_make_js_friendly_settings($settings);

  // Get a unique index for the next pre-element added by this API function.
  $pre_id = drupal_html_id('ace-editor-add');
  $pre = '<pre id="' . $pre_id . '">' . $content . '</pre>';

  // Put all instances and their settings to JS.
  $js_ettings = array();
  $js_settings['ace_editor']['editor_instances'][] = array(
    'id' => $pre_id,
    'content' => $content,
    'settings' => $settings,
  );

  // Add the javascript files needed.
  ace_editor_add_js($settings, FALSE);
  drupal_add_js($js_settings, 'setting');
  drupal_add_js(drupal_get_path('module', 'ace_editor') . '/js/ace_editor.js');
  drupal_add_css(drupal_get_path('module', 'ace_editor') . '/styles/ace_editor.css');
  return $pre;
}