Commit a5717aa0 authored by zhangtaihao's avatar zhangtaihao Committed by sun

- #356480 by Shawn_Smiley, zhangtaihao, idflood, whurleyf1: Added Lazy-load support for editors.

parent 83476bf1
......@@ -171,6 +171,7 @@ function wysiwyg_ckeditor_settings_form_validate_css_classes($element, &$form_st
function wysiwyg_ckeditor_settings($editor, $config, $theme) {
$settings = array(
'baseHref' => $GLOBALS['base_url'] . '/',
'global_basepath_var' => 'CKEDITOR_BASEPATH',
'width' => 'auto',
// For better compatibility with smaller textareas.
'resize_minWidth' => 450,
......
(function($) {
Drupal.wysiwyg.editor.init.ckeditor = function(settings) {
// CKEditor loses its base path info in case of Ajax.
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 = {};
......
......@@ -63,6 +63,8 @@ Drupal.wysiwyg.editor.attach.tinymce = function(context, params, settings) {
ed.onEvent.add(function(ed, e) {
Drupal.wysiwyg.activeId = ed.id;
});
// Indicate that the DOM has been loaded (in case of Ajax).
tinymce.dom.Event.domLoaded = true;
// Make toolbar buttons wrappable (required for IE).
ed.onPostRender.add(function (ed) {
var $toolbar = $('<div class="wysiwygToolbar"></div>');
......
......@@ -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'];
}
......@@ -11,6 +11,17 @@ Drupal.wysiwygInit = function() {
if (/KDE/.test(navigator.vendor)) {
return;
}
// 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 + '/';
}
});
});
}
jQuery.each(Drupal.wysiwyg.editor.init, function(editor) {
// Clone, so original settings are not overwritten.
......@@ -160,6 +171,10 @@ Drupal.wysiwygAttach = function(context, params) {
* @see Drupal.detachBehaviors
*/
Drupal.wysiwygDetach = function (context, params, trigger) {
// Do not attempt to detach an unknown editor instance (Ajax).
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])) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment