You are here

function editor_attach in Editor 5

Same name and namespace in other branches
  1. 6 editor.module \editor_attach()

Initialize the editor attachment process.

This function essentially adds required files and settings needed to 'attach' Editor via JavaScript.

1 call to editor_attach()
editor_init in ./editor.module
Implementation of hook_init().

File

./editor.module, line 157
Extendable WYSIWYG editor @author Tj Holowaychuk <tj@vision-media.ca> @link http://vision-media.ca @package Editor

Code

function editor_attach() {

  // Make sure design_mode plugin is available
  if (!($design_mode = plugins_available('design_mode'))) {
    return;
  }

  // Make sure visibility validates
  if (!visibility_api_access('editor')) {
    return;
  }

  // Gather plugins and profiles
  $plugins = editor_invoke_plugins();
  if (!($profile = editor_profile_get(variable_get('editor_default_profile', 'small')))) {
    return;
  }

  // Settings
  $data = array(
    'editor' => array(
      'toolbars' => editor_display_toolbars($profile),
    ),
  );

  // Plugin settings
  if (count($plugins)) {
    foreach ($plugins as $plugin) {
      $data['editor']['plugins'][$plugin->pid] = $plugin;
    }
  }

  // Add required css and javascript
  $module_path = drupal_get_path('module', 'editor');
  drupal_add_js($design_mode);
  drupal_add_css($module_path . '/editor.css');
  drupal_add_js($module_path . '/editor.js');
  drupal_add_js($module_path . '/editor.plugins.js');
  drupal_add_js($data, 'setting');
}