diff --git a/editors/ckeditor.inc b/editors/ckeditor.inc index 6a92bb2..f0aca54 100644 --- a/editors/ckeditor.inc +++ b/editors/ckeditor.inc @@ -156,7 +156,7 @@ function wysiwyg_ckeditor_settings_form_validate_css_classes($element, &$form_st } /** - * Returns an inline initialization JavaScript for this editor library. + * Returns an initialization JavaScript for this editor library. * * @param array $editor * The editor library definition. @@ -192,6 +192,7 @@ EOL; */ function wysiwyg_ckeditor_settings($editor, $config, $theme) { $settings = array( + 'baseHref' => $GLOBALS['base_url'] . '/', 'width' => 'auto', // For better compatibility with smaller textareas. 'resize_minWidth' => 450, diff --git a/editors/tinymce.inc b/editors/tinymce.inc index f865a7c..42c5fd1 100644 --- a/editors/tinymce.inc +++ b/editors/tinymce.inc @@ -127,7 +127,7 @@ function wysiwyg_tinymce_themes($editor, $profile) { } /** - * Returns an inline initialization JavaScript for this editor library. + * Returns an initialization JavaScript for this editor library. * * @param array $editor * The editor library definition. diff --git a/wysiwyg.api.php b/wysiwyg.api.php index 9b4811a..6e3bb5a 100644 --- a/wysiwyg.api.php +++ b/wysiwyg.api.php @@ -214,6 +214,9 @@ function hook_INCLUDE_editor() { // A callback to convert administrative profile/editor settings into // JavaScript settings. 'settings callback' => 'wysiwyg_ckeditor_settings', + // A callback to return an initialization JavaScript snippet for this editor + // library. It will be included before the actual library files. + 'init callback' => 'wysiwyg_ckeditor_init', // A callback to supply definitions of available editor plugins. 'plugin callback' => 'wysiwyg_ckeditor_plugins', // A callback to convert administrative plugin settings for a editor profile diff --git a/wysiwyg.module b/wysiwyg.module index 1f996d3..7e0d605 100644 --- a/wysiwyg.module +++ b/wysiwyg.module @@ -306,7 +306,7 @@ function wysiwyg_load_editor($profile) { $path = drupal_get_path('module', 'wysiwyg'); if (!isset($init_added)) { - // Initialize our namespaces in the *header* to do not force editor + // Initialize our namespaces in the *header* to not force editor // integration scripts to check and define Drupal.wysiwyg on its own. drupal_add_js($path . '/wysiwyg.init.js', array('group' => JS_LIBRARY, 'weight' => -1)); $init_added = TRUE; @@ -338,14 +338,27 @@ function wysiwyg_load_editor($profile) { $files = $files['files']; } - // Check whether the editor requires an inline initialization script. + // Check whether the editor requires an initialization script. if (!empty($editor['init callback'])) { - // Request global variables from the editor. - $init_script = $editor['init callback']($editor, $library, $profile); - if (!empty($init_script)) { - // ajax_render() ignores inline scripts. We work around that. - // @see wysiwyg_js_alter() - drupal_add_js($init_script, array('wysiwyg' => 'inline') + $default_library_options); + $init = $editor['init callback']($editor, $library, $profile); + if (!empty($init)) { + // Build a file for each of the editors to hold the init scripts. + // @todo Aggregate all inits to one file when wysiwyg_process_form() + // builds a registry of profiles in use to need only one HTTP request. + $jspath = 'public://js/wysiwyg'; + file_prepare_directory($jspath, FILE_CREATE_DIRECTORY); + $filename = 'js_wysiwyg_' . $name . '_' . drupal_hash_base64($init) . '.js'; + $uri = $jspath . '/' . $filename; + // Attempt to save the file in the public files folder. + if (!file_exists($uri) && !file_unmanaged_save_data($init, $uri, FILE_EXISTS_REPLACE)) { + // Fall back to an inline script, won't work in AJAX calls. + drupal_add_js($init, array('type' => 'inline') + $default_library_options); + } + else { + // Link to the new file. + drupal_add_js(file_create_url($uri), $default_library_options); + } + } } @@ -414,19 +427,6 @@ function wysiwyg_load_editor($profile) { } /** - * Implements hook_js_alter(). - * - * @see wysiwyg_load_editor() - */ -function wysiwyg_js_alter(&$items) { - foreach ($items as &$item) { - if (isset($item['wysiwyg'])) { - $item['type'] = 'inline'; - } - } -} - -/** * Add editor settings for a given input format. */ function wysiwyg_add_editor_settings($profile, $theme) {