diff --git a/editors/ckeditor.inc b/editors/ckeditor.inc index c267e06..db7c848 100644 --- a/editors/ckeditor.inc +++ b/editors/ckeditor.inc @@ -185,6 +185,7 @@ function wysiwyg_ckeditor_settings($editor, $config, $theme) { // @todo Check whether completely disabling ProcessHTMLEntities is an option. 'entities_latin' => FALSE, 'entities_greek' => FALSE, + 'global_basepath_var' => 'CKEDITOR_BASEPATH', ); // Add HTML block format settings; common block formats are already predefined diff --git a/editors/js/ckeditor-3.0.js b/editors/js/ckeditor-3.0.js index f288928..ae021ee 100644 --- a/editors/js/ckeditor-3.0.js +++ b/editors/js/ckeditor-3.0.js @@ -1,6 +1,9 @@ (function($) { Drupal.wysiwyg.editor.init.ckeditor = function(settings) { + window.CKEDITOR_BASEPATH = settings.global.editorBasePath + '/'; + CKEDITOR.basePath = window.CKEDITOR_BASEPATH; + // Plugins must only be loaded once. Only the settings from the first format // will be used but they're identical anyway. var registeredPlugins = {}; diff --git a/editors/js/tinymce-3.js b/editors/js/tinymce-3.js index cc59f44..6b349a0 100644 --- a/editors/js/tinymce-3.js +++ b/editors/js/tinymce-3.js @@ -63,6 +63,8 @@ Drupal.wysiwyg.editor.attach.tinymce = function(context, params, settings) { ed.onEvent.add(function(ed, e) { Drupal.wysiwyg.activeId = ed.id; }); + // Tell TinyMCE DOM has been loaded for AJAX + tinymce.dom.Event.domLoaded = true; // Make toolbar buttons wrappable (required for IE). ed.onPostRender.add(function (ed) { var $toolbar = $('
'); diff --git a/tests/wysiwyg_test.module b/tests/wysiwyg_test.module index c908e29..c2dd9a9 100644 --- a/tests/wysiwyg_test.module +++ b/tests/wysiwyg_test.module @@ -5,3 +5,46 @@ * Testing functionality for Wysiwyg module. */ +/** + * Implements hook_menu(). + */ +function wysiwyg_test_menu() { + $items['wysiwyg-test/ajax'] = array( + 'title' => 'Ajaxified form', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('wysiwyg_test_ajax_form'), + 'access callback' => TRUE, + ); + return $items; +} + +/** + * Form constructor for an ajaxified form lazy-loading a textarea. + */ +function wysiwyg_test_ajax_form($form, &$form_state) { + $form['enable'] = array( + '#type' => 'checkbox', + '#title' => 'Load textarea', + '#ajax' => array( + 'callback' => 'wysiwyg_test_ajax_form_callback', + 'wrapper' => 'ajax-wrapper', + ), + ); + $form['wrapper'] = array( + '#type' => 'container', + '#id' => 'ajax-wrapper', + ); + return $form; +} + +/** + * #ajax callback for wysiwyg_test_ajax_form(). + */ +function wysiwyg_test_ajax_form_callback($form, &$form_state) { + $form['body'] = array( + '#type' => 'text_format', + '#default_value' => '', + ); + form_builder($form['form_id']['#value'], $form, $form_state); + return $form['body']; +} diff --git a/wysiwyg.init.js b/wysiwyg.init.js index 6ccdb31..54babf7 100644 --- a/wysiwyg.init.js +++ b/wysiwyg.init.js @@ -6,6 +6,18 @@ Drupal.wysiwyg.editor = Drupal.wysiwyg.editor || { 'init': {}, 'attach': {}, 'de Drupal.wysiwyg.plugins = Drupal.wysiwyg.plugins || {}; (function ($) { + // See if the current editor requires a global basepath variable + // to be set before loading. + if (Drupal.settings.wysiwyg) { + $.each(Drupal.settings.wysiwyg.configs, function(editor_index, editor_value) { + $.each(editor_value, function(format_index, format_value){ + if (format_value.global_basepath_var) { + window[format_value.global_basepath_var] = Drupal.settings.wysiwyg.configs[editor_index].global.editorBasePath + '/'; + } + }); + }); + } + // Determine support for queryCommandEnabled(). // An exception should be thrown for non-existing commands. // Safari and Chrome (WebKit based) return -1 instead. diff --git a/wysiwyg.js b/wysiwyg.js index a6bf6a9..421d9ca 100644 --- a/wysiwyg.js +++ b/wysiwyg.js @@ -160,6 +160,9 @@ Drupal.wysiwygAttach = function(context, params) { * @see Drupal.detachBehaviors */ Drupal.wysiwygDetach = function (context, params, trigger) { + if (typeof Drupal.wysiwyg.instances[params.field] == 'undefined') { + return; + } trigger = trigger || 'unload'; var editor = Drupal.wysiwyg.instances[params.field].editor; if (jQuery.isFunction(Drupal.wysiwyg.editor.detach[editor])) { @@ -258,4 +261,11 @@ Drupal.wysiwyg.getParams = function(element, params) { */ Drupal.wysiwygInit(); +// Respond to CTools detach behaviors event. +$(document).bind('CToolsDetachBehaviors', function(context) { + for (var i in Drupal.wysiwyg.instances) { + Drupal.wysiwygDetach(context, Drupal.wysiwyg.instances[i]); + } +}); + })(jQuery);