Commit c3dc7f9a authored by sun's avatar sun

#322657 by sun: Fixed "Enabled by default" option does not work when disabled.

parent a74955bf
......@@ -6,6 +6,7 @@ Wysiwyg x.x-x.x, xxxx-xx-xx
Wysiwyg 6.x-x.x, xxxx-xx-xx
---------------------------
#322657 by sun: Fixed "Enabled by default" option does not work when disabled.
#328052 by sun: Fixed switching input formats leads to wrong editor/state.
#337569 by sun: Fixed different profiles for same editor are not respected.
#340195 by sun: Fixed #after_build function not invoked on all forms.
......
......@@ -12,10 +12,8 @@ Drupal.wysiwyg.editor.attach.fckeditor = function(context, params, settings) {
for (var setting in settings) {
FCKinstance.Config[setting] = settings[setting];
}
// Attach editor control if default is on.
if (Drupal.settings.wysiwyg.status) {
FCKinstance.ReplaceTextarea();
}
// Attach editor.
FCKinstance.ReplaceTextarea();
};
/**
......
......@@ -4,10 +4,8 @@
* Attach this editor to a target element.
*/
Drupal.wysiwyg.editor.attach.jwysiwyg = function(context, params, settings) {
// Attach editor control if default is on.
if (Drupal.settings.wysiwyg.status) {
$('#' + params.field).wysiwyg();
}
// Attach editor.
$('#' + params.field).wysiwyg();
};
/**
......
......@@ -4,11 +4,9 @@
* Attach this editor to a target element.
*/
Drupal.wysiwyg.editor.attach.nicedit = function(context, params, settings) {
// Attach editor control if default is on.
if (Drupal.settings.wysiwyg.status) {
var editor = new nicEditor(settings);
editor.panelInstance(params.field);
}
// Attach editor.
var editor = new nicEditor(settings);
editor.panelInstance(params.field);
};
/**
......
......@@ -36,10 +36,8 @@ Drupal.wysiwyg.editor.attach.tinymce = function(context, params, settings) {
for (var setting in settings) {
tinyMCE.settings[setting] = settings[setting];
}
// Attach editor control if default is on.
if (Drupal.settings.wysiwyg.status) {
tinyMCE.execCommand('mceAddControl', true, params.field);
}
// Attach editor.
tinyMCE.execCommand('mceAddControl', true, params.field);
};
/**
......
......@@ -37,10 +37,8 @@ Drupal.wysiwyg.editor.attach.tinymce = function(context, params, settings) {
for (var setting in settings) {
tinyMCE.settings[setting] = settings[setting];
}
// Attach editor control if default is on.
if (Drupal.settings.wysiwyg.status) {
tinyMCE.execCommand('mceAddControl', true, params.field);
}
// Attach editor.
tinyMCE.execCommand('mceAddControl', true, params.field);
};
/**
......
......@@ -52,22 +52,19 @@ var o = function (id) {
* Attach this editor to a target element.
*/
Drupal.wysiwyg.editor.attach.whizzywig = function(context, params, settings) {
// Attach editor control if default is on.
if (Drupal.settings.wysiwyg.status) {
// Assign button images path, if available.
if (settings.buttonPath) {
window.buttonPath = settings.buttonPath;
}
// Create Whizzywig container.
wysiwygWhizzywig.currentField = params.field;
wysiwygWhizzywig.fields[wysiwygWhizzywig.currentField] = '';
// Attach editor.
makeWhizzyWig(params.field, (settings.buttons ? settings.buttons : 'all'));
// Whizzywig fails to detect and set initial textarea contents.
var instance = $('#whizzy' + params.field).get(0);
if (instance) {
instance.contentWindow.document.body.innerHTML = $('#' + params.field).val();
}
// Assign button images path, if available.
if (settings.buttonPath) {
window.buttonPath = settings.buttonPath;
}
// Create Whizzywig container.
wysiwygWhizzywig.currentField = params.field;
wysiwygWhizzywig.fields[wysiwygWhizzywig.currentField] = '';
// Attach editor.
makeWhizzyWig(params.field, (settings.buttons ? settings.buttons : 'all'));
// Whizzywig fails to detect and set initial textarea contents.
var instance = $('#whizzy' + params.field).get(0);
if (instance) {
instance.contentWindow.document.body.innerHTML = $('#' + params.field).val();
}
};
......
......@@ -39,17 +39,14 @@ Drupal.behaviors.attachWysiwyg = function(context) {
// Directly attach this editor, if the input format is enabled or there is
// only one input format at all.
if (($this.is(':input') && $this.is(':checked')) || $this.is('div')) {
Drupal.wysiwygAttachToggleLink(context, params);
Drupal.wysiwygAttach(context, params);
}
// Attach onChange handlers to input format selector elements.
if ($this.is(':input')) {
$this.change(function() {
// If not disabled, detach the current and attach a new editor.
if (Drupal.wysiwyg.instances[params.field].status) {
Drupal.wysiwygDetach(context, params);
Drupal.wysiwygAttach(context, params);
}
Drupal.wysiwygDetach(context, params);
Drupal.wysiwygAttach(context, params);
});
}
$this.addClass('wysiwyg-processed');
......@@ -71,19 +68,21 @@ Drupal.behaviors.attachWysiwyg = function(context) {
*/
Drupal.wysiwygAttach = function(context, params) {
if (typeof Drupal.wysiwyg.editor.attach[params.editor] == 'function') {
// Attach editor.
Drupal.wysiwyg.editor.attach[params.editor](context, params, (Drupal.settings.wysiwyg.configs[params.editor] ? Drupal.wysiwyg.clone(Drupal.settings.wysiwyg.configs[params.editor][params.format]) : {}));
// (Re-)initialize field instance.
Drupal.wysiwyg.instances[params.field] = {};
// Store new editor name and status for this field.
Drupal.wysiwyg.instances[params.field].editor = params.editor;
Drupal.wysiwyg.instances[params.field].status = true;
// Display toggle link.
$('#wysiwyg-toggle-' + params.field).show();
}
// Hide toggle link in case no editor is attached.
if (params.editor == 'none') {
$('#wysiwyg-toggle-' + params.field).hide();
// Attach or update toggle link.
Drupal.wysiwygAttachToggleLink(context, params);
// Attach editor, if enabled by default or last state was enabled.
if (params.status) {
Drupal.wysiwyg.editor.attach[params.editor](context, params, (Drupal.settings.wysiwyg.configs[params.editor] ? Drupal.wysiwyg.clone(Drupal.settings.wysiwyg.configs[params.editor][params.format]) : {}));
}
// Otherwise, attach default behaviors.
else {
Drupal.wysiwyg.editor.attach.none(context, params);
Drupal.wysiwyg.instances[params.field].editor = 'none';
}
}
}
......@@ -103,7 +102,7 @@ Drupal.wysiwygDetach = function(context, params) {
}
/**
* Append a editor toggle link to a target element.
* Append or update an editor toggle link to a target element.
*
* @param context
* A DOM element, supplied by Drupal.attachBehaviors().
......@@ -111,40 +110,53 @@ Drupal.wysiwygDetach = function(context, params) {
* An object containing input format parameters.
*/
Drupal.wysiwygAttachToggleLink = function(context, params) {
var text = document.createTextNode(Drupal.settings.wysiwyg.status ? Drupal.settings.wysiwyg.disable : Drupal.settings.wysiwyg.enable);
var a = document.createElement('a');
$(a).click(function() {
if (Drupal.wysiwyg.instances[params.field].status) {
if (!$('#wysiwyg-toggle-' + params.field).size()) {
var text = document.createTextNode(params.status ? Drupal.settings.wysiwyg.disable : Drupal.settings.wysiwyg.enable);
var a = document.createElement('a');
$(a).attr({id: 'wysiwyg-toggle-' + params.field, href: 'javascript:void(0);'}).append(text);
var div = document.createElement('div');
$(div).append(a);
$('#' + params.field).after(div);
}
$('#wysiwyg-toggle-' + params.field).html(params.status ? Drupal.settings.wysiwyg.disable : Drupal.settings.wysiwyg.enable).show().unbind('click').click(function() {
if (params.status) {
// Detach current editor.
params.status = false;
Drupal.wysiwygDetach(context, params);
Drupal.wysiwyg.instances[params.field].status = false;
$('#wysiwyg-toggle-' + params.field).html(Drupal.settings.wysiwyg.enable).blur();
// After disabling the editor, re-attach default behaviors.
Drupal.wysiwyg.editor.attach.none(context, params);
Drupal.wysiwyg.instances[params.field].editor = 'none';
$(this).html(Drupal.settings.wysiwyg.enable).blur();
}
else {
// Before enabling the editor, detach default behaviors.
Drupal.wysiwyg.editor.detach.none(context, params);
// Attach the editor using parameters of the currently selected input format.
Drupal.wysiwygAttach(context, Drupal.wysiwyg.getParams($('.wysiwyg-field-' + params.field + ':checked', context).get(0)));
$('#wysiwyg-toggle-' + params.field).html(Drupal.settings.wysiwyg.disable).blur();
// Attach new editor using parameters of the currently selected input format.
Drupal.wysiwyg.getParams($('.wysiwyg-field-' + params.field + ':checked', context).get(0), params);
params.status = true;
Drupal.wysiwygAttach(context, params);
$(this).html(Drupal.settings.wysiwyg.disable).blur();
}
})
.attr('id', 'wysiwyg-toggle-' + params.field)
.attr('href', 'javascript:void(0);')
.append(text);
var div = document.createElement('div');
$(div).append(a);
$('#' + params.field).after(div);
});
// Hide toggle link in case no editor is attached.
if (params.editor == 'none') {
$('#wysiwyg-toggle-' + params.field).hide();
}
}
/**
* Parse the CSS classes of an input format DOM element into parameters.
*
* Format is "wysiwyg-name-value".
* Syntax for CSS classes is "wysiwyg-name-value".
*
* @param element
* An input format DOM element containing CSS classes to parse.
* @param params
* (optional) An object containing input format parameters to update.
*/
Drupal.wysiwyg.getParams = function(element) {
Drupal.wysiwyg.getParams = function(element, params) {
var classes = element.className.split(' ');
var params = {};
var params = params || {};
for (var i in classes) {
if (classes[i].substr(0, 8) == 'wysiwyg-') {
var parts = classes[i].split('-');
......@@ -154,6 +166,9 @@ Drupal.wysiwyg.getParams = function(element) {
}
// Convert format id into string.
params.format = 'format' + params.format;
// Convert numeric values.
params.status = parseInt(params.status);
params.resizable = parseInt(params.resizable);
return params;
}
......
......@@ -115,10 +115,12 @@ function wysiwyg_process_form(&$form) {
foreach ($formats as $format) {
// Default to 'none' editor (Drupal's default behaviors).
$editor = 'none';
$status = 1;
// Fetch the profile associated to this input format.
$profile = wysiwyg_get_profile($format);
if ($profile) {
$editor = $profile->editor;
$status = (int)wysiwyg_user_get_status($profile);
// Check editor theme (and reset it if not/no longer available).
$theme = wysiwyg_get_editor_themes($profile, (isset($profile->settings['theme']) ? $profile->settings['theme'] : ''));
......@@ -131,7 +133,7 @@ function wysiwyg_process_form(&$form) {
// Use a prefix/suffix for a single input format, or attach to input
// format selector radio buttons.
if (isset($element['format']['guidelines'])) {
$element['format']['guidelines']['#prefix'] = '<div class="wysiwyg wysiwyg-format-'. $format .' wysiwyg-editor-'. $editor .' wysiwyg-field-'. $field['#id'] . $extra_class .'">';
$element['format']['guidelines']['#prefix'] = '<div class="wysiwyg wysiwyg-format-'. $format .' wysiwyg-editor-'. $editor .' wysiwyg-field-'. $field['#id'] .' wysiwyg-status-'. $status . $extra_class .'">';
$element['format']['guidelines']['#suffix'] = '</div>';
// Edge-case: Default format contains no input filters.
if (empty($element['format']['guidelines']['#value'])) {
......@@ -145,7 +147,7 @@ function wysiwyg_process_form(&$form) {
else {
$element[$format]['#attributes']['class'] = '';
}
$element[$format]['#attributes']['class'] .= 'wysiwyg wysiwyg-format-'. $format .' wysiwyg-editor-'. $editor .' wysiwyg-field-'. $field['#id'] . $extra_class;
$element[$format]['#attributes']['class'] .= 'wysiwyg wysiwyg-format-'. $format .' wysiwyg-editor-'. $editor .' wysiwyg-field-'. $field['#id'] .' wysiwyg-status-'. $status . $extra_class;
}
}
}
......@@ -235,13 +237,10 @@ function wysiwyg_load_editor($profile) {
drupal_add_css($editor['css path'] . '/' . $file, 'module', 'screen');
}
$status = wysiwyg_user_get_status($profile);
drupal_add_js(array('wysiwyg' => array(
'configs' => array($editor['name'] => array()),
// @todo Move into profile settings.
'showToggle' => isset($profile->settings['show_toggle']) ? $profile->settings['show_toggle'] : TRUE,
// @todo http://drupal.org/node/322433
'status' => $status,
// @todo Move into (global) editor settings.
// If JS compression is enabled, at least TinyMCE is unable to determine
// its own base path and exec mode since it can't find the script name.
......
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